blob: c648dfe3db15728e9b2a1f83f21cb2750b7179f1 [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
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000012#include "tfm_api.h"
13#include "cmsis_os2.h"
14#include "tfm_integ_test.h"
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020015#include "tfm_ns_svc.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000016#include "tfm_ns_lock.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000017#ifdef TEST_FRAMEWORK_NS
Tamas Banc2074a72018-08-14 10:23:12 +010018#include "test/framework/test_framework_integ_test.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000019#endif
Jamie Fox17c30bb2019-01-10 13:39:33 +000020#ifdef PSA_API_TEST_NS
21#include "psa_api_test.h"
22#endif
Gabor Kerteszeb953f52018-07-17 13:36:28 +020023#include "target_cfg.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000024#include "Driver_USART.h"
25
26/* For UART the CMSIS driver is used */
Gabor Kerteszeb953f52018-07-17 13:36:28 +020027extern ARM_DRIVER_USART NS_DRIVER_STDIO;
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000028
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020029/**
30 * \brief Modified table template for user defined SVC functions
31 *
32 * \details RTX has a weak definition of osRtxUserSVC, which
33 * is overridden here
34 */
Antonio de Angelisf1f7ebd2018-11-23 23:11:41 +000035#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004))
36/* Workaround needed for a bug in Armclang 6.11, more details at:
37 * http://www.keil.com/support/docs/4089.htm
38 */
39__attribute__((section(".gnu.linkonce")))
40#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020041extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
42 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
43 (void *)USER_SVC_COUNT,
44
45#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
46
47 /* SVC API for Services */
Miklos Balint16a9ffb2018-11-19 11:35:49 +010048#ifdef TFM_NS_CLIENT_IDENTIFICATION
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020049 LIST_SVC_NSPM
Miklos Balint16a9ffb2018-11-19 11:35:49 +010050#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020051
52#undef X
53
54/*
55 * (void *)user_function1,
56 * ...
57 */
58};
59
TTornblomc640e072019-06-14 14:33:51 +020060#if defined(__ARMCC_VERSION)
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}
TTornblomc640e072019-06-14 14:33:51 +020072#elif defined(__GNUC__)
Gabor Kerteszeb953f52018-07-17 13:36:28 +020073/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000074int _write(int fd, char * str, int len)
75{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020076 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000077
78 return len;
79}
TTornblomc640e072019-06-14 14:33:51 +020080#elif defined(__ICCARM__)
81int putchar(int ch)
82{
83 /* Send byte to NS_DRIVER_STDIO */
84 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
85 /* Return character written */
86 return ch;
87}
88#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000089
90/**
91 * \brief List of RTOS thread attributes
92 */
93#ifdef TEST_FRAMEWORK_NS
Tamas Banaaf90392019-01-02 13:24:13 +000094/* Allocate dedicated stack for test executor thread.
95 * It must be 64 bit aligned.
96 */
97static uint64_t test_app_stack[(3u * 1024u) / (sizeof(uint64_t))]; /* 3KB */
98
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000099static const osThreadAttr_t tserv_test = {
100 .name = "test_app",
Tamas Banaaf90392019-01-02 13:24:13 +0000101 .stack_size = sizeof(test_app_stack),
102 .stack_mem = test_app_stack,
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000103};
Jamie Fox17c30bb2019-01-10 13:39:33 +0000104#elif PSA_API_TEST_NS
105static const osThreadAttr_t psa_api_test_attr = {
106 .name = "psa_api_test",
107 .stack_size = 3072U
108};
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000109#endif
110
111/**
112 * \brief Static globals to hold RTOS related quantities,
113 * main thread
114 */
115static osStatus_t status;
116static osThreadId_t thread_id;
117
118/**
119 * \brief main() function
120 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100121#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000122__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100123#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000124int main(void)
125{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200126 (void)NS_DRIVER_STDIO.Initialize(NULL);
127 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000128
129 status = osKernelInitialize();
130
131 /* Initialize the TFM NS lock */
132 tfm_ns_lock_init();
133
134#ifdef TEST_FRAMEWORK_NS
135 thread_id = osThreadNew(test_app, NULL, &tserv_test);
Jamie Fox17c30bb2019-01-10 13:39:33 +0000136#elif PSA_API_TEST_NS
137 thread_id = osThreadNew(psa_api_test, NULL, &psa_api_test_attr);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000138#else
139 UNUSED_VARIABLE(thread_id);
140#endif
141
142 status = osKernelStart();
143
144 /* Reached only in case of error */
145 for (;;) {
146 }
147}