blob: c3ba83ba22671dc1f0003407f43c8345bc53d345 [file] [log] [blame]
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00001/*
Jamie Fox5592db02017-12-18 16:48:29 +00002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <stdio.h>
9#include <string.h>
10#include <stdbool.h>
11
12#include "cmsis.h"
13#include "tfm_api.h"
14#include "cmsis_os2.h"
15#include "tfm_integ_test.h"
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020016#include "tfm_ns_svc.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000017#include "tfm_ns_lock.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000018#ifdef TEST_FRAMEWORK_NS
Tamas Banc2074a72018-08-14 10:23:12 +010019#include "test/framework/test_framework_integ_test.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000020#endif
21
Gabor Kerteszeb953f52018-07-17 13:36:28 +020022#include "target_cfg.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000023#include "Driver_USART.h"
24
25/* For UART the CMSIS driver is used */
Gabor Kerteszeb953f52018-07-17 13:36:28 +020026extern ARM_DRIVER_USART NS_DRIVER_STDIO;
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000027
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020028/**
29 * \brief Modified table template for user defined SVC functions
30 *
31 * \details RTX has a weak definition of osRtxUserSVC, which
32 * is overridden here
33 */
34extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
35 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
36 (void *)USER_SVC_COUNT,
37
38#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
39
40 /* SVC API for Services */
41 LIST_SVC_NSPM
42
43#undef X
44
45/*
46 * (void *)user_function1,
47 * ...
48 */
49};
50
Gabor Kerteszeb953f52018-07-17 13:36:28 +020051/* Struct FILE is implemented in stdio.h. Used to redirect printf to
52 * NS_DRIVER_STDIO
53 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000054FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020055/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000056int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020057 /* Send byte to NS_DRIVER_STDIO */
58 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000059 /* Return character written */
60 return ch;
61}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020062/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000063int _write(int fd, char * str, int len)
64{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020065 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000066
67 return len;
68}
69
70/**
71 * \brief List of RTOS thread attributes
72 */
73#ifdef TEST_FRAMEWORK_NS
74static const osThreadAttr_t tserv_test = {
75 .name = "test_app",
76 .stack_size = 1024U
77};
78#endif
79
80/**
81 * \brief Static globals to hold RTOS related quantities,
82 * main thread
83 */
84static osStatus_t status;
85static osThreadId_t thread_id;
86
87/**
88 * \brief main() function
89 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010090#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000091__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010092#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000093int main(void)
94{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020095 (void)NS_DRIVER_STDIO.Initialize(NULL);
96 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000097
98 status = osKernelInitialize();
99
100 /* Initialize the TFM NS lock */
101 tfm_ns_lock_init();
102
103#ifdef TEST_FRAMEWORK_NS
104 thread_id = osThreadNew(test_app, NULL, &tserv_test);
105#else
106 UNUSED_VARIABLE(thread_id);
107#endif
108
109 status = osKernelStart();
110
111 /* Reached only in case of error */
112 for (;;) {
113 }
114}