blob: b6f1786350bef3f06fbb168a4b152de9a12a86e9 [file] [log] [blame]
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00001/*
Jamie Fox17c30bb2019-01-10 13:39:33 +00002 * Copyright (c) 2017-2019, 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
Jamie Fox17c30bb2019-01-10 13:39:33 +000021#ifdef PSA_API_TEST_NS
22#include "psa_api_test.h"
23#endif
Gabor Kerteszeb953f52018-07-17 13:36:28 +020024#include "target_cfg.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000025#include "Driver_USART.h"
26
27/* For UART the CMSIS driver is used */
Gabor Kerteszeb953f52018-07-17 13:36:28 +020028extern ARM_DRIVER_USART NS_DRIVER_STDIO;
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000029
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020030/**
31 * \brief Modified table template for user defined SVC functions
32 *
33 * \details RTX has a weak definition of osRtxUserSVC, which
34 * is overridden here
35 */
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000036#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004))
37/* Workaround needed for a bug in Armclang 6.11, more details at:
38 * http://www.keil.com/support/docs/4089.htm
39 */
40__attribute__((section(".gnu.linkonce")))
41#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020042extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
43 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
44 (void *)USER_SVC_COUNT,
45
46#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
47
48 /* SVC API for Services */
Miklos Balint16a9ffb2018-11-19 11:35:49 +010049#ifdef TFM_NS_CLIENT_IDENTIFICATION
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020050 LIST_SVC_NSPM
Miklos Balint16a9ffb2018-11-19 11:35:49 +010051#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020052
53#undef X
54
55/*
56 * (void *)user_function1,
57 * ...
58 */
59};
60
Gabor Kerteszeb953f52018-07-17 13:36:28 +020061/* Struct FILE is implemented in stdio.h. Used to redirect printf to
62 * NS_DRIVER_STDIO
63 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000064FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020065/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000066int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020067 /* Send byte to NS_DRIVER_STDIO */
68 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000069 /* Return character written */
70 return ch;
71}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020072/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000073int _write(int fd, char * str, int len)
74{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020075 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000076
77 return len;
78}
79
80/**
81 * \brief List of RTOS thread attributes
82 */
83#ifdef TEST_FRAMEWORK_NS
84static const osThreadAttr_t tserv_test = {
85 .name = "test_app",
86 .stack_size = 1024U
87};
Jamie Fox17c30bb2019-01-10 13:39:33 +000088#elif PSA_API_TEST_NS
89static const osThreadAttr_t psa_api_test_attr = {
90 .name = "psa_api_test",
91 .stack_size = 3072U
92};
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000093#endif
94
95/**
96 * \brief Static globals to hold RTOS related quantities,
97 * main thread
98 */
99static osStatus_t status;
100static osThreadId_t thread_id;
101
102/**
103 * \brief main() function
104 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100105#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000106__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100107#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000108int main(void)
109{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200110 (void)NS_DRIVER_STDIO.Initialize(NULL);
111 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000112
113 status = osKernelInitialize();
114
115 /* Initialize the TFM NS lock */
116 tfm_ns_lock_init();
117
118#ifdef TEST_FRAMEWORK_NS
119 thread_id = osThreadNew(test_app, NULL, &tserv_test);
Jamie Fox17c30bb2019-01-10 13:39:33 +0000120#elif PSA_API_TEST_NS
121 thread_id = osThreadNew(psa_api_test, NULL, &psa_api_test_attr);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000122#else
123 UNUSED_VARIABLE(thread_id);
124#endif
125
126 status = osKernelStart();
127
128 /* Reached only in case of error */
129 for (;;) {
130 }
131}