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" |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 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 |
Tamas Ban | c2074a7 | 2018-08-14 10:23:12 +0100 | [diff] [blame] | 19 | #include "test/framework/test_framework_integ_test.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 20 | #endif |
| 21 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 22 | #include "target_cfg.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 23 | #include "Driver_USART.h" |
| 24 | |
| 25 | /* For UART the CMSIS driver is used */ |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 26 | extern ARM_DRIVER_USART NS_DRIVER_STDIO; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 27 | |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 28 | /** |
| 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 | */ |
| 34 | extern 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 */ |
| 41 | LIST_SVC_NSPM |
| 42 | |
| 43 | #undef X |
| 44 | |
| 45 | /* |
| 46 | * (void *)user_function1, |
| 47 | * ... |
| 48 | */ |
| 49 | }; |
| 50 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 51 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to |
| 52 | * NS_DRIVER_STDIO |
| 53 | */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 54 | FILE __stdout; |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 55 | /* Redirects armclang printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 56 | int fputc(int ch, FILE *f) { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 57 | /* Send byte to NS_DRIVER_STDIO */ |
| 58 | (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 59 | /* Return character written */ |
| 60 | return ch; |
| 61 | } |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 62 | /* redirects gcc printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 63 | int _write(int fd, char * str, int len) |
| 64 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 65 | (void)NS_DRIVER_STDIO.Send(str, len); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 66 | |
| 67 | return len; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * \brief List of RTOS thread attributes |
| 72 | */ |
| 73 | #ifdef TEST_FRAMEWORK_NS |
| 74 | static const osThreadAttr_t tserv_test = { |
| 75 | .name = "test_app", |
| 76 | .stack_size = 1024U |
| 77 | }; |
| 78 | #endif |
| 79 | |
| 80 | /** |
| 81 | * \brief Static globals to hold RTOS related quantities, |
| 82 | * main thread |
| 83 | */ |
| 84 | static osStatus_t status; |
| 85 | static osThreadId_t thread_id; |
| 86 | |
| 87 | /** |
| 88 | * \brief main() function |
| 89 | */ |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 90 | #ifndef __GNUC__ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 91 | __attribute__((noreturn)) |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 92 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 93 | int main(void) |
| 94 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 95 | (void)NS_DRIVER_STDIO.Initialize(NULL); |
| 96 | NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 97 | |
| 98 | status = osKernelInitialize(); |
| 99 | |
| 100 | /* Initialize the TFM NS lock */ |
| 101 | tfm_ns_lock_init(); |
| 102 | |
| 103 | #ifdef TEST_FRAMEWORK_NS |
| 104 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
| 105 | #else |
| 106 | UNUSED_VARIABLE(thread_id); |
| 107 | #endif |
| 108 | |
| 109 | status = osKernelStart(); |
| 110 | |
| 111 | /* Reached only in case of error */ |
| 112 | for (;;) { |
| 113 | } |
| 114 | } |