Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 3 | * |
| 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 Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 17 | #include "tfm_ns_lock.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 18 | #ifdef TEST_FRAMEWORK_NS |
| 19 | #include "test/framework/integ_test.h" |
| 20 | #endif |
| 21 | |
| 22 | #include "Driver_USART.h" |
| 23 | |
| 24 | /* For UART the CMSIS driver is used */ |
| 25 | extern ARM_DRIVER_USART Driver_USART0; |
| 26 | |
| 27 | /** |
| 28 | * \brief Modified table template for user defined SVC functions |
| 29 | * |
| 30 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 31 | * is overridden here |
| 32 | */ |
| 33 | extern void * const osRtxUserSVC[1+USER_SVC_COUNT]; |
| 34 | void * const osRtxUserSVC[1+USER_SVC_COUNT] = { |
| 35 | (void *)USER_SVC_COUNT, |
| 36 | |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 37 | #define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER, |
| 38 | /* SVC API for Services */ |
| 39 | LIST_SVC_DISPATCHERS |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 40 | |
| 41 | #if defined(CORE_TEST_INTERACTIVE) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 42 | LIST_SVC_CORE_TEST_INTERACTIVE |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 43 | #endif /* CORE_TEST_INTERACTIVE */ |
| 44 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 45 | #if defined(TFM_PARTITION_TEST_CORE) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 46 | LIST_SVC_TFM_PARTITION_TEST_CORE |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 47 | #endif /* TFM_PARTITION_TEST_CORE */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 48 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 49 | #if defined(TFM_PARTITION_TEST_SST) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 50 | LIST_SVC_TFM_PARTITION_TEST_SST |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 51 | #endif /* TFM_PARTITION_TEST_SST */ |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 52 | |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 53 | #undef X |
| 54 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 55 | //(void *)user_function1, |
| 56 | // ... |
| 57 | }; |
| 58 | |
| 59 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */ |
| 60 | FILE __stdout; |
| 61 | /* Redirects armclang printf to UART */ |
| 62 | int fputc(int ch, FILE *f) { |
| 63 | /* Send byte to UART0 */ |
| 64 | (void)Driver_USART0.Send((const unsigned char *)&ch, 1); |
| 65 | /* Return character written */ |
| 66 | return ch; |
| 67 | } |
| 68 | /* redirects gcc printf to uart */ |
| 69 | int _write(int fd, char * str, int len) |
| 70 | { |
| 71 | (void)Driver_USART0.Send(str, len); |
| 72 | |
| 73 | return len; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * \brief List of RTOS thread attributes |
| 78 | */ |
| 79 | #ifdef TEST_FRAMEWORK_NS |
| 80 | static const osThreadAttr_t tserv_test = { |
| 81 | .name = "test_app", |
| 82 | .stack_size = 1024U |
| 83 | }; |
| 84 | #endif |
| 85 | |
| 86 | /** |
| 87 | * \brief Static globals to hold RTOS related quantities, |
| 88 | * main thread |
| 89 | */ |
| 90 | static osStatus_t status; |
| 91 | static osThreadId_t thread_id; |
| 92 | |
| 93 | /** |
| 94 | * \brief main() function |
| 95 | */ |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 96 | #ifndef __GNUC__ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 97 | __attribute__((noreturn)) |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 98 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 99 | int main(void) |
| 100 | { |
| 101 | (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */ |
| 102 | Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
| 103 | |
| 104 | status = osKernelInitialize(); |
| 105 | |
| 106 | /* Initialize the TFM NS lock */ |
| 107 | tfm_ns_lock_init(); |
| 108 | |
| 109 | #ifdef TEST_FRAMEWORK_NS |
| 110 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
| 111 | #else |
| 112 | UNUSED_VARIABLE(thread_id); |
| 113 | #endif |
| 114 | |
| 115 | status = osKernelStart(); |
| 116 | |
| 117 | /* Reached only in case of error */ |
| 118 | for (;;) { |
| 119 | } |
| 120 | } |