Skip to content

Commit d3d03c9

Browse files
author
Charley Chu
committed
psoc64: Update TF-M for MBedOS
- Replace TF-M OS wrapper API with CMSIS API - Add busy loop in mailbox_raw_spin_lock() - Use static allocated semaphore for NS lock Signed-off-by: Charley Chu <[email protected]>
1 parent ff90636 commit d3d03c9

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include "cy_ipc_sema.h"
1717

1818
#include "ns_ipc_config.h"
19-
#include "os_wrapper/thread.h"
2019
#include "tfm_ns_mailbox.h"
2120
#include "platform_multicore.h"
21+
#include "cmsis_os2.h"
2222

2323
static uint8_t saved_irq_state = 1;
2424

@@ -120,12 +120,12 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
120120

121121
const void *tfm_ns_mailbox_get_task_handle(void)
122122
{
123-
return os_wrapper_thread_get_handle();
123+
return osThreadGetId();;
124124
}
125125

126126
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
127127
{
128-
os_wrapper_thread_wait_flag((uint32_t)handle, OS_WRAPPER_WAIT_FOREVER);
128+
osThreadFlagsWait(handle, osFlagsWaitAll, osWaitForever);
129129
}
130130

131131
static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
@@ -179,6 +179,10 @@ static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
179179
* notification event from secure core. However, it is more
180180
* complex and requires more code and more modifications.
181181
*/
182+
volatile uint32_t count = 1000;
183+
while(count > 0) {
184+
count--;
185+
}
182186
Cy_IPC_Sema_Status(sema_num);
183187
}
184188
}
@@ -277,7 +281,7 @@ void cpuss_interrupts_ipc_8_IRQHandler(void)
277281
{
278282
uint32_t magic;
279283
mailbox_msg_handle_t handle;
280-
void *task_handle;
284+
osThreadId_t task_handle;
281285

282286
if (!mailbox_clear_intr())
283287
return;
@@ -291,9 +295,9 @@ void cpuss_interrupts_ipc_8_IRQHandler(void)
291295
break;
292296
}
293297

294-
task_handle = (void *)tfm_ns_mailbox_get_msg_owner(handle);
298+
task_handle = (osThreadId_t)tfm_ns_mailbox_get_msg_owner(handle);
295299
if (task_handle) {
296-
os_wrapper_thread_set_flag_isr(task_handle, (uint32_t)handle);
300+
osThreadFlagsSet(task_handle, handle);
297301
}
298302
}
299303
}

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55
*
66
*/
77

8-
#include "os_wrapper/semaphore.h"
9-
108
#include "tfm_api.h"
119
#include "tfm_mailbox.h"
1210
#include "tfm_multi_core_api.h"
11+
#include "cmsis_os2.h"
12+
#include "mbed_rtos_storage.h"
1313

1414
#define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT
1515

1616
static void *ns_lock_handle = NULL;
17+
static mbed_rtos_storage_semaphore_t tfm_ns_sema_obj;
1718

1819
__attribute__((weak))
1920
enum tfm_status_e tfm_ns_interface_init(void)
2021
{
21-
ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT,
22-
MAX_SEMAPHORE_COUNT,
23-
NULL);
22+
osSemaphoreAttr_t sema_attrib = {
23+
.name = "tfm_ns_lock",
24+
.attr_bits = 0,
25+
.cb_size = sizeof(tfm_ns_sema_obj),
26+
.cb_mem = &tfm_ns_sema_obj
27+
};
28+
29+
ns_lock_handle = osSemaphoreNew(MAX_SEMAPHORE_COUNT,
30+
MAX_SEMAPHORE_COUNT,
31+
&sema_attrib);
2432
if (!ns_lock_handle) {
2533
return TFM_ERROR_GENERIC;
2634
}
@@ -35,11 +43,10 @@ int32_t tfm_ns_wait_for_s_cpu_ready(void)
3543

3644
uint32_t tfm_ns_multi_core_lock_acquire(void)
3745
{
38-
return os_wrapper_semaphore_acquire(ns_lock_handle,
39-
OS_WRAPPER_WAIT_FOREVER);
46+
return osSemaphoreAcquire(ns_lock_handle, osWaitForever);
4047
}
4148

4249
uint32_t tfm_ns_multi_core_lock_release(void)
4350
{
44-
return os_wrapper_semaphore_release(ns_lock_handle);
51+
return osSemaphoreRelease(ns_lock_handle);
4552
}

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_psa_ns_api.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <stdint.h>
99
#include <stdbool.h>
1010

11-
#include "os_wrapper/mutex.h"
12-
1311
#include "psa/client.h"
1412
#include "psa/error.h"
1513
#include "tfm_api.h"
@@ -64,7 +62,7 @@ uint32_t psa_framework_version(void)
6462
uint32_t version;
6563
int32_t ret;
6664

67-
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
65+
if (tfm_ns_multi_core_lock_acquire() != 0) {
6866
return PSA_VERSION_NONE;
6967
}
7068

@@ -82,7 +80,7 @@ uint32_t psa_framework_version(void)
8280
version = PSA_VERSION_NONE;
8381
}
8482

85-
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
83+
if (tfm_ns_multi_core_lock_release() != 0) {
8684
return PSA_VERSION_NONE;
8785
}
8886

@@ -98,7 +96,7 @@ uint32_t psa_version(uint32_t sid)
9896

9997
params.psa_version_params.sid = sid;
10098

101-
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
99+
if (tfm_ns_multi_core_lock_acquire() != 0) {
102100
return PSA_VERSION_NONE;
103101
}
104102

@@ -116,7 +114,7 @@ uint32_t psa_version(uint32_t sid)
116114
version = PSA_VERSION_NONE;
117115
}
118116

119-
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
117+
if (tfm_ns_multi_core_lock_release() != 0) {
120118
return PSA_VERSION_NONE;
121119
}
122120

@@ -133,7 +131,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t version)
133131
params.psa_connect_params.sid = sid;
134132
params.psa_connect_params.version = version;
135133

136-
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
134+
if (tfm_ns_multi_core_lock_acquire() != 0) {
137135
return PSA_NULL_HANDLE;
138136
}
139137

@@ -151,7 +149,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t version)
151149
psa_handle = PSA_NULL_HANDLE;
152150
}
153151

154-
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
152+
if (tfm_ns_multi_core_lock_release() != 0) {
155153
return PSA_NULL_HANDLE;
156154
}
157155

@@ -174,7 +172,7 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
174172
params.psa_call_params.out_vec = out_vec;
175173
params.psa_call_params.out_len = out_len;
176174

177-
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
175+
if (tfm_ns_multi_core_lock_acquire() != 0) {
178176
return PSA_ERROR_GENERIC_ERROR;
179177
}
180178

@@ -192,7 +190,7 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
192190
status = PSA_INTER_CORE_COMM_ERR;
193191
}
194192

195-
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
193+
if (tfm_ns_multi_core_lock_release() != 0) {
196194
return PSA_ERROR_GENERIC_ERROR;
197195
}
198196

@@ -207,7 +205,7 @@ void psa_close(psa_handle_t handle)
207205

208206
params.psa_close_params.handle = handle;
209207

210-
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
208+
if (tfm_ns_multi_core_lock_acquire() != 0) {
211209
return;
212210
}
213211

0 commit comments

Comments
 (0)