blob: e4bf5d6b68e4f531b1ce1312ed7c55dc86952e04 [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
Tamas Banaaf90392019-01-02 13:24:13 +000084/* Allocate dedicated stack for test executor thread.
85 * It must be 64 bit aligned.
86 */
87static uint64_t test_app_stack[(3u * 1024u) / (sizeof(uint64_t))]; /* 3KB */
88
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000089static const osThreadAttr_t tserv_test = {
90 .name = "test_app",
Tamas Banaaf90392019-01-02 13:24:13 +000091 .stack_size = sizeof(test_app_stack),
92 .stack_mem = test_app_stack,
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000093};
Jamie Fox17c30bb2019-01-10 13:39:33 +000094#elif PSA_API_TEST_NS
95static const osThreadAttr_t psa_api_test_attr = {
96 .name = "psa_api_test",
97 .stack_size = 3072U
98};
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000099#endif
100
101/**
102 * \brief Static globals to hold RTOS related quantities,
103 * main thread
104 */
105static osStatus_t status;
106static osThreadId_t thread_id;
107
108/**
109 * \brief main() function
110 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100111#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000112__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100113#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000114int main(void)
115{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200116 (void)NS_DRIVER_STDIO.Initialize(NULL);
117 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000118
119 status = osKernelInitialize();
120
121 /* Initialize the TFM NS lock */
122 tfm_ns_lock_init();
123
124#ifdef TEST_FRAMEWORK_NS
125 thread_id = osThreadNew(test_app, NULL, &tserv_test);
Jamie Fox17c30bb2019-01-10 13:39:33 +0000126#elif PSA_API_TEST_NS
127 thread_id = osThreadNew(psa_api_test, NULL, &psa_api_test_attr);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000128#else
129 UNUSED_VARIABLE(thread_id);
130#endif
131
132 status = osKernelStart();
133
134 /* Reached only in case of error */
135 for (;;) {
136 }
137}