1 /***************************************************************************//**
2 * \file psoc6_system_init_cm4.c
3 * \version 1.00
4 *
5 * The device custom system init source file for CM4 core.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25 #include "cycfg.h"
26 #include "cy_device.h"
27
28 #if defined(CY_IPC_DEFAULT_CFG_DISABLE)
29 #include "cy_ipc_sema.h"
30 #include "cy_ipc_pipe.h"
31 #include "cy_ipc_drv.h"
32
33 #if defined(CY_DEVICE_PSOC6ABLE2)
34 #include "cy_flash.h"
35 #endif /* defined(CY_DEVICE_PSOC6ABLE2) */
36 #endif /* defined(CY_IPC_DEFAULT_CFG_DISABLE) */
37
38 #if defined(CY_DEVICE_SECURE)
39 #include "cy_pra.h"
40 #endif /* defined(CY_DEVICE_SECURE) */
41
42 /* SCB->CPACR */
43 #define SCB_CPACR_CP10_CP11_ENABLE (0xFUL << 20u)
44
45 /*******************************************************************************
46 * Function Name: Cy_SystemInit
47 ****************************************************************************//**
48 *
49 * The function is called during device startup.
50 *
51 *******************************************************************************/
Cy_SystemInit(void)52 void Cy_SystemInit(void)
53 {
54 #if defined(__ARMCC_VERSION)
55 /* FP registers are still accessed inside armclang RTX library
56 * RTX_CM3.lib even with __FPU_USED not defined.
57 * Enable FPU as a temp workaround*/
58 uint32_t interruptState;
59 interruptState = Cy_SysLib_EnterCriticalSection();
60 SCB->CPACR |= SCB_CPACR_CP10_CP11_ENABLE;
61 __DSB();
62 __ISB();
63 Cy_SysLib_ExitCriticalSection(interruptState);
64 #endif
65 }
66
67
68
69 #if defined(CY_IPC_DEFAULT_CFG_DISABLE)
70 /*******************************************************************************
71 * Function Name: Cy_SysIpcPipeIsrCm4
72 ****************************************************************************//**
73 *
74 * This is the interrupt service routine for the system pipe.
75 *
76 *******************************************************************************/
Cy_SysIpcPipeIsrCm4(void)77 void Cy_SysIpcPipeIsrCm4(void)
78 {
79 Cy_IPC_Pipe_ExecuteCallback(CY_IPC_EP_CYPIPE_CM4_ADDR);
80 }
81 #endif
82
83
84 /*******************************************************************************
85 * Function Name: Cy_Platform_Init
86 ****************************************************************************//**
87 *
88 * CM4 custom HW initialization
89 *
90 *******************************************************************************/
Cy_Platform_Init(void)91 void Cy_Platform_Init(void)
92 {
93 Cy_PDL_Init(CY_DEVICE_CFG);
94
95 #if defined(CY_IPC_DEFAULT_CFG_DISABLE)
96 /* Allocate and initialize semaphores for the system operations. */
97 static uint32_t ipcSemaArray[CY_IPC_SEMA_COUNT / CY_IPC_SEMA_PER_WORD];
98 (void) Cy_IPC_Sema_Init(CY_IPC_CHAN_SEMA, CY_IPC_SEMA_COUNT, ipcSemaArray);
99
100 /********************************************************************************
101 *
102 * Initializes the system pipes. The system pipes are used by BLE and Flash.
103 *
104 * If the default startup file is not used, or SystemInit() is not called in your
105 * project, call the following three functions prior to executing any flash or
106 * EmEEPROM write or erase operation:
107 * -# Cy_IPC_Sema_Init()
108 * -# Cy_IPC_Pipe_Config()
109 * -# Cy_IPC_Pipe_Init()
110 * -# Cy_Flash_Init()
111 *
112 *******************************************************************************/
113 /* Create an array of endpoint structures */
114 static cy_stc_ipc_pipe_ep_t systemIpcPipeEpArray[CY_IPC_MAX_ENDPOINTS];
115
116 Cy_IPC_Pipe_Config(systemIpcPipeEpArray);
117
118 static cy_ipc_pipe_callback_ptr_t systemIpcPipeSysCbArray[CY_SYS_CYPIPE_CLIENT_CNT];
119
120 static const cy_stc_ipc_pipe_config_t systemIpcPipeConfigCm4 =
121 {
122 /* .ep0ConfigData */
123 {
124 /* .ipcNotifierNumber */ CY_IPC_INTR_CYPIPE_EP0,
125 /* .ipcNotifierPriority */ CY_SYS_INTR_CYPIPE_PRIOR_EP0,
126 /* .ipcNotifierMuxNumber */ CY_SYS_INTR_CYPIPE_MUX_EP0,
127 /* .epAddress */ CY_IPC_EP_CYPIPE_CM0_ADDR,
128 /* .epConfig */ CY_SYS_CYPIPE_CONFIG_EP0
129 },
130 /* .ep1ConfigData */
131 {
132 /* .ipcNotifierNumber */ CY_IPC_INTR_CYPIPE_EP1,
133 /* .ipcNotifierPriority */ CY_SYS_INTR_CYPIPE_PRIOR_EP1,
134 /* .ipcNotifierMuxNumber */ 0u,
135 /* .epAddress */ CY_IPC_EP_CYPIPE_CM4_ADDR,
136 /* .epConfig */ CY_SYS_CYPIPE_CONFIG_EP1
137 },
138 /* .endpointClientsCount */ CY_SYS_CYPIPE_CLIENT_CNT,
139 /* .endpointsCallbacksArray */ systemIpcPipeSysCbArray,
140 /* .userPipeIsrHandler */ &Cy_SysIpcPipeIsrCm4
141 };
142
143 Cy_IPC_Pipe_Init(&systemIpcPipeConfigCm4);
144
145 #if defined(CY_DEVICE_PSOC6ABLE2)
146 Cy_Flash_Init();
147 #endif /* defined(CY_DEVICE_PSOC6ABLE2) */
148
149 #endif /* defined(CY_IPC_DEFAULT_CFG_DISABLE) */
150
151 #if defined(CY_DEVICE_SECURE)
152 /* Initialize Protected Register Access driver */
153 Cy_PRA_Init();
154 #endif /* defined(CY_DEVICE_SECURE) */
155 }
156
157
tfm_ns_platform_init(void)158 int32_t tfm_ns_platform_init (void)
159 {
160 Cy_Platform_Init();
161 return 0;
162 }
163
164 /* [] END OF FILE */
165