Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 12 | #include "tfm_api.h" |
| 13 | #include "cmsis_os2.h" |
| 14 | #include "tfm_integ_test.h" |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 15 | #include "tfm_ns_svc.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 16 | #include "tfm_ns_lock.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 17 | #ifdef TEST_FRAMEWORK_NS |
Tamas Ban | c2074a7 | 2018-08-14 10:23:12 +0100 | [diff] [blame] | 18 | #include "test/framework/test_framework_integ_test.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 19 | #endif |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 20 | #ifdef PSA_API_TEST_NS |
| 21 | #include "psa_api_test.h" |
| 22 | #endif |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 23 | #include "target_cfg.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 24 | #include "Driver_USART.h" |
| 25 | |
| 26 | /* For UART the CMSIS driver is used */ |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 27 | extern ARM_DRIVER_USART NS_DRIVER_STDIO; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 28 | |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 29 | /** |
| 30 | * \brief Modified table template for user defined SVC functions |
| 31 | * |
| 32 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 33 | * is overridden here |
| 34 | */ |
Antonio de Angelis | f1f7ebd | 2018-11-23 23:11:41 +0000 | [diff] [blame] | 35 | #if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION == 6110004)) |
| 36 | /* Workaround needed for a bug in Armclang 6.11, more details at: |
| 37 | * http://www.keil.com/support/docs/4089.htm |
| 38 | */ |
| 39 | __attribute__((section(".gnu.linkonce"))) |
| 40 | #endif |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 41 | extern void * const osRtxUserSVC[1+USER_SVC_COUNT]; |
| 42 | void * const osRtxUserSVC[1+USER_SVC_COUNT] = { |
| 43 | (void *)USER_SVC_COUNT, |
| 44 | |
| 45 | #define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER, |
| 46 | |
| 47 | /* SVC API for Services */ |
Miklos Balint | 16a9ffb | 2018-11-19 11:35:49 +0100 | [diff] [blame] | 48 | #ifdef TFM_NS_CLIENT_IDENTIFICATION |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 49 | LIST_SVC_NSPM |
Miklos Balint | 16a9ffb | 2018-11-19 11:35:49 +0100 | [diff] [blame] | 50 | #endif |
Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame] | 51 | |
| 52 | #undef X |
| 53 | |
| 54 | /* |
| 55 | * (void *)user_function1, |
| 56 | * ... |
| 57 | */ |
| 58 | }; |
| 59 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 60 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to |
| 61 | * NS_DRIVER_STDIO |
| 62 | */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 63 | FILE __stdout; |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 64 | /* Redirects armclang printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 65 | int fputc(int ch, FILE *f) { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 66 | /* Send byte to NS_DRIVER_STDIO */ |
| 67 | (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 68 | /* Return character written */ |
| 69 | return ch; |
| 70 | } |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 71 | /* redirects gcc printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 72 | int _write(int fd, char * str, int len) |
| 73 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 74 | (void)NS_DRIVER_STDIO.Send(str, len); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 75 | |
| 76 | return len; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * \brief List of RTOS thread attributes |
| 81 | */ |
| 82 | #ifdef TEST_FRAMEWORK_NS |
Tamas Ban | aaf9039 | 2019-01-02 13:24:13 +0000 | [diff] [blame] | 83 | /* Allocate dedicated stack for test executor thread. |
| 84 | * It must be 64 bit aligned. |
| 85 | */ |
| 86 | static uint64_t test_app_stack[(3u * 1024u) / (sizeof(uint64_t))]; /* 3KB */ |
| 87 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 88 | static const osThreadAttr_t tserv_test = { |
| 89 | .name = "test_app", |
Tamas Ban | aaf9039 | 2019-01-02 13:24:13 +0000 | [diff] [blame] | 90 | .stack_size = sizeof(test_app_stack), |
| 91 | .stack_mem = test_app_stack, |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 92 | }; |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 93 | #elif PSA_API_TEST_NS |
| 94 | static const osThreadAttr_t psa_api_test_attr = { |
| 95 | .name = "psa_api_test", |
| 96 | .stack_size = 3072U |
| 97 | }; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | /** |
| 101 | * \brief Static globals to hold RTOS related quantities, |
| 102 | * main thread |
| 103 | */ |
| 104 | static osStatus_t status; |
| 105 | static osThreadId_t thread_id; |
| 106 | |
| 107 | /** |
| 108 | * \brief main() function |
| 109 | */ |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 110 | #ifndef __GNUC__ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 111 | __attribute__((noreturn)) |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 112 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 113 | int main(void) |
| 114 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 115 | (void)NS_DRIVER_STDIO.Initialize(NULL); |
| 116 | NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 117 | |
| 118 | status = osKernelInitialize(); |
| 119 | |
| 120 | /* Initialize the TFM NS lock */ |
| 121 | tfm_ns_lock_init(); |
| 122 | |
| 123 | #ifdef TEST_FRAMEWORK_NS |
| 124 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
Jamie Fox | 17c30bb | 2019-01-10 13:39:33 +0000 | [diff] [blame] | 125 | #elif PSA_API_TEST_NS |
| 126 | thread_id = osThreadNew(psa_api_test, NULL, &psa_api_test_attr); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 127 | #else |
| 128 | UNUSED_VARIABLE(thread_id); |
| 129 | #endif |
| 130 | |
| 131 | status = osKernelStart(); |
| 132 | |
| 133 | /* Reached only in case of error */ |
| 134 | for (;;) { |
| 135 | } |
| 136 | } |