Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2017, Arm Limited. All rights reserved. |
| 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" |
| 16 | #include "tfm_ns_svc.h" |
| 17 | #include "tfm_sst_svc_handler.h" |
| 18 | #include "tfm_ns_lock.h" |
| 19 | #ifdef CORE_TEST_SERVICES |
| 20 | #include "test/suites/core/non_secure/svc_core_test_ns.h" |
| 21 | #endif |
| 22 | #ifdef TEST_FRAMEWORK_NS |
| 23 | #include "test/framework/integ_test.h" |
| 24 | #endif |
| 25 | |
| 26 | #include "Driver_USART.h" |
| 27 | |
| 28 | /* For UART the CMSIS driver is used */ |
| 29 | extern ARM_DRIVER_USART Driver_USART0; |
| 30 | |
| 31 | /** |
| 32 | * \brief Modified table template for user defined SVC functions |
| 33 | * |
| 34 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 35 | * is overridden here |
| 36 | */ |
| 37 | extern void * const osRtxUserSVC[1+USER_SVC_COUNT]; |
| 38 | void * const osRtxUserSVC[1+USER_SVC_COUNT] = { |
| 39 | (void *)USER_SVC_COUNT, |
| 40 | |
| 41 | /* SERVICES_TEST_NS */ |
| 42 | (void *)tfm_sst_svc_get_handle, |
| 43 | (void *)tfm_sst_svc_create, |
| 44 | (void *)tfm_sst_svc_get_attributes, |
| 45 | (void *)tfm_sst_svc_read, |
| 46 | (void *)tfm_sst_svc_write, |
| 47 | (void *)tfm_sst_svc_delete, |
| 48 | |
| 49 | #if defined(CORE_TEST_INTERACTIVE) |
| 50 | (void *)svc_secure_decrement_ns_lock_1, |
| 51 | (void *)svc_secure_decrement_ns_lock_2, |
| 52 | #endif /* CORE_TEST_INTERACTIVE */ |
| 53 | |
| 54 | #if defined(CORE_TEST_SERVICES) |
| 55 | (void *)svc_tfm_core_test, |
| 56 | (void *)svc_tfm_core_test_multiple_calls, |
| 57 | #endif /* CORE_TEST_SERVICES */ |
| 58 | |
| 59 | //(void *)user_function1, |
| 60 | // ... |
| 61 | }; |
| 62 | |
| 63 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */ |
| 64 | FILE __stdout; |
| 65 | /* Redirects armclang printf to UART */ |
| 66 | int fputc(int ch, FILE *f) { |
| 67 | /* Send byte to UART0 */ |
| 68 | (void)Driver_USART0.Send((const unsigned char *)&ch, 1); |
| 69 | /* Return character written */ |
| 70 | return ch; |
| 71 | } |
| 72 | /* redirects gcc printf to uart */ |
| 73 | int _write(int fd, char * str, int len) |
| 74 | { |
| 75 | (void)Driver_USART0.Send(str, len); |
| 76 | |
| 77 | return len; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * \brief List of RTOS thread attributes |
| 82 | */ |
| 83 | #ifdef TEST_FRAMEWORK_NS |
| 84 | static const osThreadAttr_t tserv_test = { |
| 85 | .name = "test_app", |
| 86 | .stack_size = 1024U |
| 87 | }; |
| 88 | #endif |
| 89 | |
| 90 | /** |
| 91 | * \brief Static globals to hold RTOS related quantities, |
| 92 | * main thread |
| 93 | */ |
| 94 | static osStatus_t status; |
| 95 | static osThreadId_t thread_id; |
| 96 | |
| 97 | /** |
| 98 | * \brief main() function |
| 99 | */ |
| 100 | __attribute__((noreturn)) |
| 101 | int main(void) |
| 102 | { |
| 103 | (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */ |
| 104 | Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
| 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 | } |