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