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" |
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 |
| 20 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 21 | #include "target_cfg.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 22 | #include "Driver_USART.h" |
| 23 | |
| 24 | /* For UART the CMSIS driver is used */ |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 25 | extern ARM_DRIVER_USART NS_DRIVER_STDIO; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 26 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 27 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to |
| 28 | * NS_DRIVER_STDIO |
| 29 | */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 30 | FILE __stdout; |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 31 | /* Redirects armclang printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 32 | int fputc(int ch, FILE *f) { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 33 | /* Send byte to NS_DRIVER_STDIO */ |
| 34 | (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 35 | /* Return character written */ |
| 36 | return ch; |
| 37 | } |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 38 | /* redirects gcc printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 39 | int _write(int fd, char * str, int len) |
| 40 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 41 | (void)NS_DRIVER_STDIO.Send(str, len); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 42 | |
| 43 | return len; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * \brief List of RTOS thread attributes |
| 48 | */ |
| 49 | #ifdef TEST_FRAMEWORK_NS |
| 50 | static const osThreadAttr_t tserv_test = { |
| 51 | .name = "test_app", |
| 52 | .stack_size = 1024U |
| 53 | }; |
| 54 | #endif |
| 55 | |
| 56 | /** |
| 57 | * \brief Static globals to hold RTOS related quantities, |
| 58 | * main thread |
| 59 | */ |
| 60 | static osStatus_t status; |
| 61 | static osThreadId_t thread_id; |
| 62 | |
| 63 | /** |
| 64 | * \brief main() function |
| 65 | */ |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 66 | #ifndef __GNUC__ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 67 | __attribute__((noreturn)) |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 68 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 69 | int main(void) |
| 70 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame] | 71 | (void)NS_DRIVER_STDIO.Initialize(NULL); |
| 72 | NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 73 | |
| 74 | status = osKernelInitialize(); |
| 75 | |
| 76 | /* Initialize the TFM NS lock */ |
| 77 | tfm_ns_lock_init(); |
| 78 | |
| 79 | #ifdef TEST_FRAMEWORK_NS |
| 80 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
| 81 | #else |
| 82 | UNUSED_VARIABLE(thread_id); |
| 83 | #endif |
| 84 | |
| 85 | status = osKernelStart(); |
| 86 | |
| 87 | /* Reached only in case of error */ |
| 88 | for (;;) { |
| 89 | } |
| 90 | } |