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