blob: fd40820f90b52033ec8e29c6667469de786f008d [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
26#include "Driver_USART.h"
27
28/* For UART the CMSIS driver is used */
29extern ARM_DRIVER_USART Driver_USART0;
30
31/**
32 * \brief Modified table template for user defined SVC functions
33 *
34 * \details RTX has a weak definition of osRtxUserSVC, which
35 * is overridden here
36 */
37extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
38 void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
39 (void *)USER_SVC_COUNT,
40
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010041#define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER,
42 /* SVC API for Services */
43 LIST_SVC_DISPATCHERS
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000044
45#if defined(CORE_TEST_INTERACTIVE)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010046 LIST_SVC_CORE_TEST_INTERACTIVE
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000047#endif /* CORE_TEST_INTERACTIVE */
48
Mate Toth-Pal349714a2018-02-23 15:30:24 +010049#if defined(TFM_PARTITION_TEST_CORE)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010050 LIST_SVC_TFM_PARTITION_TEST_CORE
Mate Toth-Pal349714a2018-02-23 15:30:24 +010051#endif /* TFM_PARTITION_TEST_CORE */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000052
Mate Toth-Pal349714a2018-02-23 15:30:24 +010053#if defined(TFM_PARTITION_TEST_SST)
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010054 LIST_SVC_TFM_PARTITION_TEST_SST
Mate Toth-Pal349714a2018-02-23 15:30:24 +010055#endif /* TFM_PARTITION_TEST_SST */
Jamie Fox5592db02017-12-18 16:48:29 +000056
Ben Davis6d7256b2018-04-18 14:16:53 +010057#if defined(TFM_PARTITION_TEST_SECURE_SERVICES)
58 LIST_SVC_TFM_PARTITION_TEST_SECURE_SERVICES
59#endif /* TFM_PARTITION_TEST_SECURE_SERVICES */
60
Antonio de Angelisd9cd66e2018-03-27 11:19:59 +010061#undef X
62
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000063//(void *)user_function1,
64// ...
65};
66
67/* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */
68FILE __stdout;
69/* Redirects armclang printf to UART */
70int fputc(int ch, FILE *f) {
71 /* Send byte to UART0 */
72 (void)Driver_USART0.Send((const unsigned char *)&ch, 1);
73 /* Return character written */
74 return ch;
75}
76/* redirects gcc printf to uart */
77int _write(int fd, char * str, int len)
78{
79 (void)Driver_USART0.Send(str, len);
80
81 return len;
82}
83
84/**
85 * \brief List of RTOS thread attributes
86 */
87#ifdef TEST_FRAMEWORK_NS
88static const osThreadAttr_t tserv_test = {
89 .name = "test_app",
90 .stack_size = 1024U
91};
92#endif
93
94/**
95 * \brief Static globals to hold RTOS related quantities,
96 * main thread
97 */
98static osStatus_t status;
99static osThreadId_t thread_id;
100
101/**
102 * \brief main() function
103 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100104#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000105__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +0100106#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +0000107int main(void)
108{
109 (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */
110 Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
111
112 status = osKernelInitialize();
113
114 /* Initialize the TFM NS lock */
115 tfm_ns_lock_init();
116
117#ifdef TEST_FRAMEWORK_NS
118 thread_id = osThreadNew(test_app, NULL, &tserv_test);
119#else
120 UNUSED_VARIABLE(thread_id);
121#endif
122
123 status = osKernelStart();
124
125 /* Reached only in case of error */
126 for (;;) {
127 }
128}