blob: e50686794441513dac2177554f1a0cf46db5d00a [file] [log] [blame]
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00001/*
Jamie Fox5592db02017-12-18 16:48:29 +00002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +00003 *
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 Angelisa54ed7e2017-11-29 13:37:58 +000016#include "tfm_ns_lock.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000017#ifdef TEST_FRAMEWORK_NS
18#include "test/framework/integ_test.h"
19#endif
20
Gabor Kerteszeb953f52018-07-17 13:36:28 +020021#include "target_cfg.h"
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000022#include "Driver_USART.h"
23
24/* For UART the CMSIS driver is used */
Gabor Kerteszeb953f52018-07-17 13:36:28 +020025extern ARM_DRIVER_USART NS_DRIVER_STDIO;
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000026
Gabor Kerteszeb953f52018-07-17 13:36:28 +020027/* Struct FILE is implemented in stdio.h. Used to redirect printf to
28 * NS_DRIVER_STDIO
29 */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000030FILE __stdout;
Gabor Kerteszeb953f52018-07-17 13:36:28 +020031/* Redirects armclang printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000032int fputc(int ch, FILE *f) {
Gabor Kerteszeb953f52018-07-17 13:36:28 +020033 /* Send byte to NS_DRIVER_STDIO */
34 (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000035 /* Return character written */
36 return ch;
37}
Gabor Kerteszeb953f52018-07-17 13:36:28 +020038/* redirects gcc printf to NS_DRIVER_STDIO */
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000039int _write(int fd, char * str, int len)
40{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020041 (void)NS_DRIVER_STDIO.Send(str, len);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000042
43 return len;
44}
45
46/**
47 * \brief List of RTOS thread attributes
48 */
49#ifdef TEST_FRAMEWORK_NS
50static 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 */
60static osStatus_t status;
61static osThreadId_t thread_id;
62
63/**
64 * \brief main() function
65 */
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010066#ifndef __GNUC__
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000067__attribute__((noreturn))
Mate Toth-Pal31a2d962018-03-09 13:14:44 +010068#endif
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000069int main(void)
70{
Gabor Kerteszeb953f52018-07-17 13:36:28 +020071 (void)NS_DRIVER_STDIO.Initialize(NULL);
72 NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
Antonio de Angelisa54ed7e2017-11-29 13:37:58 +000073
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}