blob: fb7b10a612a790d8dd621a1e27816cf9ef114a74 [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"
17#include "tfm_sst_svc_handler.h"
18#include "tfm_ns_lock.h"
19#ifdef CORE_TEST_SERVICES
20#include "test/suites/core/non_secure/svc_core_test_ns.h"
21#endif
Jamie Fox5592db02017-12-18 16:48:29 +000022#ifdef SST_TEST_SERVICES
23#include "test/test_services/tfm_sst_test_service/sst_test_service_svc.h"
24#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000025#ifdef TEST_FRAMEWORK_NS
26#include "test/framework/integ_test.h"
27#endif
28
29#include "Driver_USART.h"
30
31/* For UART the CMSIS driver is used */
32extern ARM_DRIVER_USART Driver_USART0;
33
34/**
35 * \brief Modified table template for user defined SVC functions
36 *
37 * \details RTX has a weak definition of osRtxUserSVC, which
38 * is overridden here
39 */
40extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
41 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
42 (void *)USER_SVC_COUNT,
43
44/* SERVICES_TEST_NS */
45 (void *)tfm_sst_svc_get_handle,
46 (void *)tfm_sst_svc_create,
47 (void *)tfm_sst_svc_get_attributes,
48 (void *)tfm_sst_svc_read,
49 (void *)tfm_sst_svc_write,
50 (void *)tfm_sst_svc_delete,
51
52#if defined(CORE_TEST_INTERACTIVE)
53 (void *)svc_secure_decrement_ns_lock_1,
54 (void *)svc_secure_decrement_ns_lock_2,
55#endif /* CORE_TEST_INTERACTIVE */
56
57#if defined(CORE_TEST_SERVICES)
58 (void *)svc_tfm_core_test,
59 (void *)svc_tfm_core_test_multiple_calls,
60#endif /* CORE_TEST_SERVICES */
61
Jamie Fox5592db02017-12-18 16:48:29 +000062#if defined(SST_TEST_SERVICES)
63 (void *)sst_test_service_svc_setup,
64 (void *)sst_test_service_svc_dummy_encrypt,
65 (void *)sst_test_service_svc_dummy_decrypt,
66 (void *)sst_test_service_svc_clean,
67#endif /* SST_TEST_SERVICES */
68
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000069//(void *)user_function1,
70// ...
71};
72
73/* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */
74FILE __stdout;
75/* Redirects armclang printf to UART */
76int fputc(int ch, FILE *f) {
77 /* Send byte to UART0 */
78 (void)Driver_USART0.Send((const unsigned char *)&ch, 1);
79 /* Return character written */
80 return ch;
81}
82/* redirects gcc printf to uart */
83int _write(int fd, char * str, int len)
84{
85 (void)Driver_USART0.Send(str, len);
86
87 return len;
88}
89
90/**
91 * \brief List of RTOS thread attributes
92 */
93#ifdef TEST_FRAMEWORK_NS
94static const osThreadAttr_t tserv_test = {
95 .name = "test_app",
96 .stack_size = 1024U
97};
98#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 */
110__attribute__((noreturn))
111int main(void)
112{
113 (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */
114 Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
115
116 status = osKernelInitialize();
117
118 /* Initialize the TFM NS lock */
119 tfm_ns_lock_init();
120
121#ifdef TEST_FRAMEWORK_NS
122 thread_id = osThreadNew(test_app, NULL, &tserv_test);
123#else
124 UNUSED_VARIABLE(thread_id);
125#endif
126
127 status = osKernelStart();
128
129 /* Reached only in case of error */
130 for (;;) {
131 }
132}