App: Create a dedicated mailbox thread

Create a dedicated mailbox thread to align with TF-M dual-cpu NS
mailbox new working model.
Update other NS mailbox APIs to align with TF-M changes.

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: I1eac4b84085b9e5a329cf82f7bf4e017fcf6062a
diff --git a/app/main_ns.c b/app/main_ns.c
index e153572..850b6a6 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -71,6 +71,19 @@
 };
 #endif
 
+#ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD
+static osThreadFunc_t mailbox_thread_func = tfm_ns_mailbox_thread_runner;
+/* 1KB stack */
+#define MAILBOX_THREAD_STACK_SIZE           (1u * 1024u)
+static uint64_t mailbox_thread_stack[MAILBOX_THREAD_STACK_SIZE /
+                                     sizeof(uint64_t)];
+static const osThreadAttr_t mailbox_thread_attr = {
+    .name = "mailbox_thread",
+    .stack_mem = mailbox_thread_stack,
+    .stack_size = sizeof(mailbox_thread_stack),
+};
+#endif
+
 /**
  * \brief Static globals to hold RTOS related quantities,
  *        main thread
@@ -163,6 +176,10 @@
     /* Initialize the TFM NS interface */
     tfm_ns_interface_init();
 
+#ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD
+    (void) osThreadNew(mailbox_thread_func, NULL, &mailbox_thread_attr);
+#endif
+
 #if defined(TEST_FRAMEWORK_NS) || defined(TEST_FRAMEWORK_S)
     thread_func = test_app;
 #elif defined(PSA_API_TEST_NS)