From ae995996684fb9b6df840b3723e059a10cdf037b Mon Sep 17 00:00:00 2001
From: Nick Saulnier <nsaulnier@ti.com>
Date: Wed, 14 Jun 2023 17:13:24 -0500
Subject: [PATCH] Linux_RPMsg_Echo: add additional endpoints

Create 2 additional endpoints that can be called from Linux userspace:
remote port 15
remote port 16
Each endpoint is given its own RTOS task, for 4 RTOS tasks total.

Note that all the endpoints that are intended for communication with Linux
userspace should be given the same service name of rpmsg_chrdev

sample usage with rpmsg_char_simple Linux userspace application:
rpmsg_char_simple -r 2 -n 10 -d rpmsg_chrdev -p 15
sends 10 RPMsg messages to endpoint #15

Signed-off-by: Nick Saulnier <nsaulnier@ti.com>
---
 .../ipc/ipc_rpmsg_echo_linux/ipc_rpmsg_echo.c | 58 ++++++++++++++++++-
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/examples/drivers/ipc/ipc_rpmsg_echo_linux/ipc_rpmsg_echo.c b/examples/drivers/ipc/ipc_rpmsg_echo_linux/ipc_rpmsg_echo.c
index f6f8b2355811..26b2cecaef8b 100644
--- a/examples/drivers/ipc/ipc_rpmsg_echo_linux/ipc_rpmsg_echo.c
+++ b/examples/drivers/ipc/ipc_rpmsg_echo_linux/ipc_rpmsg_echo.c
@@ -70,6 +70,20 @@
 #define IPC_RPMESSAGE_SERVICE_CHRDEV      "rpmsg_chrdev"
 #define IPC_RPMESSAGE_ENDPT_CHRDEV_PING   (14U)
 
+/* This is used to run the 2nd echo test with user space kernel */
+/*
+ * Additional endpoints for communication with userspace should all use the
+ * same IPC_RPMESSAGE_SERVICE_CHRDEV      "rpmsg_chrdev"
+ */
+#define IPC_RPMESSAGE_ENDPT_CHRDEV_PING2   (15U)
+
+/* This is used to run the 3rd echo test with user space kernel */
+/*
+ * Additional endpoints for communication with userspace should all use the
+ * same IPC_RPMESSAGE_SERVICE_CHRDEV      "rpmsg_chrdev"
+ */
+#define IPC_RPMESSAGE_ENDPT_CHRDEV_PING3   (16U)
+
 /* Use by this to receive ACK messages that it sends to other RTOS cores */
 #define IPC_RPMESSAGE_RNDPT_ACK_REPLY     (11U)
 
@@ -79,9 +93,9 @@
 /*
  * Number of RP Message ping "servers" we will start,
  * - one for ping messages for linux kernel "sample ping" client
- * - and another for ping messages from linux "user space" client using "rpmsg char"
+ * - and another three for ping messages from linux "user space" client using "rpmsg char"
  */
-#define IPC_RPMESSAGE_NUM_RECV_TASKS         (2u)
+#define IPC_RPMESSAGE_NUM_RECV_TASKS         (4u)
 
 /* RPMessage object used to recvice messages */
 RPMessage_Object gIpcRecvMsgObject[IPC_RPMESSAGE_NUM_RECV_TASKS];
@@ -249,6 +263,16 @@ void ipc_rpmsg_create_recv_tasks(void)
     status = RPMessage_construct(&gIpcRecvMsgObject[1], &createParams);
     DebugP_assert(status==SystemP_SUCCESS);
 
+    RPMessage_CreateParams_init(&createParams);
+    createParams.localEndPt = IPC_RPMESSAGE_ENDPT_CHRDEV_PING2;
+    status = RPMessage_construct(&gIpcRecvMsgObject[2], &createParams);
+    DebugP_assert(status==SystemP_SUCCESS);
+
+    RPMessage_CreateParams_init(&createParams);
+    createParams.localEndPt = IPC_RPMESSAGE_ENDPT_CHRDEV_PING3;
+    status = RPMessage_construct(&gIpcRecvMsgObject[3], &createParams);
+    DebugP_assert(status==SystemP_SUCCESS);
+
     /* We need to "announce" to Linux client else Linux does not know a service exists on this CPU
      * This is not mandatory to do for RTOS clients
      */
@@ -258,6 +282,12 @@ void ipc_rpmsg_create_recv_tasks(void)
     status = RPMessage_announce(CSL_CORE_ID_A53SS0_0, IPC_RPMESSAGE_ENDPT_CHRDEV_PING, IPC_RPMESSAGE_SERVICE_CHRDEV);
     DebugP_assert(status==SystemP_SUCCESS);
 
+    status = RPMessage_announce(CSL_CORE_ID_A53SS0_0, IPC_RPMESSAGE_ENDPT_CHRDEV_PING2, IPC_RPMESSAGE_SERVICE_CHRDEV);
+    DebugP_assert(status==SystemP_SUCCESS);
+
+    status = RPMessage_announce(CSL_CORE_ID_A53SS0_0, IPC_RPMESSAGE_ENDPT_CHRDEV_PING3, IPC_RPMESSAGE_SERVICE_CHRDEV);
+    DebugP_assert(status==SystemP_SUCCESS);
+
     /* Create the tasks which will handle the ping service */
     TaskP_Params_init(&taskParams);
     taskParams.name = "RPMESSAGE_PING";
@@ -282,6 +312,30 @@ void ipc_rpmsg_create_recv_tasks(void)
 
     status = TaskP_construct(&gIpcTask[1], &taskParams);
     DebugP_assert(status == SystemP_SUCCESS);
+
+    TaskP_Params_init(&taskParams);
+    taskParams.name = "RPMESSAGE_CHAR_PING2";
+    taskParams.stackSize = IPC_RPMESSAFE_TASK_STACK_SIZE;
+    taskParams.stack = gIpcTaskStack[2];
+    taskParams.priority = IPC_RPMESSAFE_TASK_PRI;
+    /* we use the same task function for echo but pass the appropiate rpmsg handle to it, to echo messages */
+    taskParams.args = &gIpcRecvMsgObject[2];
+    taskParams.taskMain = ipc_recv_task_main;
+
+    status = TaskP_construct(&gIpcTask[2], &taskParams);
+    DebugP_assert(status == SystemP_SUCCESS);
+
+    TaskP_Params_init(&taskParams);
+    taskParams.name = "RPMESSAGE_CHAR_PING3";
+    taskParams.stackSize = IPC_RPMESSAFE_TASK_STACK_SIZE;
+    taskParams.stack = gIpcTaskStack[3];
+    taskParams.priority = IPC_RPMESSAFE_TASK_PRI;
+    /* we use the same task function for echo but pass the appropiate rpmsg handle to it, to echo messages */
+    taskParams.args = &gIpcRecvMsgObject[3];
+    taskParams.taskMain = ipc_recv_task_main;
+
+    status = TaskP_construct(&gIpcTask[3], &taskParams);
+    DebugP_assert(status == SystemP_SUCCESS);
 }
 
 void ipc_rpmsg_echo_main(void *args)
-- 
2.34.1

