Skip to content

Commit

Permalink
Bluetooth: Remove unnecessary runtime kernel object initialization
Browse files Browse the repository at this point in the history
There are static initializer macros available for most kernel objects
which we should use whenever possible.

Change-Id: I496f4d05d26801eddd21fae53bdd4fcdc3246fe3
Signed-off-by: Johan Hedberg <[email protected]>
  • Loading branch information
Johan Hedberg committed Dec 16, 2016
1 parent 8387483 commit 1c9da66
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 39 deletions.
6 changes: 1 addition & 5 deletions drivers/bluetooth/nble/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ NET_BUF_POOL_DEFINE(prep_pool, CONFIG_BLUETOOTH_ATT_PREPARE_COUNT,
BLE_GATT_MTU_SIZE, sizeof(struct nble_gatts_write_evt),
NULL);

static struct k_fifo queue;
static K_FIFO_DEFINE(queue);
#endif

struct nble_gatt_service {
Expand Down Expand Up @@ -1581,10 +1581,6 @@ void on_nble_gatts_read_evt(const struct nble_gatts_read_evt *ev)
void bt_gatt_init(void)
{
BT_DBG("");

#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0
k_fifo_init(&queue);
#endif
}

void bt_gatt_connected(struct bt_conn *conn)
Expand Down
3 changes: 1 addition & 2 deletions drivers/bluetooth/nble/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);

static struct device *nble_dev;

static struct k_fifo rx_queue;
static K_FIFO_DEFINE(rx_queue);

