blob: 0205b1b7582bbf5924d20525a8ac30ba72c9b1e4 [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
Gabor Kerteszeb953f52018-07-17 13:36:28 +020060/* Struct FILE is implemented in stdio.h. Used to redirect printf to
61 * NS_DRIVER_STDIO
62 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000063FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020064/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000065int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020066 /* Send byte to NS_DRIVER_STDIO */
67 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000068 /* Return character written */
69 return ch;
70}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020071/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000072int _write(int fd, char * str, int len)
73{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020074 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000075
76 return len;
77}
78
79/**
80 * \brief List of RTOS thread attributes
81 */
82#ifdef TEST_FRAMEWORK_NS
Tamas Banaaf90392019-01-02 13:24:13 +000083/* Allocate dedicated stack for test executor thread.
84 * It must be 64 bit aligned.
85 */
86static uint64_t test_app_stack[(3u * 1024u) / (sizeof(uint64_t))]; /* 3KB */
87
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000088static const osThreadAttr_t tserv_test = {
89 .name = "test_app",
Tamas Banaaf90392019-01-02 13:24:13 +000090 .stack_size = sizeof(test_app_stack),
91 .stack_mem = test_app_stack,
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000092};
Jamie Fox17c30bb2019-01-10 13:39:33 +000093#elif PSA_API_TEST_NS
94static const osThreadAttr_t psa_api_test_attr = {
95 .name = "psa_api_test",
96 .stack_size = 3072U
97};
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000098#endif
99
100/**
101 * \brief Static globals to hold RTOS related quantities,
102 * main thread
103 */
104static osStatus_t status;
105static osThreadId_t thread_id;
106
107/**
108 * \brief main() function
109 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100110#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000111__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100112#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000113int main(void)
114{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200115 (void)NS_DRIVER_STDIO.Initialize(NULL);
116 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000117
118 status = osKernelInitialize();
119
120 /* Initialize the TFM NS lock */
121 tfm_ns_lock_init();
122
123#ifdef TEST_FRAMEWORK_NS
124 thread_id = osThreadNew(test_app, NULL, &tserv_test);
Jamie Fox17c30bb2019-01-10 13:39:33 +0000125#elif PSA_API_TEST_NS
126 thread_id = osThreadNew(psa_api_test, NULL, &psa_api_test_attr);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000127#else
128 UNUSED_VARIABLE(thread_id);
129#endif
130
131 status = osKernelStart();
132
133 /* Reached only in case of error */
134 for (;;) {
135 }
136}