Test: Refactor the os_wrapper layer and NS test
This patch refactors the os_wrapper layer and NS test.
- Use consistent naming of functions in the OS wrapper.
- Code style fixes.
- Rename the implementation to highlight that they are
CMSIS-RTOS2 specific examples.
- Reduce stack size used by SST test threads in regression.
- Reorganise the SST test to avoid the usage of thread
join operation.
- Remove un-needed functions.
- Disallow LOG_MSG(...) from Handler mode.
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: Ifbdb3429f006cdf1a97090ed0c5e0db195777969
diff --git a/interface/src/tfm_ns_lock_cmsis_rtos.c b/interface/src/tfm_ns_lock_cmsis_rtos.c
new file mode 100644
index 0000000..a81f6e1
--- /dev/null
+++ b/interface/src/tfm_ns_lock_cmsis_rtos.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "cmsis_os2.h"
+
+#include "tfm_api.h"
+#include "tfm_ns_lock.h"
+
+/**
+ * \brief struct ns_lock_state type
+ */
+struct ns_lock_state {
+ bool init;
+ osMutexId_t id;
+};
+
+/**
+ * \brief ns_lock status
+ */
+static struct ns_lock_state ns_lock = {.init = false, .id = NULL};
+
+/**
+ * \brief Mutex properties, NS lock
+ */
+static const osMutexAttr_t ns_lock_attrib = {
+ .name = "ns_lock",
+ .attr_bits = osMutexPrioInherit,
+ .cb_mem = NULL,
+ .cb_size = 0U
+};
+
+/**
+ * \brief NS world, NS lock based dispatcher
+ */
+uint32_t tfm_ns_lock_dispatch(veneer_fn fn,
+ uint32_t arg0, uint32_t arg1,
+ uint32_t arg2, uint32_t arg3)
+{
+ uint32_t result;
+
+ /* Check the NS lock has been initialized */
+ if (ns_lock.init == false) {
+ return TFM_ERROR_GENERIC;
+ }
+
+ /* TFM request protected by NS lock */
+ if (osMutexAcquire(ns_lock.id, osWaitForever) != osOK) {
+ return TFM_ERROR_GENERIC;
+ }
+
+ result = fn(arg0, arg1, arg2, arg3);
+
+ if (osMutexRelease(ns_lock.id) != osOK) {
+ return TFM_ERROR_GENERIC;
+ }
+
+ return result;
+}
+
+/**
+ * \brief NS world, Init NS lock
+ */
+enum tfm_status_e tfm_ns_lock_init(void)
+{
+ if (ns_lock.init == false) {
+ ns_lock.id = osMutexNew(&ns_lock_attrib);
+ ns_lock.init = true;
+ return TFM_SUCCESS;
+ } else {
+ return TFM_ERROR_GENERIC;
+ }
+}