1 /*
2  * Copyright (c) 2016-2022 Arm Limited
3  * Copyright (c) 2023 Nuvoton Technology Corp.
4  *
5  * Licensed under the Apache License Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing software
12  * distributed under the License is distributed on an "AS IS" BASIS
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /**
19  * \file platform_retarget_dev.c
20  * \brief This file defines exports the structures based on the peripheral
21  * definitions from device_cfg.h.
22  * This retarget file is meant to be used as a helper for baremetal
23  * applications and/or as an example of how to configure the generic
24  * driver structures.
25  */
26 
27 #include "NuMicro.h"
28 #include "platform_retarget_dev.h"
29 #include "platform_retarget.h"
30 #include "system_core_init.h"
31 #include "tfm_plat_defs.h"
32 
33 /* ARM UART driver structures */
34 #ifdef ARM_UART0_S
35 static const struct arm_uart_dev_cfg_t ARM_UART0_DEV_CFG_S = {
36     .base = UART0_BASE_S,
37     .default_baudrate = DEFAULT_UART_BAUDRATE};
38 static struct arm_uart_dev_data_t ARM_UART0_DEV_DATA_S = {
39     .state = 0,
40     .system_clk = 0,
41     .baudrate = 0};
42 struct arm_uart_dev_t ARM_UART0_DEV_S = {&(ARM_UART0_DEV_CFG_S),
43                                          &(ARM_UART0_DEV_DATA_S)};
44 #endif
45 #ifdef ARM_UART0_NS
46 static const struct arm_uart_dev_cfg_t ARM_UART0_DEV_CFG_NS = {
47     .base = UART0_BASE_NS,
48     .default_baudrate = DEFAULT_UART_BAUDRATE};
49 static struct arm_uart_dev_data_t ARM_UART0_DEV_DATA_NS = {
50     .state = 0,
51     .system_clk = 0,
52     .baudrate = 0};
53 struct arm_uart_dev_t ARM_UART0_DEV_NS = {&(ARM_UART0_DEV_CFG_NS),
54                                           &(ARM_UART0_DEV_DATA_NS)};
55 #endif
56 
57 /* CMSDK Timer driver structures */
58 
59 /* CMSDK Timer driver structures */
60 #ifdef CMSDK_TIMER0_S
61 static const struct cmsdk_timer_dev_cfg_t CMSDK_TIMER0_DEV_CFG_S
62 #ifdef TFM_PARTITION_SLIH_TEST
63     TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_SLIH_TEST", "APP-ROT")
64 #elif defined(TFM_PARTITION_FLIH_TEST)
65     TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_FLIH_TEST", "APP-ROT")
66 #endif
67     = {.base = CMSDK_TIMER0_BASE_S};
68 static struct cmsdk_timer_dev_data_t CMSDK_TIMER0_DEV_DATA_S
69 #ifdef TFM_PARTITION_SLIH_TEST
70     TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_SLIH_TEST", "APP-ROT")
71 #elif defined(TFM_PARTITION_FLIH_TEST)
72     TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_FLIH_TEST", "APP-ROT")
73 #endif
74     = {.is_initialized = 0};
75 
76 struct cmsdk_timer_dev_t CMSDK_TIMER0_DEV_S
77 #ifdef TFM_PARTITION_SLIH_TEST
78     TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_SLIH_TEST", "APP-ROT")
79 #elif defined(TFM_PARTITION_FLIH_TEST)
80     TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_FLIH_TEST", "APP-ROT")
81 #endif
82        = {&(CMSDK_TIMER0_DEV_CFG_S), &(CMSDK_TIMER0_DEV_DATA_S)};
83 #endif
84 #ifdef CMSDK_TIMER0_NS
85 static const struct cmsdk_timer_dev_cfg_t CMSDK_TIMER0_DEV_CFG_NS = {
86     .base = CMSDK_TIMER0_BASE_NS};
87 static struct cmsdk_timer_dev_data_t CMSDK_TIMER0_DEV_DATA_NS = {
88     .is_initialized = 0};
89 struct cmsdk_timer_dev_t CMSDK_TIMER0_DEV_NS = {&(CMSDK_TIMER0_DEV_CFG_NS),
90                                                 &(CMSDK_TIMER0_DEV_DATA_NS)};
91 #endif
92 
93 #ifdef CMSDK_TIMER1_S
94 static const struct cmsdk_timer_dev_cfg_t CMSDK_TIMER1_DEV_CFG_S = {
95     .base = CMSDK_TIMER1_BASE_S};
96 static struct cmsdk_timer_dev_data_t CMSDK_TIMER1_DEV_DATA_S = {
97     .is_initialized = 0};
98 struct cmsdk_timer_dev_t CMSDK_TIMER1_DEV_S = {&(CMSDK_TIMER1_DEV_CFG_S),
99                                                &(CMSDK_TIMER1_DEV_DATA_S)};
100 #endif
101 #ifdef CMSDK_TIMER1_NS
102 static const struct cmsdk_timer_dev_cfg_t CMSDK_TIMER1_DEV_CFG_NS = {
103     .base = CMSDK_TIMER1_BASE_NS};
104 static struct cmsdk_timer_dev_data_t CMSDK_TIMER1_DEV_DATA_NS = {
105     .is_initialized = 0};
106 struct cmsdk_timer_dev_t CMSDK_TIMER1_DEV_NS = {&(CMSDK_TIMER1_DEV_CFG_NS),
107                                                 &(CMSDK_TIMER1_DEV_DATA_NS)};
108 #endif
109 
110