nuttx/sim: use workquene instead rptun_loop

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao 2023-07-11 12:07:09 +08:00 committed by Xiang Xiao
parent 3c63b9b646
commit 0b01340aec
3 changed files with 42 additions and 41 deletions

View File

@ -187,10 +187,6 @@ static int sim_loop_task(int argc, char **argv)
host_usrsock_loop(); host_usrsock_loop();
#endif #endif
#ifdef CONFIG_RPTUN
sim_rptun_loop();
#endif
#ifdef CONFIG_SIM_HCISOCKET #ifdef CONFIG_SIM_HCISOCKET
sim_bthcisock_loop(); sim_bthcisock_loop();
#endif #endif

View File

@ -350,7 +350,6 @@ void sim_netdriver_loop(void);
#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, bool master);
void sim_rptun_loop(void);
#endif #endif
/* sim_hcisocket.c **********************************************************/ /* sim_hcisocket.c **********************************************************/

View File

@ -25,9 +25,16 @@
#include <nuttx/drivers/addrenv.h> #include <nuttx/drivers/addrenv.h>
#include <nuttx/rptun/rptun.h> #include <nuttx/rptun/rptun.h>
#include <nuttx/list.h> #include <nuttx/list.h>
#include <nuttx/wqueue.h>
#include "sim_internal.h" #include "sim_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define SIM_RPTUN_WORK_DELAY 1
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@ -43,7 +50,6 @@ struct sim_rptun_shmem_s
struct sim_rptun_dev_s struct sim_rptun_dev_s
{ {
struct list_node node;
struct rptun_dev_s rptun; struct rptun_dev_s rptun;
rptun_callback_t callback; rptun_callback_t callback;
void *arg; void *arg;
@ -53,6 +59,10 @@ struct sim_rptun_dev_s
struct simple_addrenv_s addrenv[2]; struct simple_addrenv_s addrenv[2];
char cpuname[RPMSG_NAME_SIZE + 1]; char cpuname[RPMSG_NAME_SIZE + 1];
char shmemname[RPMSG_NAME_SIZE + 1]; char shmemname[RPMSG_NAME_SIZE + 1];
/* Work queue for transmit */
struct work_s worker;
}; };
/**************************************************************************** /****************************************************************************
@ -195,37 +205,10 @@ static int sim_rptun_register_callback(struct rptun_dev_s *dev,
return 0; return 0;
} }
/**************************************************************************** static void sim_rptun_work(void *arg)
* Private Data
****************************************************************************/
static const struct rptun_ops_s g_sim_rptun_ops =
{ {
.get_cpuname = sim_rptun_get_cpuname, struct sim_rptun_dev_s *dev = arg;
.get_firmware = sim_rptun_get_firmware,
.get_addrenv = sim_rptun_get_addrenv,
.get_resource = sim_rptun_get_resource,
.is_autostart = sim_rptun_is_autostart,
.is_master = sim_rptun_is_master,
.start = sim_rptun_start,
.stop = sim_rptun_stop,
.notify = sim_rptun_notify,
.register_callback = sim_rptun_register_callback,
};
static struct list_node g_dev_list = LIST_INITIAL_VALUE(g_dev_list);
/****************************************************************************
* Public Functions
****************************************************************************/
void sim_rptun_loop(void)
{
struct sim_rptun_dev_s *dev;
list_for_every_entry(&g_dev_list, dev,
struct sim_rptun_dev_s, node)
{
if (dev->shmem != NULL) if (dev->shmem != NULL)
{ {
bool should_notify = false; bool should_notify = false;
@ -246,9 +229,33 @@ void sim_rptun_loop(void)
dev->callback(dev->arg, RPTUN_NOTIFY_ALL); dev->callback(dev->arg, RPTUN_NOTIFY_ALL);
} }
} }
}
work_queue(HPWORK, &dev->worker,
sim_rptun_work, dev, SIM_RPTUN_WORK_DELAY);
} }
/****************************************************************************
* Private Data
****************************************************************************/
static const struct rptun_ops_s g_sim_rptun_ops =
{
.get_cpuname = sim_rptun_get_cpuname,
.get_firmware = sim_rptun_get_firmware,
.get_addrenv = sim_rptun_get_addrenv,
.get_resource = sim_rptun_get_resource,
.is_autostart = sim_rptun_is_autostart,
.is_master = sim_rptun_is_master,
.start = sim_rptun_start,
.stop = sim_rptun_stop,
.notify = sim_rptun_notify,
.register_callback = sim_rptun_register_callback,
};
/****************************************************************************
* Public Functions
****************************************************************************/
int sim_rptun_init(const char *shmemname, const char *cpuname, bool master) int sim_rptun_init(const char *shmemname, const char *cpuname, bool master)
{ {
struct sim_rptun_dev_s *dev; struct sim_rptun_dev_s *dev;
@ -264,14 +271,13 @@ int sim_rptun_init(const char *shmemname, const char *cpuname, bool master)
dev->rptun.ops = &g_sim_rptun_ops; dev->rptun.ops = &g_sim_rptun_ops;
strlcpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE); strlcpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE);
strlcpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE); strlcpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE);
list_add_tail(&g_dev_list, &dev->node);
ret = rptun_initialize(&dev->rptun); ret = rptun_initialize(&dev->rptun);
if (ret < 0) if (ret < 0)
{ {
list_delete(&dev->node);
kmm_free(dev); kmm_free(dev);
return ret;
} }
return ret; return work_queue(HPWORK, &dev->worker, sim_rptun_work, dev, 0);
} }