mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
nuttx/sim: use workquene instead of sim_bthcisock_loop
Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include <nuttx/nuttx.h>
|
#include <nuttx/nuttx.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/queue.h>
|
#include <nuttx/wqueue.h>
|
||||||
#include <nuttx/net/bluetooth.h>
|
#include <nuttx/net/bluetooth.h>
|
||||||
#include <nuttx/wireless/bluetooth/bt_driver.h>
|
#include <nuttx/wireless/bluetooth/bt_driver.h>
|
||||||
#include <nuttx/wireless/bluetooth/bt_uart.h>
|
#include <nuttx/wireless/bluetooth/bt_uart.h>
|
||||||
@@ -50,7 +50,8 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define BLUETOOTH_RX_FRAMELEN 1024
|
#define SIM_BTHCI_RX_FRAMELEN 1024
|
||||||
|
#define SIM_BTHCI_WORK_DELAY USEC2TICK(1000)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
@@ -59,9 +60,12 @@
|
|||||||
struct bthcisock_s
|
struct bthcisock_s
|
||||||
{
|
{
|
||||||
struct bt_driver_s drv;
|
struct bt_driver_s drv;
|
||||||
int id;
|
int id;
|
||||||
int fd;
|
int fd;
|
||||||
sq_entry_t link;
|
|
||||||
|
/* Work queue for transmit */
|
||||||
|
|
||||||
|
struct work_s worker;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -75,12 +79,6 @@ static int bthcisock_open(struct bt_driver_s *drv);
|
|||||||
static void bthcisock_close(struct bt_driver_s *drv);
|
static void bthcisock_close(struct bt_driver_s *drv);
|
||||||
static int bthcisock_receive(struct bt_driver_s *drv);
|
static int bthcisock_receive(struct bt_driver_s *drv);
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static sq_queue_t g_bthcisock_list;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -126,7 +124,7 @@ static void bthcisock_close(struct bt_driver_s *drv)
|
|||||||
static int bthcisock_receive(struct bt_driver_s *drv)
|
static int bthcisock_receive(struct bt_driver_s *drv)
|
||||||
{
|
{
|
||||||
struct bthcisock_s *dev = (struct bthcisock_s *)drv;
|
struct bthcisock_s *dev = (struct bthcisock_s *)drv;
|
||||||
char data[BLUETOOTH_RX_FRAMELEN];
|
char data[SIM_BTHCI_RX_FRAMELEN];
|
||||||
enum bt_buf_type_e type;
|
enum bt_buf_type_e type;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -196,14 +194,11 @@ static struct bthcisock_s *bthcisock_alloc(int dev_id)
|
|||||||
drv->send = bthcisock_send;
|
drv->send = bthcisock_send;
|
||||||
drv->close = bthcisock_close;
|
drv->close = bthcisock_close;
|
||||||
|
|
||||||
sq_addlast(&dev->link, &g_bthcisock_list);
|
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bthcisock_free(struct bthcisock_s *dev)
|
static void bthcisock_free(struct bthcisock_s *dev)
|
||||||
{
|
{
|
||||||
sq_rem((sq_entry_t *)&dev->link, &g_bthcisock_list);
|
|
||||||
kmm_free(dev);
|
kmm_free(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +223,27 @@ static int bthcisock_driver_register(struct bt_driver_s *drv, int id,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sim_bthcisock_work
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Feed pending packets on the host sockets into the Bluetooth stack.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void sim_bthcisock_work(void *arg)
|
||||||
|
{
|
||||||
|
struct bthcisock_s *dev = arg;
|
||||||
|
|
||||||
|
if (host_bthcisock_avail(dev->fd))
|
||||||
|
{
|
||||||
|
bthcisock_receive(&dev->drv);
|
||||||
|
}
|
||||||
|
|
||||||
|
work_queue(HPWORK, &dev->worker,
|
||||||
|
sim_bthcisock_work, dev, SIM_BTHCI_WORK_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -289,39 +305,8 @@ end:
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
bthcisock_free(dev);
|
bthcisock_free(dev);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return work_queue(HPWORK, &dev->worker, sim_bthcisock_work, dev, 0);
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: sim_bthcisock_loop
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Feed pending packets on the host sockets into the Bluetooth stack.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* Zero is returned on success; a negated errno value is returned on any
|
|
||||||
* failure.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int sim_bthcisock_loop(void)
|
|
||||||
{
|
|
||||||
struct bthcisock_s *dev;
|
|
||||||
sq_entry_t *entry;
|
|
||||||
|
|
||||||
for (entry = sq_peek(&g_bthcisock_list); entry; entry = sq_next(entry))
|
|
||||||
{
|
|
||||||
dev = container_of(entry, struct bthcisock_s, link);
|
|
||||||
if (host_bthcisock_avail(dev->fd))
|
|
||||||
{
|
|
||||||
bthcisock_receive(&dev->drv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,10 +187,6 @@ static int sim_loop_task(int argc, char **argv)
|
|||||||
host_usrsock_loop();
|
host_usrsock_loop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_HCISOCKET
|
|
||||||
sim_bthcisock_loop();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_SOUND
|
#ifdef CONFIG_SIM_SOUND
|
||||||
sim_audio_loop();
|
sim_audio_loop();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -358,7 +358,6 @@ int sim_rptun_init(const char *shmemname, const char *cpuname, bool master);
|
|||||||
|
|
||||||
#ifdef CONFIG_SIM_HCISOCKET
|
#ifdef CONFIG_SIM_HCISOCKET
|
||||||
int sim_bthcisock_register(int dev_id);
|
int sim_bthcisock_register(int dev_id);
|
||||||
int sim_bthcisock_loop(void);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* sim_audio.c **************************************************************/
|
/* sim_audio.c **************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user