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