wireless/bluetooth: Add driver object in all driver methods so that the driver has a way of maintaingin context.

This commit is contained in:
Gregory Nutt 2018-03-29 15:12:00 -06:00
parent accef0ca9e
commit aaf5fee1e6
5 changed files with 20 additions and 26 deletions

View File

@ -60,11 +60,12 @@ struct bt_driver_s
/* Open the HCI transport */
CODE int (*open)(void);
CODE int (*open)(FAR const struct bt_driver_s *dev);
/* Send data to HCI */
CODE int (*send)(FAR struct bt_buf_s *buf);
CODE int (*send)(FAR const struct bt_driver_s *dev,
FAR struct bt_buf_s *buf);
};
/****************************************************************************
@ -73,11 +74,11 @@ struct bt_driver_s
/* Register a new HCI driver to the Bluetooth stack */
int bt_driver_register(FAR struct bt_driver_s *drv);
int bt_driver_register(FAR const struct bt_driver_s *dev);
/* Unregister a previously registered HCI driver */
void bt_driver_unregister(FAR struct bt_driver_s *drv);
void bt_driver_unregister(FAR const struct bt_driver_s *dev);
/* Receive data from the controller/HCI driver */

View File

@ -1,5 +1,6 @@
#############################################################################
# Kconfig - Bluetooth LE stack configuration options
# wireless/bluetooth/Kconfig
# Bluetooth LE stack configuration options
#
# Copyright (C) 2018 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>

View File

@ -358,7 +358,7 @@ static int conn_tx_kthread(int argc, FAR char *argv[])
}
wlinfo("passing buf %p len %u to driver\n", buf, buf->len);
g_btdev.dev->send(buf);
g_btdev.dev->send(g_btdev.dev, buf);
bt_buf_put(buf);
}

View File

@ -169,7 +169,7 @@ int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf)
if (opcode == BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS)
{
g_btdev.dev->send(buf);
g_btdev.dev->send(g_btdev.dev, buf);
bt_buf_put(buf);
return 0;
}
@ -975,7 +975,7 @@ static void hci_event(FAR struct bt_buf_s *buf)
static int hci_tx_kthread(int argc, FAR char *argv[])
{
FAR struct bt_driver_s *dev = g_btdev.dev;
FAR const struct bt_driver_s *dev = g_btdev.dev;
int ret;
wlinfo("started\n");
@ -1006,7 +1006,7 @@ static int hci_tx_kthread(int argc, FAR char *argv[])
wlinfo("Sending command %x (buf %p) to driver\n",
buf->u.hci.opcode, buf);
dev->send(buf);
dev->send(dev, buf);
/* Clear out any existing sent command */
@ -1397,44 +1397,36 @@ void bt_recv(FAR struct bt_buf_s *buf)
}
}
int bt_driver_register(FAR struct bt_driver_s *dev)
int bt_driver_register(FAR const struct bt_driver_s *dev)
{
if (g_btdev.dev)
DEBUGASSERT(dev != NULL && dev->open != NULL && dev->send != NULL);
if (g_btdev.dev != NULL)
{
return -EALREADY;
}
if (!dev->open || !dev->send)
{
return -EINVAL;
}
g_btdev.dev = dev;
return 0;
}
void bt_driver_unregister(FAR struct bt_driver_s *dev)
void bt_driver_unregister(FAR const struct bt_driver_s *dev)
{
g_btdev.dev = NULL;
}
int bt_init(void)
{
FAR struct bt_driver_s *dev = g_btdev.dev;
FAR const struct bt_driver_s *dev = g_btdev.dev;
int err;
if (!dev)
{
wlerr("ERROR: No HCI driver registered\n");
return -ENODEV;
}
DEBUGASSERT(dev != NULL);
bt_buf_init();
cmd_queue_init();
rx_queue_init();
err = dev->open();
err = dev->open(dev);
if (err)
{
wlerr("ERROR: HCI driver open failed (%d)\n", err);

View File

@ -136,7 +136,7 @@ struct bt_dev_s
/* Registered HCI driver */
FAR struct bt_driver_s *dev;
FAR const struct bt_driver_s *dev;
};
/****************************************************************************