Skip to content

Commit c525aec

Browse files
Charley ChuRaymond Ngun
authored andcommitted
Add TFM V1.0
Signed-off-by: Charley Chu <[email protected]>
1 parent badfa18 commit c525aec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+13206
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2019 Arm Limited. All rights reserved.
3+
* Copyright (c) 2019 Cypress Semiconductor Corporation. All rights reserved.
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*/
7+
8+
#include "cmsis_compiler.h"
9+
10+
#include "platform_multicore.h"
11+
#include "tfm_multi_core_api.h"
12+
#include "tfm_ns_mailbox.h"
13+
14+
#include "cy_ipc_drv.h"
15+
#include "cy_sysint.h"
16+
#if CY_SYSTEM_CPU_CM0P
17+
#include "spe_ipc_config.h"
18+
#else
19+
#include "ns_ipc_config.h"
20+
#endif
21+
22+
int platform_mailbox_fetch_msg_ptr(void **msg_ptr)
23+
{
24+
cy_en_ipcdrv_status_t status;
25+
26+
if (!msg_ptr) {
27+
return PLATFORM_MAILBOX_INVAL_PARAMS;
28+
}
29+
30+
status = Cy_IPC_Drv_ReadMsgPtr(Cy_IPC_Drv_GetIpcBaseAddress(IPC_RX_CHAN),
31+
msg_ptr);
32+
if (status != CY_IPC_DRV_SUCCESS) {
33+
return PLATFORM_MAILBOX_RX_ERROR;
34+
}
35+
36+
Cy_IPC_Drv_ReleaseNotify(Cy_IPC_Drv_GetIpcBaseAddress(IPC_RX_CHAN),
37+
IPC_RX_RELEASE_MASK);
38+
return PLATFORM_MAILBOX_SUCCESS;
39+
}
40+
41+
int platform_mailbox_fetch_msg_data(uint32_t *data_ptr)
42+
{
43+
cy_en_ipcdrv_status_t status;
44+
45+
if (!data_ptr) {
46+
return PLATFORM_MAILBOX_INVAL_PARAMS;
47+
}
48+
49+
status = Cy_IPC_Drv_ReadMsgWord(Cy_IPC_Drv_GetIpcBaseAddress(IPC_RX_CHAN),
50+
data_ptr);
51+
if (status != CY_IPC_DRV_SUCCESS) {
52+
return PLATFORM_MAILBOX_RX_ERROR;
53+
}
54+
55+
Cy_IPC_Drv_ReleaseNotify(Cy_IPC_Drv_GetIpcBaseAddress(IPC_RX_CHAN),
56+
IPC_RX_RELEASE_MASK);
57+
return PLATFORM_MAILBOX_SUCCESS;
58+
}
59+
60+
int platform_mailbox_send_msg_ptr(const void *msg_ptr)
61+
{
62+
cy_en_ipcdrv_status_t status;
63+
64+
if (!msg_ptr)
65+
return PLATFORM_MAILBOX_INVAL_PARAMS;
66+
67+
status = Cy_IPC_Drv_SendMsgPtr(Cy_IPC_Drv_GetIpcBaseAddress(IPC_TX_CHAN),
68+
IPC_TX_NOTIFY_MASK, msg_ptr);
69+
if (status != CY_IPC_DRV_SUCCESS) {
70+
return PLATFORM_MAILBOX_TX_ERROR;
71+
}
72+
73+
return PLATFORM_MAILBOX_SUCCESS;
74+
}
75+
76+
int platform_mailbox_send_msg_data(uint32_t data)
77+
{
78+
cy_en_ipcdrv_status_t status;
79+
80+
status = Cy_IPC_Drv_SendMsgWord(Cy_IPC_Drv_GetIpcBaseAddress(IPC_TX_CHAN),
81+
IPC_TX_NOTIFY_MASK, data);
82+
if (status != CY_IPC_DRV_SUCCESS) {
83+
return PLATFORM_MAILBOX_TX_ERROR;
84+
}
85+
86+
return PLATFORM_MAILBOX_SUCCESS;
87+
}
88+
89+
void platform_mailbox_wait_for_notify(void)
90+
{
91+
uint32_t status;
92+
93+
while (1) {
94+
status = Cy_IPC_Drv_GetInterruptStatusMasked(
95+
Cy_IPC_Drv_GetIntrBaseAddr(IPC_RX_INTR_STRUCT));
96+
status >>= CY_IPC_NOTIFY_SHIFT;
97+
if (status & IPC_RX_INT_MASK) {
98+
break;
99+
}
100+
}
101+
102+
Cy_IPC_Drv_ClearInterrupt(Cy_IPC_Drv_GetIntrBaseAddr(IPC_RX_INTR_STRUCT),
103+
0, IPC_RX_INT_MASK);
104+
}
105+
106+
int platform_ns_ipc_init(void)
107+
{
108+
Cy_IPC_Drv_SetInterruptMask(Cy_IPC_Drv_GetIntrBaseAddr(IPC_RX_INTR_STRUCT),
109+
0, IPC_RX_INT_MASK);
110+
return PLATFORM_MAILBOX_SUCCESS;
111+
}
112+
113+
int32_t tfm_platform_ns_wait_for_s_cpu_ready(void)
114+
{
115+
uint32_t data = 0;
116+
117+
if (platform_ns_ipc_init() != PLATFORM_MAILBOX_SUCCESS) {
118+
return PLATFORM_MAILBOX_INVAL_PARAMS;
119+
}
120+
while(data != IPC_SYNC_MAGIC)
121+
{
122+
platform_mailbox_wait_for_notify();
123+
platform_mailbox_fetch_msg_data(&data);
124+
}
125+
126+
if (platform_mailbox_send_msg_data(~IPC_SYNC_MAGIC) !=
127+
PLATFORM_MAILBOX_SUCCESS) {
128+
return PLATFORM_MAILBOX_RX_ERROR;
129+
}
130+
return PLATFORM_MAILBOX_SUCCESS;
131+
}

0 commit comments

Comments
 (0)