blob: 94eebc869b84f6aad2519ea68839ec1e87bfbb40 [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"
16#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
19#include "test/framework/integ_test.h"
20#endif
Ben Davis6d7256b2018-04-18 14:16:53 +010021#ifdef TFM_PARTITION_TEST_SECURE_SERVICES
22#include \
23 "test/test_services/tfm_secure_client_service/tfm_secure_client_service_svc.h"
24#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000025
Gabor Kerteszeb953f52018-07-17 13:36:28 +020026#include "target_cfg.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000027#include "Driver_USART.h"
28
29/* For UART the CMSIS driver is used */
Gabor Kerteszeb953f52018-07-17 13:36:28 +020030extern ARM_DRIVER_USART NS_DRIVER_STDIO;
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000031
32/**
33 * \brief Modified table template for user defined SVC functions
34 *
35 * \details RTX has a weak definition of osRtxUserSVC, which
36 * is overridden here
37 */
38extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
39 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
40 (void *)USER_SVC_COUNT,
41
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010042#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
43 /* SVC API for Services */
44 LIST_SVC_DISPATCHERS
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000045
46#if defined(CORE_TEST_INTERACTIVE)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010047 LIST_SVC_CORE_TEST_INTERACTIVE
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000048#endif /* CORE_TEST_INTERACTIVE */
49
Mate Toth-Pal349714a2018-02-23 15:30:24 +010050#if defined(TFM_PARTITION_TEST_CORE)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010051 LIST_SVC_TFM_PARTITION_TEST_CORE
Mate Toth-Pal349714a2018-02-23 15:30:24 +010052#endif /* TFM_PARTITION_TEST_CORE */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000053
Mate Toth-Pal349714a2018-02-23 15:30:24 +010054#if defined(TFM_PARTITION_TEST_SST)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010055 LIST_SVC_TFM_PARTITION_TEST_SST
Mate Toth-Pal349714a2018-02-23 15:30:24 +010056#endif /* TFM_PARTITION_TEST_SST */
Jamie Fox5592db02017-12-18 16:48:29 +000057
Ben Davis6d7256b2018-04-18 14:16:53 +010058#if defined(TFM_PARTITION_TEST_SECURE_SERVICES)
59 LIST_SVC_TFM_PARTITION_TEST_SECURE_SERVICES
60#endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
61
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010062#undef X
63
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000064//(void *)user_function1,
65// ...
66};
67
Gabor Kerteszeb953f52018-07-17 13:36:28 +020068/* Struct FILE is implemented in stdio.h. Used to redirect printf to
69 * NS_DRIVER_STDIO
70 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000071FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020072/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000073int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020074 /* Send byte to NS_DRIVER_STDIO */
75 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000076 /* Return character written */
77 return ch;
78}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020079/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000080int _write(int fd, char * str, int len)
81{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020082 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000083
84 return len;
85}
86
87/**
88 * \brief List of RTOS thread attributes
89 */
90#ifdef TEST_FRAMEWORK_NS
91static const osThreadAttr_t tserv_test = {
92 .name = "test_app",
93 .stack_size = 1024U
94};
95#endif
96
97/**
98 * \brief Static globals to hold RTOS related quantities,
99 * main thread
100 */
101static osStatus_t status;
102static osThreadId_t thread_id;
103
104/**
105 * \brief main() function
106 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100107#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000108__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100109#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000110int main(void)
111{
Gabor Kerteszeb953f52018-07-17 13:36:28 +0200112 (void)NS_DRIVER_STDIO.Initialize(NULL);
113 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000114
115 status = osKernelInitialize();
116
117 /* Initialize the TFM NS lock */
118 tfm_ns_lock_init();
119
120#ifdef TEST_FRAMEWORK_NS
121 thread_id = osThreadNew(test_app, NULL, &tserv_test);
122#else
123 UNUSED_VARIABLE(thread_id);
124#endif
125
126 status = osKernelStart();
127
128 /* Reached only in case of error */
129 for (;;) {
130 }
131}