Skip to content

Commit 3ff5a3b

Browse files
authored
Merge pull request ARMmbed#13418 from CharleyChu/topic/master_cytfm
Update PSoC64 TFM release package.
2 parents 9df8d33 + 4749e17 commit 3ff5a3b

File tree

6 files changed

+12564
-12687
lines changed

6 files changed

+12564
-12687
lines changed

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_V1_0/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c

Lines changed: 17 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "cy_ipc_drv.h"
1515
#include "cy_sysint.h"
16-
#include "cy_ipc_sema.h"
1716

1817
#include "ns_ipc_config.h"
1918
#include "tfm_ns_mailbox.h"
@@ -52,21 +51,6 @@ int32_t tfm_ns_mailbox_hal_notify_peer(void)
5251
}
5352
}
5453

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-
7054
int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
7155
{
7256
uint32_t stage;
@@ -75,10 +59,6 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
7559
return MAILBOX_INVAL_PARAMS;
7660
}
7761

78-
/* Init semaphores used for critical sections */
79-
if (mailbox_sema_init() != PLATFORM_MAILBOX_SUCCESS)
80-
return MAILBOX_INIT_ERROR;
81-
8262
/*
8363
* FIXME
8464
* 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)
120100

121101
const void *tfm_ns_mailbox_get_task_handle(void)
122102
{
123-
return osThreadGetId();;
103+
return osThreadGetId();
124104
}
125105

126106
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
127107
{
128108
osThreadFlagsWait(handle, osFlagsWaitAll, osWaitForever);
129109
}
130110

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-
240111
void tfm_ns_mailbox_hal_enter_critical(void)
241112
{
242113
saved_irq_state = Cy_SysLib_EnterCriticalSection();
243114

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+
}
245120
}
246121

247122
void tfm_ns_mailbox_hal_exit_critical(void)
248123
{
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);
251127
Cy_SysLib_ExitCriticalSection(saved_irq_state);
252128
}
253129

254130
void tfm_ns_mailbox_hal_enter_critical_isr(void)
255131
{
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+
}
257137
}
258138

259139
void tfm_ns_mailbox_hal_exit_critical_isr(void)
260140
{
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);
262144
}
263145

264146
static bool mailbox_clear_intr(void)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eecaad9e4014
1+
9fd2fd6250d5

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_V1_0/include/platform_multicore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define IPC_PSA_CLIENT_REPLY_NOTIFY_MASK (1 << IPC_PSA_CLIENT_REPLY_INTR_STRUCT)
2525
#define IPC_PSA_CLIENT_REPLY_IPC_INTR cpuss_interrupts_ipc_8_IRQn
2626

27+
#define IPC_PSA_MAILBOX_LOCK_CHAN (10)
28+
2729
#define IPC_RX_RELEASE_MASK (0)
2830

2931
#define CY_IPC_NOTIFY_SHIFT (16)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e90e02327eb3
1+
9fd2fd6250d5

0 commit comments

Comments
 (0)