static void rx_thread(void)
{
Expand Down Expand Up @@ -218,7 +218,6 @@ int nble_open(void)
BT_DBG("");

/* Initialize receive queue and start rx_thread */
k_fifo_init(&rx_queue);
k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack),
(k_thread_entry_t)rx_thread,
NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
Expand Down
8 changes: 2 additions & 6 deletions samples/bluetooth/hci_uart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ NET_BUF_POOL_DEFINE(cmd_tx_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
NET_BUF_POOL_DEFINE(acl_tx_pool, TX_BUF_COUNT, BT_BUF_ACL_SIZE,
BT_BUF_USER_DATA_MIN, NULL);

static struct k_fifo tx_queue;
static K_FIFO_DEFINE(tx_queue);

#define H4_CMD 0x01
#define H4_ACL 0x02
Expand Down Expand Up @@ -353,15 +353,11 @@ DEVICE_INIT(hci_uart, "hci_uart", &hci_uart_init, NULL, NULL,
void main(void)
{
/* incoming events and data from the controller */
static struct k_fifo rx_queue;
static K_FIFO_DEFINE(rx_queue);
int err;

SYS_LOG_DBG("Start");

/* Initialize the FIFOs */
k_fifo_init(&tx_queue);
k_fifo_init(&rx_queue);

/* Enable the raw interface, this will in turn open the HCI driver */
bt_enable_raw(&rx_queue);
/* Spawn the TX thread and start feeding commands and data to the
Expand Down
4 changes: 1 addition & 3 deletions samples/bluetooth/hci_usb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static struct device *btusb_dev;
#define DEV_DATA(dev) \
((struct btusb_dev_data_t * const)(dev)->driver_data)

static struct k_fifo rx_queue;
static K_FIFO_DEFINE(rx_queue);

/* HCI command buffers */
#define CMD_BUF_SIZE (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
Expand Down Expand Up @@ -691,8 +691,6 @@ void main(void)
{
SYS_LOG_DBG("Start");

k_fifo_init(&rx_queue);

bt_enable_raw(&rx_queue);

while (1) {
Expand Down
3 changes: 1 addition & 2 deletions subsys/bluetooth/controller/hci/hci_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static uint8_t ALIGNED(4) _ticker_user_ops[RADIO_TICKER_USER_OPS]
[TICKER_USER_OP_T_SIZE];
static uint8_t ALIGNED(4) _radio[LL_MEM_TOTAL];

static struct k_sem sem_recv;
static K_SEM_DEFINE(sem_recv, 0, UINT_MAX);
static BT_STACK_NOINIT(recv_thread_stack,
CONFIG_BLUETOOTH_CONTROLLER_RX_STACK_SIZE);

Expand Down Expand Up @@ -348,7 +348,6 @@ static int hci_driver_open(void)
irq_enable(NRF5_IRQ_SWI4_IRQn);
irq_enable(NRF5_IRQ_SWI5_IRQn);

k_sem_init(&sem_recv, 0, UINT_MAX);
k_thread_spawn(recv_thread_stack, sizeof(recv_thread_stack),
recv_thread, NULL, NULL, NULL, K_PRIO_COOP(7), 0,
K_NO_WAIT);
Expand Down
26 changes: 13 additions & 13 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,19 @@
static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);
static BT_STACK_NOINIT(cmd_tx_thread_stack, CONFIG_BLUETOOTH_HCI_SEND_STACK);

struct bt_dev bt_dev;
struct bt_dev bt_dev = {
/* Give cmd_sem allowing to send first HCI_Reset cmd, the only
* exception is if the controller requests to wait for an
* initial Command Complete for NOP.
*/
#if !defined(CONFIG_BLUETOOTH_WAIT_NOP)
.ncmd_sem = K_SEM_INITIALIZER(bt_dev.ncmd_sem, 1, 1),
#else
.ncmd_sem = K_SEM_INITIALIZER(bt_dev.ncmd_sem, 0, 1),
#endif
.cmd_tx_queue = K_FIFO_INITIALIZER(bt_dev.cmd_tx_queue),
.rx_queue = K_FIFO_INITIALIZER(bt_dev.rx_queue),
};

const struct bt_storage *bt_storage;

Expand Down Expand Up @@ -3679,24 +3691,12 @@ int bt_enable(bt_ready_cb_t cb)
return -EALREADY;
}

/* Give cmd_sem allowing to send first HCI_Reset cmd, the only
* exception is if the controller requests to wait for an
* initial Command Complete for NOP.
*/
#if !defined(CONFIG_BLUETOOTH_WAIT_NOP)
k_sem_init(&bt_dev.ncmd_sem, 1, 1);
#else
k_sem_init(&bt_dev.ncmd_sem, 0, 1);
#endif

/* TX thread */
k_fifo_init(&bt_dev.cmd_tx_queue);
k_thread_spawn(cmd_tx_thread_stack, sizeof(cmd_tx_thread_stack),
(k_thread_entry_t)hci_cmd_tx_thread, NULL, NULL, NULL,
K_PRIO_COOP(7), 0, K_NO_WAIT);

/* RX thread */
k_fifo_init(&bt_dev.rx_queue);
k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack),
(k_thread_entry_t)hci_rx_thread, cb, NULL, NULL,
K_PRIO_COOP(7), 0, K_NO_WAIT);
Expand Down
4 changes: 1 addition & 3 deletions subsys/bluetooth/host/hci_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static const uint8_t debug_public_key[64] = {
};
#endif

static struct k_fifo ecc_queue;
static K_FIFO_DEFINE(ecc_queue);
static int (*drv_send)(struct net_buf *buf);
static uint32_t private_key[8];

Expand Down Expand Up @@ -277,8 +277,6 @@ static int ecc_send(struct net_buf *buf)

void bt_hci_ecc_init(void)
{
k_fifo_init(&ecc_queue);

k_thread_spawn(ecc_thread_stack, sizeof(ecc_thread_stack),
ecc_thread, NULL, NULL, NULL,
K_PRIO_PREEMPT(10), 0, K_NO_WAIT);
Expand Down
7 changes: 2 additions & 5 deletions tests/bluetooth/tester/src/bttester.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static char __stack stack[STACKSIZE];
#define CMD_QUEUED 2
static uint8_t cmd_buf[CMD_QUEUED * BTP_MTU];

static struct k_fifo cmds_queue;
static struct k_fifo avail_queue;
static K_FIFO_DEFINE(cmds_queue);
static K_FIFO_DEFINE(avail_queue);

static void supported_commands(uint8_t *data, uint16_t len)
{
Expand Down Expand Up @@ -206,9 +206,6 @@ void tester_init(void)
{
int i;

k_fifo_init(&cmds_queue);
k_fifo_init(&avail_queue);

for (i = 0; i < CMD_QUEUED; i++) {
k_fifo_put(&avail_queue, &cmd_buf[i * BTP_MTU]);
}
Expand Down

0 comments on commit 1c9da66

Please sign in to comment.