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 #include #include #include @@ -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 /****************************************************************************