rpmsgdev_server: Support exporting devices
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
parent
ae6a7a4526
commit
f2ca3753dd
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
x
Reference in New Issue
Block a user