Skip to content

Commit 04eca5b

Browse files
author
Charley Chu
committed
Changes required in TF-M release
- Replace TF-M OS wrapper API with CMSIS API - Add busy loop in mailbox_raw_spin_lock() - Rename the IPC8 IRQ handler - Use static allocated semaphore for NS lock Signed-off-by: Charley Chu <[email protected]>
1 parent 8538257 commit 04eca5b

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

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

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

1818
#include "ns_ipc_config.h"
19-
#include "os_wrapper/thread.h"
20-
#include "os_wrapper/semaphore.h"
2119
#include "tfm_ns_mailbox.h"
2220
#include "platform_multicore.h"
21+
#include "cmsis_os2.h"
2322

2423
static uint8_t saved_irq_state = 1;
2524

@@ -121,22 +120,22 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
121120

122121
void * tfm_ns_mailbox_hal_create_semaphore(void)
123122
{
124-
return os_wrapper_semaphore_create(1, 0, NULL);
123+
return osSemaphoreNew(1, 0, NULL);
125124
}
126125

127126
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
128127
{
129128
void *sem = tfm_ns_mailbox_get_msg_semaphore(handle);
130129
if (sem != NULL) {
131-
os_wrapper_semaphore_acquire(sem, OS_WRAPPER_WAIT_FOREVER);
130+
osSemaphoreAcquire(sem, osWaitForever);
132131
}
133132
}
134133

135134
void tfm_ns_mailbox_hal_delete_semaphore(mailbox_msg_handle_t handle)
136135
{
137136
void *sem = tfm_ns_mailbox_get_msg_semaphore(handle);
138137
if (sem != NULL) {
139-
os_wrapper_semaphore_delete(sem);
138+
osSemaphoreDelete(sem);
140139
}
141140
}
142141

@@ -191,6 +190,10 @@ static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
191190
* notification event from secure core. However, it is more
192191
* complex and requires more code and more modifications.
193192
*/
193+
volatile uint32_t count = 1000;
194+
while(count > 0) {
195+
count--;
196+
}
194197
Cy_IPC_Sema_Status(sema_num);
195198
}
196199
}
@@ -285,7 +288,7 @@ static bool mailbox_clear_intr(void)
285288
return true;
286289
}
287290

288-
void tfm_ns_mailbox_ipc_IRQHandler(void)
291+
void cpuss_interrupts_ipc_8_IRQHandler(void)
289292
{
290293
uint32_t magic;
291294
mailbox_msg_handle_t handle;
@@ -306,9 +309,8 @@ void tfm_ns_mailbox_ipc_IRQHandler(void)
306309

307310
sem = (void *)tfm_ns_mailbox_get_msg_semaphore(handle);
308311
if (sem) {
309-
yield |= os_wrapper_semaphore_release_isr(sem);
312+
yield |= osSemaphoreRelease(sem);
310313
}
311314
}
312-
os_wrapper_isr_yield(yield);
313315
}
314316
}

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)