mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:22:53 +08:00
arch/sim: add bth4 bridge codes
Signed-off-by: chengkai <chengkai@xiaomi.com>
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
#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>
|
||||||
|
#include <nuttx/wireless/bluetooth/bt_bridge.h>
|
||||||
#include <nuttx/serial/uart_bth4.h>
|
#include <nuttx/serial/uart_bth4.h>
|
||||||
|
|
||||||
#include "up_internal.h"
|
#include "up_internal.h"
|
||||||
@@ -200,6 +201,33 @@ static struct bthcisock_s *bthcisock_alloc(int dev_id)
|
|||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bthcisock_free(struct bthcisock_s *dev)
|
||||||
|
{
|
||||||
|
sq_rem((sq_entry_t *)&dev->link, &g_bthcisock_list);
|
||||||
|
kmm_free(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bthcisock_driver_register(struct bt_driver_s *drv, int id,
|
||||||
|
bool bt)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_UART_BTH4
|
||||||
|
char name[32];
|
||||||
|
|
||||||
|
if (bt)
|
||||||
|
{
|
||||||
|
snprintf(name, sizeof(name), "/dev/ttyBT%d", id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(name, sizeof(name), "/dev/ttyBLE%d", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uart_bth4_register(name, drv);
|
||||||
|
#else
|
||||||
|
return bt_netdev_register(drv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -222,8 +250,9 @@ static struct bthcisock_s *bthcisock_alloc(int dev_id)
|
|||||||
int bthcisock_register(int dev_id)
|
int bthcisock_register(int dev_id)
|
||||||
{
|
{
|
||||||
struct bthcisock_s *dev;
|
struct bthcisock_s *dev;
|
||||||
#if defined(CONFIG_UART_BTH4)
|
#if defined(CONFIG_BLUETOOTH_BRIDGE)
|
||||||
char name[32];
|
struct bt_driver_s *btdrv;
|
||||||
|
struct bt_driver_s *bledrv;
|
||||||
#endif
|
#endif
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -233,15 +262,33 @@ int bthcisock_register(int dev_id)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_UART_BTH4)
|
#if defined(CONFIG_BLUETOOTH_BRIDGE)
|
||||||
snprintf(name, sizeof(name), "/dev/ttyHCI%d", dev_id);
|
ret = bt_bridge_register(&dev->drv, &btdrv, &bledrv);
|
||||||
ret = uart_bth4_register(name, &dev->drv);
|
|
||||||
#else
|
|
||||||
ret = bt_netdev_register(&dev->drv);
|
|
||||||
#endif
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
kmm_free(dev);
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bthcisock_driver_register(btdrv, dev_id, true);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bthcisock_driver_register(bledrv, dev_id, false);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
#else
|
||||||
|
ret = bthcisock_driver_register(&dev->drv, dev_id, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
bthcisock_free(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ CONFIG_ARCH_BOARD="sim"
|
|||||||
CONFIG_ARCH_BOARD_SIM=y
|
CONFIG_ARCH_BOARD_SIM=y
|
||||||
CONFIG_ARCH_CHIP="sim"
|
CONFIG_ARCH_CHIP="sim"
|
||||||
CONFIG_ARCH_SIM=y
|
CONFIG_ARCH_SIM=y
|
||||||
CONFIG_BLUETOOTH_UART=y
|
CONFIG_BLUETOOTH_BRIDGE=y
|
||||||
CONFIG_BOARDCTL_POWEROFF=y
|
CONFIG_BOARDCTL_POWEROFF=y
|
||||||
CONFIG_BUILTIN=y
|
CONFIG_BUILTIN=y
|
||||||
CONFIG_DEBUG_SYMBOLS=y
|
CONFIG_DEBUG_SYMBOLS=y
|
||||||
|
|||||||
Reference in New Issue
Block a user