nuttx/sim: Sim_rptun support configuring whether the master will automatically boot slave

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao
2023-08-31 23:44:48 +08:00
committed by Petro Karashchenko
parent df98320c2c
commit cb105192c7
3 changed files with 31 additions and 13 deletions
+11 -1
View File
@@ -42,6 +42,16 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Determine master-slave relationship when configuring with multiple cores */
#ifdef CONFIG_RPTUN
# define SIM_RPTUN_MASTER (1 << 0) /* As the master */
# define SIM_RPTUN_SLAVE (0 << 0) /* As the slave */
# define SIM_RPTUN_BOOT (1 << 1) /* As the master and boot the slave */
# define SIM_RPTUN_NOBOOT (0 << 1) /* As the master but not boot the slave */
#endif
#ifndef CONFIG_SMP_NCPUS #ifndef CONFIG_SMP_NCPUS
# define CONFIG_SMP_NCPUS 1 # define CONFIG_SMP_NCPUS 1
#endif #endif
@@ -362,7 +372,7 @@ void sim_netdriver_loop(void);
/* sim_rptun.c **************************************************************/ /* sim_rptun.c **************************************************************/
#ifdef CONFIG_RPTUN #ifdef CONFIG_RPTUN
int sim_rptun_init(const char *shmemname, const char *cpuname, bool master); int sim_rptun_init(const char *shmemname, const char *cpuname, int master);
#endif #endif
/* sim_hcisocket.c **********************************************************/ /* sim_hcisocket.c **********************************************************/
+17 -10
View File
@@ -59,7 +59,7 @@ struct sim_rptun_dev_s
struct rptun_dev_s rptun; struct rptun_dev_s rptun;
rptun_callback_t callback; rptun_callback_t callback;
void *arg; void *arg;
bool master; int master;
unsigned int seq; unsigned int seq;
struct sim_rptun_shmem_s *shmem; struct sim_rptun_shmem_s *shmem;
struct simple_addrenv_s addrenv[2]; struct simple_addrenv_s addrenv[2];
@@ -179,13 +179,17 @@ static int sim_rptun_start(struct rptun_dev_s *dev)
struct sim_rptun_dev_s, rptun); struct sim_rptun_dev_s, rptun);
pid_t pid; pid_t pid;
pid = host_posix_spawn(sim_rptun_get_cpuname(dev), NULL, NULL); if (priv->master & SIM_RPTUN_BOOT)
if (pid < 0)
{ {
return pid; pid = host_posix_spawn(sim_rptun_get_cpuname(dev), NULL, NULL);
if (pid < 0)
{
return pid;
}
priv->pid = pid;
} }
priv->pid = pid;
return 0; return 0;
} }
@@ -194,12 +198,15 @@ static int sim_rptun_stop(struct rptun_dev_s *dev)
struct sim_rptun_dev_s *priv = container_of(dev, struct sim_rptun_dev_s *priv = container_of(dev,
struct sim_rptun_dev_s, rptun); struct sim_rptun_dev_s, rptun);
priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT; if (priv->master & SIM_RPTUN_BOOT)
{
priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT;
host_waitpid(priv->pid); host_waitpid(priv->pid);
host_freeshmem(priv->shmem); host_freeshmem(priv->shmem);
priv->shmem = NULL; priv->shmem = NULL;
}
return 0; return 0;
} }
@@ -321,7 +328,7 @@ static const struct rptun_ops_s g_sim_rptun_ops =
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
int sim_rptun_init(const char *shmemname, const char *cpuname, bool master) int sim_rptun_init(const char *shmemname, const char *cpuname, int master)
{ {
struct sim_rptun_dev_s *dev; struct sim_rptun_dev_s *dev;
int ret; int ret;
+3 -2
View File
@@ -463,9 +463,10 @@ int sim_bringup(void)
#ifdef CONFIG_RPTUN #ifdef CONFIG_RPTUN
#ifdef CONFIG_SIM_RPTUN_MASTER #ifdef CONFIG_SIM_RPTUN_MASTER
sim_rptun_init("server-proxy", "proxy", true); sim_rptun_init("server-proxy", "proxy",
SIM_RPTUN_MASTER | SIM_RPTUN_NOBOOT);
#else #else
sim_rptun_init("server-proxy", "server", false); sim_rptun_init("server-proxy", "server", SIM_RPTUN_SLAVE);
#endif #endif
#ifdef CONFIG_DEV_RPMSG #ifdef CONFIG_DEV_RPMSG