You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/15 02:18:15 UTC

(nuttx) 01/02: rpmsgdev_server: Support exporting devices

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f2ca3753ddd90f09196b4f67eca3058d8358c450
Author: wangjianyu3 <wa...@xiaomi.com>
AuthorDate: Wed Jun 5 19:18:26 2024 +0800

    rpmsgdev_server: Support exporting devices
    
    Signed-off-by: wangjianyu3 <wa...@xiaomi.com>
---
 drivers/misc/rpmsgdev_server.c   | 48 ++++++++++++++++++++++++++++++++++++++++
 include/nuttx/drivers/rpmsgdev.h |  1 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/misc/rpmsgdev_server.c b/drivers/misc/rpmsgdev_server.c
index b68ff588c6..93e1389036 100644
--- a/drivers/misc/rpmsgdev_server.c
+++ b/drivers/misc/rpmsgdev_server.c
@@ -22,6 +22,7 @@
  * Included Files
  ****************************************************************************/
 
+#include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
 #include <poll.h>
@@ -67,6 +68,12 @@ struct rpmsgdev_server_s
   struct work_s         work;  /* Poll notify work */
 };
 
+struct rpmsgdev_export_s
+{
+  FAR const char *remotecpu;  /* The client cpu name */
+  FAR const char *localpath;  /* The device path in the server cpu */
+};
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -488,10 +495,51 @@ static int rpmsgdev_ept_cb(FAR struct rpmsg_endpoint *ept,
   return -EINVAL;
 }
 
+static void rpmsgdev_server_created(FAR struct rpmsg_device *rdev,
+                                    FAR void *priv_)
+{
+  struct rpmsgdev_export_s *priv = priv_;
+  char buf[RPMSG_NAME_SIZE];
+
+  if (strcmp(priv->remotecpu, rpmsg_get_cpuname(rdev)) == 0)
+    {
+      snprintf(buf, sizeof(buf), "%s%s", RPMSGDEV_NAME_PREFIX,
+               priv->localpath);
+      rpmsgdev_ns_bind(rdev, NULL, buf, RPMSG_ADDR_ANY);
+    }
+
+  rpmsg_unregister_callback(priv,
+                            rpmsgdev_server_created,
+                            NULL,
+                            NULL,
+                            NULL);
+  kmm_free(priv);
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+int rpmsgdev_export(FAR const char *remotecpu, FAR const char *localpath)
+{
+  FAR struct rpmsgdev_export_s *priv;
+
+  priv = kmm_zalloc(sizeof(*priv));
+  if (priv == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  priv->remotecpu = remotecpu;
+  priv->localpath = localpath;
+
+  return rpmsg_register_callback(priv,
+                                 rpmsgdev_server_created,
+                                 NULL,
+                                 NULL,
+                                 NULL);
+}
+
 /****************************************************************************
  * Name: rpmsgdev_server_init
  *
diff --git a/include/nuttx/drivers/rpmsgdev.h b/include/nuttx/drivers/rpmsgdev.h
index 7ddeb95cc9..156f8c9326 100644
--- a/include/nuttx/drivers/rpmsgdev.h
+++ b/include/nuttx/drivers/rpmsgdev.h
@@ -63,6 +63,7 @@ extern "C"
 
 #ifdef CONFIG_DEV_RPMSG_SERVER
 int rpmsgdev_server_init(void);
+int rpmsgdev_export(FAR const char *remotecpu, FAR const char *localpath);
 #endif
 
 /****************************************************************************