13
13
14
14
#include "cy_ipc_drv.h"
15
15
#include "cy_sysint.h"
16
- #include "cy_ipc_sema.h"
17
16
18
17
#include "ns_ipc_config.h"
19
18
#include "tfm_ns_mailbox.h"
@@ -52,21 +51,6 @@ int32_t tfm_ns_mailbox_hal_notify_peer(void)
52
51
}
53
52
}
54
53
55
- static int32_t mailbox_sema_init (void )
56
- {
57
- #if defined(CY_IPC_DEFAULT_CFG_DISABLE )
58
- /* semaphore data */
59
- static uint32_t tfm_sema __attribute__((section ("TFM_SHARED_DATA" )));
60
-
61
- if (Cy_IPC_Sema_Init (PLATFORM_MAILBOX_IPC_CHAN_SEMA ,
62
- sizeof (tfm_sema ) * CHAR_BIT ,
63
- & tfm_sema ) != CY_IPC_SEMA_SUCCESS ) {
64
- return PLATFORM_MAILBOX_INIT_ERROR ;
65
- }
66
- #endif
67
- return PLATFORM_MAILBOX_SUCCESS ;
68
- }
69
-
70
54
int32_t tfm_ns_mailbox_hal_init (struct ns_mailbox_queue_t * queue )
71
55
{
72
56
uint32_t stage ;
@@ -75,10 +59,6 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
75
59
return MAILBOX_INVAL_PARAMS ;
76
60
}
77
61
78
- /* Init semaphores used for critical sections */
79
- if (mailbox_sema_init () != PLATFORM_MAILBOX_SUCCESS )
80
- return MAILBOX_INIT_ERROR ;
81
-
82
62
/*
83
63
* FIXME
84
64
* Further verification of mailbox queue address may be required according
@@ -120,145 +100,47 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
120
100
121
101
const void * tfm_ns_mailbox_get_task_handle (void )
122
102
{
123
- return osThreadGetId ();;
103
+ return osThreadGetId ();
124
104
}
125
105
126
106
void tfm_ns_mailbox_hal_wait_reply (mailbox_msg_handle_t handle )
127
107
{
128
108
osThreadFlagsWait (handle , osFlagsWaitAll , osWaitForever );
129
109
}
130
110
131
- static cy_en_ipcsema_status_t mailbox_raw_spin_lock (uint32_t ipc_channel ,
132
- uint32_t sema_num )
133
- {
134
- uint32_t semaIndex ;
135
- uint32_t semaMask ;
136
- cy_stc_ipc_sema_t * semaStruct ;
137
- cy_en_ipcdrv_status_t acqStatus ;
138
- cy_en_ipcsema_status_t ret = CY_IPC_SEMA_BAD_PARAM ;
139
- bool is_lock = false;
140
- IPC_STRUCT_Type * semaIpcStruct ;
141
-
142
- /* Get IPC register structure */
143
- semaIpcStruct = Cy_IPC_Drv_GetIpcBaseAddress (ipc_channel );
144
- /* Get pointer to structure */
145
- semaStruct = (cy_stc_ipc_sema_t * )Cy_IPC_Drv_ReadDataValue (semaIpcStruct );
146
-
147
- if (sema_num < semaStruct -> maxSema ) {
148
- semaIndex = sema_num / CY_IPC_SEMA_PER_WORD ;
149
- semaMask = (uint32_t )(1ul << (sema_num - \
150
- (semaIndex * CY_IPC_SEMA_PER_WORD )));
151
-
152
- while (!is_lock ) {
153
- /* Check to make sure the IPC channel is released
154
- If so, check if specific channel can be locked. */
155
- do {
156
- acqStatus = Cy_IPC_Drv_LockAcquire (semaIpcStruct );
157
- } while (acqStatus != CY_IPC_DRV_SUCCESS );
158
-
159
- if ((semaStruct -> arrayPtr [semaIndex ] & semaMask ) == 0ul ) {
160
- semaStruct -> arrayPtr [semaIndex ] |= semaMask ;
161
- is_lock = true;
162
- }
163
-
164
- /* Release, but do not trigger a release event */
165
- (void )Cy_IPC_Drv_LockRelease (semaIpcStruct ,
166
- CY_IPC_NO_NOTIFICATION );
167
-
168
- if (!is_lock ) {
169
- /*
170
- * The secure core is occupying this lock. Insert a small delay
171
- * to give the secure core a chance to acquire the IPC channel
172
- * and release the lock.
173
- * Otherwise, the secure core may not be able to release the
174
- * lock if non-secure core has higher CPU frequency. It will
175
- * generate a deadlock.
176
- * This delay won't harm performance too much since non-secure
177
- * core has to busy wait here anyway.
178
- * Alternatively, non-secure core can wait for release
179
- * notification event from secure core. However, it is more
180
- * complex and requires more code and more modifications.
181
- */
182
- volatile uint32_t count = 1000 ;
183
- while (count > 0 ) {
184
- count -- ;
185
- }
186
- Cy_IPC_Sema_Status (sema_num );
187
- }
188
- }
189
-
190
- ret = CY_IPC_SEMA_SUCCESS ;
191
- }
192
-
193
- return ret ;
194
- }
195
-
196
- static cy_en_ipcsema_status_t mailbox_raw_spin_unlock (uint32_t ipc_channel ,
197
- uint32_t sema_num )
198
- {
199
- uint32_t semaIndex ;
200
- uint32_t semaMask ;
201
- cy_stc_ipc_sema_t * semaStruct ;
202
- cy_en_ipcdrv_status_t acqStatus ;
203
- cy_en_ipcsema_status_t ret = CY_IPC_SEMA_BAD_PARAM ;
204
- bool is_unlock = false;
205
- IPC_STRUCT_Type * semaIpcStruct ;
206
-
207
- /* Get IPC register structure */
208
- semaIpcStruct = Cy_IPC_Drv_GetIpcBaseAddress (ipc_channel );
209
- /* Get pointer to structure */
210
- semaStruct = (cy_stc_ipc_sema_t * )Cy_IPC_Drv_ReadDataValue (semaIpcStruct );
211
-
212
- if (sema_num < semaStruct -> maxSema ) {
213
- semaIndex = sema_num / CY_IPC_SEMA_PER_WORD ;
214
- semaMask = (uint32_t )(1ul << (sema_num - \
215
- (semaIndex * CY_IPC_SEMA_PER_WORD )));
216
-
217
- while (!is_unlock ) {
218
- /* Check to make sure the IPC channel is released
219
- If so, check if specific channel can be locked. */
220
- do {
221
- acqStatus = Cy_IPC_Drv_LockAcquire (semaIpcStruct );
222
- } while (acqStatus != CY_IPC_DRV_SUCCESS );
223
-
224
- if ((semaStruct -> arrayPtr [semaIndex ] & semaMask ) != 0ul ) {
225
- semaStruct -> arrayPtr [semaIndex ] &= ~semaMask ;
226
- is_unlock = true;
227
- }
228
-
229
- /* Release, but do not trigger a release event */
230
- (void )Cy_IPC_Drv_LockRelease (semaIpcStruct ,
231
- CY_IPC_NO_NOTIFICATION );
232
- }
233
-
234
- ret = CY_IPC_SEMA_SUCCESS ;
235
- }
236
-
237
- return ret ;
238
- }
239
-
240
111
void tfm_ns_mailbox_hal_enter_critical (void )
241
112
{
242
113
saved_irq_state = Cy_SysLib_EnterCriticalSection ();
243
114
244
- mailbox_raw_spin_lock (CY_IPC_CHAN_SEMA , MAILBOX_SEMAPHORE_NUM );
115
+ IPC_STRUCT_Type * ipc_struct =
116
+ Cy_IPC_Drv_GetIpcBaseAddress (IPC_PSA_MAILBOX_LOCK_CHAN );
117
+ while (CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_LockAcquire (ipc_struct ))
118
+ {
119
+ }
245
120
}
246
121
247
122
void tfm_ns_mailbox_hal_exit_critical (void )
248
123
{
249
- mailbox_raw_spin_unlock (CY_IPC_CHAN_SEMA , MAILBOX_SEMAPHORE_NUM );
250
-
124
+ IPC_STRUCT_Type * ipc_struct =
125
+ Cy_IPC_Drv_GetIpcBaseAddress (IPC_PSA_MAILBOX_LOCK_CHAN );
126
+ Cy_IPC_Drv_LockRelease (ipc_struct , CY_IPC_NO_NOTIFICATION );
251
127
Cy_SysLib_ExitCriticalSection (saved_irq_state );
252
128
}
253
129
254
130
void tfm_ns_mailbox_hal_enter_critical_isr (void )
255
131
{
256
- mailbox_raw_spin_lock (CY_IPC_CHAN_SEMA , MAILBOX_SEMAPHORE_NUM );
132
+ IPC_STRUCT_Type * ipc_struct =
133
+ Cy_IPC_Drv_GetIpcBaseAddress (IPC_PSA_MAILBOX_LOCK_CHAN );
134
+ while (CY_IPC_DRV_SUCCESS != Cy_IPC_Drv_LockAcquire (ipc_struct ))
135
+ {
136
+ }
257
137
}
258
138
259
139
void tfm_ns_mailbox_hal_exit_critical_isr (void )
260
140
{
261
- mailbox_raw_spin_unlock (CY_IPC_CHAN_SEMA , MAILBOX_SEMAPHORE_NUM );
141
+ IPC_STRUCT_Type * ipc_struct =
142
+ Cy_IPC_Drv_GetIpcBaseAddress (IPC_PSA_MAILBOX_LOCK_CHAN );
143
+ Cy_IPC_Drv_LockRelease (ipc_struct , CY_IPC_NO_NOTIFICATION );
262
144
}
263
145
264
146
static bool mailbox_clear_intr (void )
0 commit comments