From a1bc65a1521d9cfbefb088e6f69dfedb0e16b7bb Mon Sep 17 00:00:00 2001 From: Charley Chu Date: Wed, 8 Jul 2020 18:03:36 -0700 Subject: [PATCH] psoc64: Update TF-M for MBedOS Signed-off-by: Charley Chu --- .../TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c | 13 ++++--------- .../TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c | 11 +++++++++-- .../TARGET_TFM/include/platform_multicore.h | 4 ++-- .../FEATURE_PSA/TARGET_TFM/include/tfm_ns_mailbox.h | 7 +++++++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c index af08ac1a39..3c642c0224 100644 --- a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c +++ b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c @@ -54,6 +54,7 @@ int32_t tfm_ns_mailbox_hal_notify_peer(void) static int32_t mailbox_sema_init(void) { +#if defined(CY_IPC_DEFAULT_CFG_DISABLE) /* semaphore data */ static uint32_t tfm_sema __attribute__((section("TFM_SHARED_DATA"))); @@ -62,6 +63,7 @@ static int32_t mailbox_sema_init(void) &tfm_sema) != CY_IPC_SEMA_SUCCESS) { return PLATFORM_MAILBOX_INIT_ERROR; } +#endif return PLATFORM_MAILBOX_SUCCESS; } @@ -118,11 +120,7 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue) const void *tfm_ns_mailbox_get_task_handle(void) { -#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL - return osThreadGetId(); -#else - return NULL; -#endif + return osThreadGetId();; } void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle) @@ -279,7 +277,7 @@ static bool mailbox_clear_intr(void) return true; } -void cpuss_interrupts_ipc_5_IRQHandler(void) +void cpuss_interrupts_ipc_8_IRQHandler(void) { uint32_t magic; mailbox_msg_handle_t handle; @@ -299,9 +297,6 @@ void cpuss_interrupts_ipc_5_IRQHandler(void) task_handle = (osThreadId_t)tfm_ns_mailbox_get_msg_owner(handle); if (task_handle) { - /* According to the description of CMSIS-RTOS v2 Thread Flags, - * osThreadFlagsSet() can be called inside Interrupt Service - * Routine. */ osThreadFlagsSet(task_handle, handle); } } diff --git a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c index b58738feb3..231e895b61 100644 --- a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c +++ b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c @@ -9,15 +9,22 @@ #include "tfm_mailbox.h" #include "tfm_multi_core_api.h" #include "cmsis_os2.h" +#include "mbed_rtos_storage.h" #define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT -static osSemaphoreId_t ns_lock_handle = NULL; +static void *ns_lock_handle = NULL; +static mbed_rtos_storage_semaphore_t tfm_ns_sema_obj; __attribute__((weak)) enum tfm_status_e tfm_ns_interface_init(void) { - osSemaphoreAttr_t sema_attrib = {0}; + osSemaphoreAttr_t sema_attrib = { + .name = "tfm_ns_lock", + .attr_bits = 0, + .cb_size = sizeof(tfm_ns_sema_obj), + .cb_mem = &tfm_ns_sema_obj + }; ns_lock_handle = osSemaphoreNew(MAX_SEMAPHORE_COUNT, MAX_SEMAPHORE_COUNT, diff --git a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/platform_multicore.h b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/platform_multicore.h index f90fb1e279..d0d72d4d29 100644 --- a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/platform_multicore.h +++ b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/platform_multicore.h @@ -19,10 +19,10 @@ #define IPC_PSA_CLIENT_CALL_IPC_INTR cpuss_interrupts_ipc_6_IRQn #define IPC_PSA_CLIENT_REPLY_CHAN (9) -#define IPC_PSA_CLIENT_REPLY_INTR_STRUCT (5) +#define IPC_PSA_CLIENT_REPLY_INTR_STRUCT (8) #define IPC_PSA_CLIENT_REPLY_INTR_MASK (1 << IPC_PSA_CLIENT_REPLY_CHAN) #define IPC_PSA_CLIENT_REPLY_NOTIFY_MASK (1 << IPC_PSA_CLIENT_REPLY_INTR_STRUCT) -#define IPC_PSA_CLIENT_REPLY_IPC_INTR cpuss_interrupts_ipc_5_IRQn +#define IPC_PSA_CLIENT_REPLY_IPC_INTR cpuss_interrupts_ipc_8_IRQn #define IPC_RX_RELEASE_MASK (0) diff --git a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/tfm_ns_mailbox.h b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/tfm_ns_mailbox.h index 2fcb1b6470..ba902aa977 100644 --- a/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/tfm_ns_mailbox.h +++ b/features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/tfm_ns_mailbox.h @@ -84,6 +84,7 @@ bool tfm_ns_mailbox_is_msg_replied(mailbox_msg_handle_t handle); */ int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue); +#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL /** * \brief Get the handle of the current non-secure task executing mailbox * functionalities @@ -96,6 +97,12 @@ int32_t tfm_ns_mailbox_init(struct ns_mailbox_queue_t *queue); * \return Return the handle of task. */ const void *tfm_ns_mailbox_get_task_handle(void); +#else +static inline const void *tfm_ns_mailbox_get_task_handle(void) +{ + return NULL; +} +#endif /** * \brief Fetch the handle to the first replied mailbox message in the NSPE