Test: Add integration of the eRPC system

 - PSA Client API IDL file
 - Client and server init and API wrappers
 - Example client application

Signed-off-by: Kevin Peng <kevin.peng@arm.com>
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
Signed-off-by: Summer Qin <summer.qin@arm.com>
Change-Id: If6180fd3e596c9daabd31262fb10ae0a1583bc9b
diff --git a/erpc/client/CMakeLists.txt b/erpc/client/CMakeLists.txt
new file mode 100644
index 0000000..61a561d
--- /dev/null
+++ b/erpc/client/CMakeLists.txt
@@ -0,0 +1,68 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_minimum_required(VERSION 3.15)
+
+if (NOT DEFINED TFM_INSTALL_PATH)
+    if (DEFINED ENV{TFM_INSTALL_PATH})
+        set(TFM_INSTALL_PATH $ENV{TFM_INSTALL_PATH})
+    else()
+        message(FATAL_ERROR "TFM_INSTALL_PATH not found. Please set TFM_INSTALL_PATH environment variable or pass -DTFM_INSTALL_PATH flag.")
+    endif()
+endif()
+
+if (NOT DEFINED ERPC_REPO_PATH)
+    if (DEFINED ENV{ERPC_REPO_PATH})
+        set(ERPC_REPO_PATH $ENV{ERPC_REPO_PATH})
+    else()
+        message(FATAL_ERROR "ERPC_REPO_PATH not found. Please set ERPC_REPO_PATH environment variable or pass -DERPC_REPO_PATH flag.")
+    endif()
+endif()
+
+# Set eRPC config file. Need to provide config file with an absolute path.
+if (ERPC_CONFIG_FILE)
+    if (NOT EXISTS ${ERPC_CONFIG_FILE})
+        message(FATAL_ERROR "ERPC_CONFIG_FILE does not exist. Please provide it with an absolute path.")
+    endif()
+    # Get the path of the customized eRPC config file
+    get_filename_component(ERPC_CONFIG_FILE_PATH ${ERPC_CONFIG_FILE} DIRECTORY)
+else()
+    # Use default one
+    set(ERPC_CONFIG_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config")
+endif()
+
+add_library(erpc_client STATIC)
+
+target_sources(erpc_client
+    PRIVATE
+        erpc_client_wrapper.c
+        erpc_client_start.c
+        # eRPC files
+        ${ERPC_REPO_PATH}/erpc_c/infra/erpc_basic_codec.cpp
+        ${ERPC_REPO_PATH}/erpc_c/infra/erpc_client_manager.cpp
+        ${ERPC_REPO_PATH}/erpc_c/infra/erpc_crc16.cpp
+        ${ERPC_REPO_PATH}/erpc_c/infra/erpc_framed_transport.cpp
+        ${ERPC_REPO_PATH}/erpc_c/infra/erpc_message_buffer.cpp
+        ${ERPC_REPO_PATH}/erpc_c/port/erpc_serial.cpp
+        ${ERPC_REPO_PATH}/erpc_c/setup/erpc_client_setup.cpp
+        ${ERPC_REPO_PATH}/erpc_c/setup/erpc_setup_mbf_dynamic.cpp
+        # Generated files
+        ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_client_api_client.cpp
+        $<$<BOOL:${CONFIG_TFM_CONNECTION_BASED_SERVICE_API}>:${CMAKE_CURRENT_SOURCE_DIR}/../generated_files/tfm_erpc_psa_connection_api_client.cpp>
+)
+
+target_include_directories(erpc_client
+    PUBLIC
+        ${ERPC_REPO_PATH}/erpc_c/port
+        ${ERPC_REPO_PATH}/erpc_c/infra
+        ${ERPC_REPO_PATH}/erpc_c/transports
+        ${ERPC_REPO_PATH}/erpc_c/setup
+        ${CMAKE_CURRENT_SOURCE_DIR}/
+        ${CMAKE_CURRENT_SOURCE_DIR}/../generated_files
+        ${TFM_INSTALL_PATH}/interface/include
+        ${ERPC_CONFIG_FILE_PATH}/
+)
diff --git a/erpc/client/config/erpc_config.h b/erpc/client/config/erpc_config.h
new file mode 100644
index 0000000..11aada4
--- /dev/null
+++ b/erpc/client/config/erpc_config.h
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2016, Freescale Semiconductor, Inc.
+ * Copyright 2016-2020 NXP
+ * Copyright 2020-2021 ACRIOS Systems s.r.o.
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ * All rights reserved.
+ *
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _ERPC_CONFIG_H_
+#define _ERPC_CONFIG_H_
+
+/*!
+ * @addtogroup config
+ * @{
+ * @file
+ */
+
+////////////////////////////////////////////////////////////////////////////////
+// Declarations
+////////////////////////////////////////////////////////////////////////////////
+
+//! @name Threading model options
+//@{
+#define ERPC_ALLOCATION_POLICY_DYNAMIC (0U) //!< Dynamic allocation policy
+#define ERPC_ALLOCATION_POLICY_STATIC (1U)  //!< Static allocation policy
+
+#define ERPC_THREADS_NONE (0U)     //!< No threads.
+#define ERPC_THREADS_PTHREADS (1U) //!< POSIX pthreads.
+#define ERPC_THREADS_FREERTOS (2U) //!< FreeRTOS.
+#define ERPC_THREADS_ZEPHYR (3U)   //!< ZEPHYR.
+#define ERPC_THREADS_MBED (4U)     //!< Mbed OS
+#define ERPC_THREADS_WIN32 (5U)    //!< WIN32
+#define ERPC_THREADS_THREADX (6U)  //!< THREADX
+
+#define ERPC_NOEXCEPT_DISABLED (0U) //!< Disabling noexcept feature.
+#define ERPC_NOEXCEPT_ENABLED (1U)  //!<  Enabling noexcept feature.
+
+#define ERPC_NESTED_CALLS_DISABLED (0U) //!< No nested calls support.
+#define ERPC_NESTED_CALLS_ENABLED (1U)  //!< Nested calls support.
+
+#define ERPC_NESTED_CALLS_DETECTION_DISABLED (0U) //!< Nested calls detection disabled.
+#define ERPC_NESTED_CALLS_DETECTION_ENABLED (1U)  //!< Nested calls detection enabled.
+
+#define ERPC_MESSAGE_LOGGING_DISABLED (0U) //!< Trace functions disabled.
+#define ERPC_MESSAGE_LOGGING_ENABLED (1U)  //!< Trace functions enabled.
+
+#define ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED (0U) //!< Do not use MCMGR for MU ISR management.
+#define ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED (1U)  //!< Use MCMGR for MU ISR management.
+
+#define ERPC_PRE_POST_ACTION_DISABLED (0U) //!< Pre post shim callbacks functions disabled.
+#define ERPC_PRE_POST_ACTION_ENABLED (1U)  //!< Pre post shim callback functions enabled.
+
+#define ERPC_PRE_POST_ACTION_DEFAULT_DISABLED (0U) //!< Pre post shim default callbacks functions disabled.
+#define ERPC_PRE_POST_ACTION_DEFAULT_ENABLED (1U)  //!< Pre post shim default callback functions enabled.
+//@}
+
+//! @name Configuration options
+//@{
+
+//! @def ERPC_ALLOCATION_POLICY
+//!
+//! @brief Choose which allocation policy should be used.
+//!
+//! Set ERPC_ALLOCATION_POLICY_DYNAMIC if dynamic allocations should be used.
+//! Set ERPC_ALLOCATION_POLICY_STATIC if static allocations should be used.
+//!
+//! Default value is ERPC_ALLOCATION_POLICY_DYNAMIC or in case of FreeRTOS it can be auto-detected if __has_include() is
+//! supported by compiler. Uncomment comment bellow to use static allocation policy. In case of static implementation
+//! user need consider another values to set (ERPC_CODEC_COUNT, ERPC_MESSAGE_LOGGERS_COUNT,
+//! ERPC_CLIENTS_THREADS_AMOUNT).
+// #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC)
+
+//! @def ERPC_CODEC_COUNT
+//!
+//! @brief Set amount of codecs objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to
+//! ERPC_ALLOCATION_POLICY_STATIC. For example if client or server is used in one thread then 1. If both are used in one
+//! thread per each then 2, ... Default value 2.
+// #define ERPC_CODEC_COUNT (2U)
+
+//! @def ERPC_MESSAGE_LOGGERS_COUNT
+//!
+//! @brief Set amount of message loggers objects used simultaneously  in case of ERPC_ALLOCATION_POLICY is set to
+//! ERPC_ALLOCATION_POLICY_STATIC.
+//! For example if client or server is used in one thread then 1. If both are used in one thread per each then 2, ...
+//! For arbitrated client 1 is enough.
+//! Default value 0 (May not be used).
+// #define ERPC_MESSAGE_LOGGERS_COUNT (0U)
+
+//! @def ERPC_CLIENTS_THREADS_AMOUNT
+//!
+//! @brief Set amount of client threads objects used in case of ERPC_ALLOCATION_POLICY is set to
+//! ERPC_ALLOCATION_POLICY_STATIC. Default value 1 (Most of current cases).
+// #define ERPC_CLIENTS_THREADS_AMOUNT (1U)
+
+//! @def ERPC_THREADS
+//!
+//! @brief Select threading model.
+//!
+//! Set to one of the @c ERPC_THREADS_x macros to specify the threading model used by eRPC.
+//!
+//! Leave commented out to attempt to auto-detect. Auto-detection works well for pthreads.
+//! FreeRTOS can be detected when building with compilers that support __has_include().
+//! Otherwise, the default is no threading.
+//#define ERPC_THREADS (ERPC_THREADS_PTHREADS)
+
+//! @def ERPC_DEFAULT_BUFFER_SIZE
+//!
+//! Uncomment to change the size of buffers allocated by one of MessageBufferFactory.
+//! (@ref client_setup and @ref server_setup). The default size is set to 256.
+//! For RPMsg transport layer, ERPC_DEFAULT_BUFFER_SIZE must be 2^n - 16.
+//#define ERPC_DEFAULT_BUFFER_SIZE (256U)
+
+//! @def ERPC_DEFAULT_BUFFERS_COUNT
+//!
+//! Uncomment to change the count of buffers allocated by one of statically allocated messages.
+//! Default value is set to 2.
+//#define ERPC_DEFAULT_BUFFERS_COUNT (2U)
+
+//! @def ERPC_NOEXCEPT
+//!
+//! @brief Disable/enable noexcept support.
+//!
+//! Uncomment for using noexcept feature.
+//#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED)
+
+//! @def ERPC_NESTED_CALLS
+//!
+//! Default set to ERPC_NESTED_CALLS_DISABLED. Uncomment when callbacks, or other eRPC
+//! functions are called from server implementation of another eRPC call. Nested functions
+//! need to be marked as @nested in IDL.
+//#define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_ENABLED)
+
+//! @def ERPC_NESTED_CALLS_DETECTION
+//!
+//! Default set to ERPC_NESTED_CALLS_DETECTION_ENABLED when NDEBUG macro is presented.
+//! This serve for locating nested calls in code. Nested calls are calls where inside eRPC function
+//! on server side is called another eRPC function (like callbacks). Code need be a bit changed
+//! to support nested calls. See ERPC_NESTED_CALLS macro.
+//#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED)
+
+//! @def ERPC_MESSAGE_LOGGING
+//!
+//! Enable eRPC message logging code through the eRPC. Take look into "erpc_message_loggers.h". Can be used for base
+//! printing messages, or sending data to another system for data analysis. Default set to
+//! ERPC_MESSAGE_LOGGING_DISABLED.
+//!
+//! Uncomment for using logging feature.
+//#define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_ENABLED)
+
+//! @def ERPC_TRANSPORT_MU_USE_MCMGR
+//!
+//! @brief MU transport layer configuration.
+//!
+//! Set to one of the @c ERPC_TRANSPORT_MU_USE_MCMGR_x macros to configure the MCMGR usage in MU transport layer.
+//!
+//! MU transport layer could leverage the Multicore Manager (MCMGR) component for Inter-Core
+//! interrupts / MU interrupts management or the Inter-Core interrupts can be managed by itself (MUX_IRQHandler
+//! overloading). By default, ERPC_TRANSPORT_MU_USE_MCMGR is set to ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED when mcmgr.h
+//! is part of the project, otherwise the ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED option is used. This settings can be
+//! overwritten from the erpc_config.h by uncommenting the ERPC_TRANSPORT_MU_USE_MCMGR macro definition. Do not forget
+//! to add the MCMGR library into your project when ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED option is used! See the
+//! erpc_mu_transport.h for additional MU settings.
+//#define ERPC_TRANSPORT_MU_USE_MCMGR ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED
+//@}
+
+//! @def ERPC_PRE_POST_ACTION
+//!
+//! Enable eRPC pre and post callback functions shim code. Take look into "erpc_pre_post_action.h". Can be used for
+//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DISABLED.
+//!
+//! Uncomment for using pre post callback feature.
+//#define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_ENABLED)
+
+//! @def ERPC_PRE_POST_ACTION_DEFAULT
+//!
+//! Enable eRPC pre and post default callback functions. Take look into "erpc_setup_extensions.h". Can be used for
+//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DEFAULT_DISABLED.
+//!
+//! Uncomment for using pre post default callback feature.
+//#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_ENABLED)
+
+//! @name Assert function definition
+//@{
+//! User custom asser defition. Include header file if needed before bellow line. If assert is not enabled, default will
+//! be used.
+// #define erpc_assert(condition)
+//@}
+
+//! @def ENDIANES_HEADER
+//!
+//! Include header file that controls the communication endianness
+//!
+//! Uncomment for example behaviour for endianness agnostic with:
+//!  1. communication in little endian.
+//!  2. current processor is big endian.
+//!  3. pointer size is 32 bit.
+//!  4. float+double scheme not defined, so throws assert if passes.
+//! #define ERPC_PROCESSOR_ENDIANNESS_LITTLE 0
+//! #define ERPC_COMMUNICATION_LITTLE        1
+//! #define ERPC_POINTER_SIZE_16             0
+//! #define ERPC_POINTER_SIZE_32             1
+//! #define ERPC_POINTER_SIZE_64             0
+//! #define ENDIANNESS_HEADER "erpc_endianness_agnostic_example.h"
+
+/*! @} */
+#endif // _ERPC_CONFIG_H_
+////////////////////////////////////////////////////////////////////////////////
+// EOF
+////////////////////////////////////////////////////////////////////////////////
diff --git a/erpc/client/erpc_client_start.c b/erpc/client/erpc_client_start.c
new file mode 100644
index 0000000..f66b73b
--- /dev/null
+++ b/erpc/client/erpc_client_start.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "erpc_mbf_setup.h"
+#include "erpc_client_setup.h"
+#include "erpc_client_start.h"
+
+void erpc_client_start(erpc_transport_t transport)
+{
+    erpc_mbf_t message_buffer_factory;
+
+    message_buffer_factory = erpc_mbf_dynamic_init();
+    erpc_client_init(transport, message_buffer_factory);
+}
diff --git a/erpc/client/erpc_client_start.h b/erpc/client/erpc_client_start.h
new file mode 100644
index 0000000..37c056a
--- /dev/null
+++ b/erpc/client/erpc_client_start.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __ERPC_CLIENT_START_H__
+#define __ERPC_CLIENT_START_H__
+
+#include "erpc_transport_setup.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief eRPC Client initialization.
+ *
+ * \param[in] transport         Transport to use.
+ */
+void erpc_client_start(erpc_transport_t transport);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ERPC_CLIENT_START_H__ */
diff --git a/erpc/client/erpc_client_wrapper.c b/erpc/client/erpc_client_wrapper.c
new file mode 100644
index 0000000..37b5f82
--- /dev/null
+++ b/erpc/client/erpc_client_wrapper.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stddef.h>
+#include "psa/client.h"
+#include "tfm_erpc_psa_client_api.h"
+
+psa_status_t psa_call(psa_handle_t handle, int32_t type,
+                      const psa_invec *in_vec, size_t in_len,
+                      psa_outvec *out_vec, size_t out_len)
+{
+    psa_status_t status;
+    size_t i;
+    binary_t in_elements[PSA_MAX_IOVEC];
+    binary_t out_elements[PSA_MAX_IOVEC];
+    list_binary_1_t erpc_in_vec = {in_elements, in_len};
+    list_binary_1_t erpc_out_vec = {out_elements, out_len};
+
+    if (in_len + out_len > PSA_MAX_IOVEC) {
+        return PSA_ERROR_PROGRAMMER_ERROR;
+    }
+
+    /* Copy PSA iovecs into RPC binary lists */
+    for (i = 0; i < in_len; ++i) {
+        in_elements[i] = (binary_t){(void *)in_vec[i].base, in_vec[i].len};
+    }
+    for (i = 0; i < out_len; ++i) {
+        out_elements[i] = (binary_t){out_vec[i].base, out_vec[i].len};
+    }
+
+    status = erpc_psa_call(handle, type, &erpc_in_vec, &erpc_out_vec);
+
+    if (status != PSA_SUCCESS) {
+        return status;
+    }
+
+    /* Copy updated out length into PSA outvec */
+    for (i = 0; i < out_len; ++i) {
+        out_vec[i].len = out_elements[i].dataLength;
+    }
+
+    return status;
+}