diff --git a/arch/sim/src/sim/sim_internal.h b/arch/sim/src/sim/sim_internal.h index cb5cccdb146..c62b78d5382 100644 --- a/arch/sim/src/sim/sim_internal.h +++ b/arch/sim/src/sim/sim_internal.h @@ -42,6 +42,16 @@ * 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 # define CONFIG_SMP_NCPUS 1 #endif @@ -362,7 +372,7 @@ void sim_netdriver_loop(void); /* sim_rptun.c **************************************************************/ #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 /* sim_hcisocket.c **********************************************************/ diff --git a/arch/sim/src/sim/sim_rptun.c b/arch/sim/src/sim/sim_rptun.c index df35dae7cb3..b88f05de7dc 100644 --- a/arch/sim/src/sim/sim_rptun.c +++ b/arch/sim/src/sim/sim_rptun.c @@ -59,7 +59,7 @@ struct sim_rptun_dev_s struct rptun_dev_s rptun; rptun_callback_t callback; void *arg; - bool master; + int master; unsigned int seq; struct sim_rptun_shmem_s *shmem; 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); pid_t pid; - pid = host_posix_spawn(sim_rptun_get_cpuname(dev), NULL, NULL); - if (pid < 0) + if (priv->master & SIM_RPTUN_BOOT) { - 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; } @@ -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, 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); - priv->shmem = NULL; + host_freeshmem(priv->shmem); + priv->shmem = NULL; + } return 0; } @@ -321,7 +328,7 @@ static const struct rptun_ops_s g_sim_rptun_ops = * 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; int ret; diff --git a/boards/sim/sim/sim/src/sim_bringup.c b/boards/sim/sim/sim/src/sim_bringup.c index 057180a3c33..b7c13435462 100644 --- a/boards/sim/sim/sim/src/sim_bringup.c +++ b/boards/sim/sim/sim/src/sim_bringup.c @@ -463,9 +463,10 @@ int sim_bringup(void) #ifdef CONFIG_RPTUN #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 - sim_rptun_init("server-proxy", "server", false); + sim_rptun_init("server-proxy", "server", SIM_RPTUN_SLAVE); #endif #ifdef CONFIG_DEV_RPMSG