Profiler: Add profiling support in NSPE

Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: Iac59d76d0ea61d90ebf0ddc61e53e16d0606e1a6
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index d4f4b63..18123fa 100755
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -274,11 +274,18 @@
 )
 
 target_compile_definitions(tfm_test_app
-    PRIVATE
+    PUBLIC
         $<$<BOOL:${TFM_NS_REG_TEST}>:TFM_NS_REG_TEST>
         $<$<BOOL:${TEST_PSA_API}>:PSA_API_TEST_NS>
 )
 
+############################# Profiling integration ############################
+
+if(CONFIG_TFM_ENALBE_PROFILING)
+    add_subdirectory(${TFM_PROFILING_PATH}/profiling_cases/tfm_ns_profiling
+                     ${CMAKE_CURRENT_BINARY_DIR}/profiling_cases)
+endif()
+
 ############################# TFM NS app #######################################
 
 add_executable(tfm_ns)
@@ -294,6 +301,7 @@
         tfm_test_app
         tfm_log
         platform_ns
+        $<$<BOOL:${CONFIG_TFM_ENALBE_PROFILING}>:tfm_ns_profiling>
 )
 
 set_target_properties(tfm_ns PROPERTIES
diff --git a/app/main_ns.c b/app/main_ns.c
index 75f85cf..8793148 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -24,6 +24,9 @@
 #if (CONFIG_TFM_FLOAT_ABI >= 1)
 #include "cmsis.h"
 #endif
+#ifdef CONFIG_TFM_ENALBE_PROFILING
+#include "tfm_ns_profiling.h"
+#endif
 
 /**
  * \brief Modified table template for user defined SVC functions
@@ -45,6 +48,20 @@
 #endif
 #endif
 
+#ifdef CONFIG_TFM_ENALBE_PROFILING
+
+#if TFM_NS_REG_TEST || PSA_API_TEST_NS
+#error "TF-M NS profiling shall not run together with NS regression tests"
+#endif
+/**
+ * \brief List of Profiling thread attributes
+ */
+const osThreadAttr_t thread_attr = {
+    .name = "profiling_thread",
+    .stack_size = 4096U,
+};
+osThreadFunc_t thread_func = tfm_ns_profiling;
+#else
 /**
  * \brief List of RTOS thread attributes
  */
@@ -58,6 +75,7 @@
  *        main thread
  */
 static osThreadFunc_t thread_func = test_app;
+#endif
 
 #ifdef TFM_MULTI_CORE_NS_OS_MAILBOX_THREAD
 static osThreadFunc_t mailbox_thread_func = tfm_ns_mailbox_thread_runner;