blob: f430df73f0c0288e8d7f4df21b342cff668cd7c0 [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 */
34extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
35 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
36 (void *)USER_SVC_COUNT,
37
38#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
39
40 /* SVC API for Services */
Miklos Balint16a9ffb2018-11-19 11:35:49 +010041#ifdef TFM_NS_CLIENT_IDENTIFICATION
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020042 LIST_SVC_NSPM
Miklos Balint16a9ffb2018-11-19 11:35:49 +010043#endif
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020044
45#undef X
46
47/*
48 * (void *)user_function1,
49 * ...
50 */
51};
52
Gabor Kerteszeb953f52018-07-17 13:36:28 +020053/* Struct FILE is implemented in stdio.h. Used to redirect printf to
54 * NS_DRIVER_STDIO
55 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000056FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020057/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000058int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020059 /* Send byte to NS_DRIVER_STDIO */
60 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000061 /* Return character written */
62 return ch;
63}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020064/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000065int _write(int fd, char * str, int len)
66{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020067 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000068
69 return len;
70}
71
72/**
73 * \brief List of RTOS thread attributes
74 */
75#ifdef TEST_FRAMEWORK_NS
76static const osThreadAttr_t tserv_test = {
77 .name = "test_app",
78 .stack_size = 1024U
79};
80#endif
81
82/**
83 * \brief Static globals to hold RTOS related quantities,
84 * main thread
85 */
86static osStatus_t status;
87static osThreadId_t thread_id;
88
89/**
90 * \brief main() function
91 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010092#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000093__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010094#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000095int main(void)
96{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020097 (void)NS_DRIVER_STDIO.Initialize(NULL);
98 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000099
100 status = osKernelInitialize();
101
102 /* Initialize the TFM NS lock */
103 tfm_ns_lock_init();
104
105#ifdef TEST_FRAMEWORK_NS
106 thread_id = osThreadNew(test_app, NULL, &tserv_test);
107#else
108 UNUSED_VARIABLE(thread_id);
109#endif
110
111 status = osKernelStart();
112
113 /* Reached only in case of error */
114 for (;;) {
115 }
116}