blob: 1e23f16b92b3d0cb5b62612e83c1d3e515c5db34 [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 */
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000034#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004))
35/* Workaround needed for a bug in Armclang 6.11, more details at:
36 * http://www.keil.com/support/docs/4089.htm
37 */
38__attribute__((section(".gnu.linkonce")))
39#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020040extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
41 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
42 (void *)USER_SVC_COUNT,
43
44#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
45
46 /* SVC API for Services */
Miklos Balint16a9ffb2018-11-19 11:35:49 +010047#ifdef TFM_NS_CLIENT_IDENTIFICATION
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020048 LIST_SVC_NSPM
Miklos Balint16a9ffb2018-11-19 11:35:49 +010049#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020050
51#undef X
52
53/*
54 * (void *)user_function1,
55 * ...
56 */
57};
58
Gabor Kerteszeb953f52018-07-17 13:36:28 +020059/* Struct FILE is implemented in stdio.h. Used to redirect printf to
60 * NS_DRIVER_STDIO
61 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000062FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020063/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000064int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020065 /* Send byte to NS_DRIVER_STDIO */
66 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000067 /* Return character written */
68 return ch;
69}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020070/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000071int _write(int fd, char * str, int len)
72{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020073 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000074
75 return len;
76}
77
78/**
79 * \brief List of RTOS thread attributes
80 */
81#ifdef TEST_FRAMEWORK_NS
82static const osThreadAttr_t tserv_test = {
83 .name = "test_app",
84 .stack_size = 1024U
85};
86#endif
87
88/**
89 * \brief Static globals to hold RTOS related quantities,
90 * main thread
91 */
92static osStatus_t status;
93static osThreadId_t thread_id;
94
95/**
96 * \brief main() function
97 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010098#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000099__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100100#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000101int main(void)
102{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200103 (void)NS_DRIVER_STDIO.Initialize(NULL);
104 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000105
106 status = osKernelInitialize();
107
108 /* Initialize the TFM NS lock */
109 tfm_ns_lock_init();
110
111#ifdef TEST_FRAMEWORK_NS
112 thread_id = osThreadNew(test_app, NULL, &tserv_test);
113#else
114 UNUSED_VARIABLE(thread_id);
115#endif
116
117 status = osKernelStart();
118
119 /* Reached only in case of error */
120 for (;;) {
121 }
122}