Skip to content

Commit

Permalink
Bluetooth: Use unified k_fifo API for FIFOs
Browse files Browse the repository at this point in the history
Change-Id: I6ddc24575e4bf3c3040945a2bdb62f153b15cdb3
Signed-off-by: Szymon Janc <[email protected]>
  • Loading branch information
Szymon Janc authored and Johan Hedberg committed Nov 11, 2016
1 parent 3062516 commit 47eaaf9
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 73 deletions.
2 changes: 1 addition & 1 deletion include/bluetooth/hci_raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int bt_send(struct net_buf *buf);
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_enable_raw(struct nano_fifo *rx_queue);
int bt_enable_raw(struct k_fifo *rx_queue);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions include/bluetooth/rfcomm.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef enum bt_rfcomm_role {
/** @brief RFCOMM DLC structure. */
struct bt_rfcomm_dlc {
/* Queue for outgoing data */
struct nano_fifo tx_queue;
struct k_fifo tx_queue;

/** TX credits */
struct k_sem tx_credits;
Expand Down Expand Up @@ -171,7 +171,7 @@ int bt_rfcomm_dlc_send(struct bt_rfcomm_dlc *dlc, struct net_buf *buf);
*
* @return New buffer.
*/
struct net_buf *bt_rfcomm_create_pdu(struct nano_fifo *fifo);
struct net_buf *bt_rfcomm_create_pdu(struct k_fifo *fifo);

#ifdef __cplusplus
}
Expand Down
13 changes: 7 additions & 6 deletions samples/bluetooth/hci_uart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static uint8_t tx_fiber_stack[STACK_SIZE];
sizeof(struct bt_hci_cmd_hdr) + \
CONFIG_BLUETOOTH_MAX_CMD_LEN)

static struct nano_fifo avail_cmd_tx;
static struct k_fifo avail_cmd_tx;
static NET_BUF_POOL(cmd_tx_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
&avail_cmd_tx, NULL, BT_BUF_USER_DATA_MIN);

Expand All @@ -63,11 +63,12 @@ static NET_BUF_POOL(cmd_tx_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
#define TX_BUF_COUNT 6
#endif

static struct nano_fifo avail_acl_tx;
static struct k_fifo avail_acl_tx;

static NET_BUF_POOL(acl_tx_pool, TX_BUF_COUNT, BT_BUF_ACL_SIZE,
&avail_acl_tx, NULL, BT_BUF_USER_DATA_MIN);

static struct nano_fifo tx_queue;
static struct k_fifo tx_queue;

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

SYS_LOG_DBG("Start");
Expand All @@ -365,8 +366,8 @@ void main(void)
net_buf_pool_init(cmd_tx_pool);
net_buf_pool_init(acl_tx_pool);
/* Initialize the FIFOs */
nano_fifo_init(&tx_queue);
nano_fifo_init(&rx_queue);
k_fifo_init(&tx_queue);
k_fifo_init(&rx_queue);

task_fiber_start(tx_fiber_stack, STACK_SIZE,
(nano_fiber_entry_t)tx_fiber, 0, 0, 7, 0);
Expand Down
8 changes: 4 additions & 4 deletions samples/bluetooth/hci_usb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ static struct device *btusb_dev;
#define DEV_DATA(dev) \
((struct btusb_dev_data_t * const)(dev)->driver_data)

static struct nano_fifo rx_queue;
static struct k_fifo rx_queue;

/* HCI command buffers */
#define CMD_BUF_SIZE (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
sizeof(struct bt_hci_cmd_hdr) + \
CONFIG_BLUETOOTH_MAX_CMD_LEN)

static struct nano_fifo avail_tx;
static struct k_fifo avail_tx;
static NET_BUF_POOL(tx_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
&avail_tx, NULL, sizeof(uint8_t));

Expand All @@ -99,7 +99,7 @@ static NET_BUF_POOL(tx_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
4 /* L2CAP header size */ + \
BT_L2CAP_MTU)

static struct nano_fifo avail_acl_tx;
static struct k_fifo avail_acl_tx;
static NET_BUF_POOL(acl_tx_pool, 2, BT_BUF_ACL_SIZE, &avail_acl_tx, NULL,
sizeof(uint8_t));

Expand Down Expand Up @@ -697,7 +697,7 @@ void main(void)
/* Initialize the buffer pools */
net_buf_pool_init(tx_pool);
net_buf_pool_init(acl_tx_pool);
nano_fifo_init(&rx_queue);
k_fifo_init(&rx_queue);

bt_enable_raw(&rx_queue);

Expand Down
16 changes: 8 additions & 8 deletions subsys/bluetooth/host/att.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct bt_attr_data {
};

/* Pool for incoming ATT packets, MTU is 23 */
static struct nano_fifo prep_data;
static struct k_fifo prep_data;
static NET_BUF_POOL(prep_pool, CONFIG_BLUETOOTH_ATT_PREPARE_COUNT,
CONFIG_BLUETOOTH_ATT_MTU, &prep_data, NULL,
sizeof(struct bt_attr_data));
Expand All @@ -82,7 +82,7 @@ struct bt_att {
sys_slist_t reqs;
struct nano_delayed_work timeout_work;
#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0
struct nano_fifo prep_queue;
struct k_fifo prep_queue;
#endif
};

Expand All @@ -91,7 +91,7 @@ static struct bt_att bt_req_pool[CONFIG_BLUETOOTH_MAX_CONN];
/*
* Pool for outgoing ATT requests packets.
*/
static struct nano_fifo req_data;
static struct k_fifo req_data;
static NET_BUF_POOL(req_pool, CONFIG_BLUETOOTH_ATT_REQ_COUNT,
BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_ATT_MTU),
&req_data, NULL, BT_BUF_USER_DATA_MIN);
Expand All @@ -102,7 +102,7 @@ static NET_BUF_POOL(req_pool, CONFIG_BLUETOOTH_ATT_REQ_COUNT,
* may only be freed after a response is received which would never happen if
* the RX fiber is waiting a buffer causing a deadlock.
*/
static struct nano_fifo rsp_data;
static struct k_fifo rsp_data;
static NET_BUF_POOL(rsp_pool, 1,
BT_L2CAP_BUF_SIZE(CONFIG_BLUETOOTH_ATT_MTU),
&rsp_data, NULL, BT_BUF_USER_DATA_MIN);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ static uint8_t att_prep_write_rsp(struct bt_att *att, uint16_t handle,
}

/* Store buffer in the outstanding queue */
nano_fifo_put(&att->prep_queue, data.buf);
k_fifo_put(&att->prep_queue, data.buf);

/* Generate response */
data.buf = bt_att_create_pdu(conn, BT_ATT_OP_PREPARE_WRITE_RSP, 0);
Expand Down Expand Up @@ -1332,7 +1332,7 @@ static uint8_t att_exec_write_rsp(struct bt_att *att, uint8_t flags)
struct net_buf *buf;
uint8_t err = 0;

while ((buf = nano_fifo_get(&att->prep_queue, TICKS_NONE))) {
while ((buf = k_fifo_get(&att->prep_queue, K_NO_WAIT))) {
struct bt_attr_data *data = net_buf_user_data(buf);

/* Just discard the data if an error was set */
Expand Down Expand Up @@ -1816,7 +1816,7 @@ static void att_reset(struct bt_att *att)
struct net_buf *buf;

/* Discard queued buffers */
while ((buf = nano_fifo_get(&att->prep_queue, TICKS_NONE))) {
while ((buf = k_fifo_get(&att->prep_queue, K_NO_WAIT))) {
net_buf_unref(buf);
}
#endif
Expand Down Expand Up @@ -1874,7 +1874,7 @@ static void bt_att_connected(struct bt_l2cap_chan *chan)
BT_DBG("chan %p cid 0x%04x", ch, ch->tx.cid);

#if CONFIG_BLUETOOTH_ATT_PREPARE_COUNT > 0
nano_fifo_init(&att->prep_queue);
k_fifo_init(&att->prep_queue);
#endif

ch->tx.mtu = BT_ATT_DEFAULT_LE_MTU;
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/avdtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define CONFIG_BLUETOOTH_AVDTP_CONN CONFIG_BLUETOOTH_MAX_CONN

/* Pool for outgoing BR/EDR signaling packets, min MTU is 48 */
static struct nano_fifo avdtp_sig;
static struct k_fifo avdtp_sig;
static NET_BUF_POOL(avdtp_sig_pool, CONFIG_BLUETOOTH_AVDTP_CONN,
BT_AVDTP_BUF_SIZE(BT_AVDTP_MIN_MTU),
&avdtp_sig, NULL, BT_BUF_USER_DATA_MIN);
Expand Down
8 changes: 4 additions & 4 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
#endif

/* Pool for outgoing ACL fragments */
static struct nano_fifo frag_buf;
static struct k_fifo frag_buf;
static NET_BUF_POOL(frag_pool, 1, BT_L2CAP_BUF_SIZE(23), &frag_buf, NULL,
BT_BUF_USER_DATA_MIN);

/* Pool for dummy buffers to wake up the tx fibers */
static struct nano_fifo dummy;
static struct k_fifo dummy;
static NET_BUF_POOL(dummy_pool, CONFIG_BLUETOOTH_MAX_CONN, 0, &dummy, NULL, 0);

/* How long until we cancel HCI_LE_Create_Connection */
Expand Down Expand Up @@ -1112,7 +1112,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
/* Actions needed for entering the new state */
switch (conn->state) {
case BT_CONN_CONNECTED:
nano_fifo_init(&conn->tx_queue);
k_fifo_init(&conn->tx_queue);
fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber,
(int)bt_conn_ref(conn), 0, 7, 0);

Expand Down Expand Up @@ -1555,7 +1555,7 @@ int bt_conn_le_conn_update(struct bt_conn *conn,
return bt_hci_cmd_send(BT_HCI_OP_LE_CONN_UPDATE, buf);
}

struct net_buf *bt_conn_create_pdu(struct nano_fifo *fifo, size_t reserve)
struct net_buf *bt_conn_create_pdu(struct k_fifo *fifo, size_t reserve)
{
size_t head_reserve = reserve + sizeof(struct bt_hci_acl_hdr) +
CONFIG_BLUETOOTH_HCI_SEND_RESERVE;
Expand Down
4 changes: 2 additions & 2 deletions subsys/bluetooth/host/conn_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct bt_conn {
struct net_buf *rx;

/* Queue for outgoing ACL data */
struct nano_fifo tx_queue;
struct k_fifo tx_queue;

/* L2CAP channels */
void *channels;
Expand Down Expand Up @@ -179,7 +179,7 @@ void bt_conn_security_changed(struct bt_conn *conn);
#endif /* CONFIG_BLUETOOTH_SMP || CONFIG_BLUETOOTH_BREDR */

/* Prepare a PDU to be sent over a connection */
struct net_buf *bt_conn_create_pdu(struct nano_fifo *fifo, size_t reserve);
struct net_buf *bt_conn_create_pdu(struct k_fifo *fifo, size_t reserve);

/* Initialize connection management */
int bt_conn_init(void);
Expand Down
14 changes: 7 additions & 7 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ struct acl_data {
#define CMD_BUF_SIZE (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
sizeof(struct bt_hci_cmd_hdr) + \
CONFIG_BLUETOOTH_MAX_CMD_LEN)
static struct nano_fifo avail_hci_cmd;
static struct k_fifo avail_hci_cmd;
static NET_BUF_POOL(hci_cmd_pool, CONFIG_BLUETOOTH_HCI_CMD_COUNT, CMD_BUF_SIZE,
&avail_hci_cmd, NULL, sizeof(struct cmd_data));

#if defined(CONFIG_BLUETOOTH_HOST_BUFFERS)
/* HCI event buffers */
static struct nano_fifo avail_hci_evt;
static struct k_fifo avail_hci_evt;
static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT,
BT_BUF_EVT_SIZE, &avail_hci_evt, NULL,
BT_BUF_USER_DATA_MIN);
Expand All @@ -124,7 +124,7 @@ static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT,
* Complete Packets) if running low on buffers. Buffers from this pool are not
* allowed to be passed to RX fiber and must be returned from bt_recv().
*/
static struct nano_fifo avail_prio_hci_evt;
static struct k_fifo avail_prio_hci_evt;
static NET_BUF_POOL(hci_evt_prio_pool, 1,
BT_BUF_EVT_SIZE, &avail_prio_hci_evt, NULL,
BT_BUF_USER_DATA_MIN);
Expand All @@ -141,7 +141,7 @@ static void report_completed_packet(struct net_buf *buf)
uint16_t handle = acl(buf)->handle;
struct bt_hci_handle_count *hc;

nano_fifo_put(buf->free, buf);
k_fifo_put(buf->free, buf);

/* Do nothing if controller to host flow control is not supported */
if (!(bt_dev.supported_commands[10] & 0x20)) {
Expand All @@ -167,7 +167,7 @@ static void report_completed_packet(struct net_buf *buf)
bt_hci_cmd_send(BT_HCI_OP_HOST_NUM_COMPLETED_PACKETS, buf);
}

static struct nano_fifo avail_acl_in;
static struct k_fifo avail_acl_in;
static NET_BUF_POOL(acl_in_pool, CONFIG_BLUETOOTH_ACL_IN_COUNT,
BT_BUF_ACL_IN_SIZE, &avail_acl_in, report_completed_packet,
sizeof(struct acl_data));
Expand Down Expand Up @@ -3655,12 +3655,12 @@ int bt_enable(bt_ready_cb_t cb)
#endif /* !CONFIG_BLUETOOTH_WAIT_NOP */

/* TX fiber */
nano_fifo_init(&bt_dev.cmd_tx_queue);
k_fifo_init(&bt_dev.cmd_tx_queue);
fiber_start(cmd_tx_fiber_stack, sizeof(cmd_tx_fiber_stack),
(nano_fiber_entry_t)hci_cmd_tx_fiber, 0, 0, 7, 0);

/* RX fiber */
nano_fifo_init(&bt_dev.rx_queue);
k_fifo_init(&bt_dev.rx_queue);
fiber_start(rx_fiber_stack, sizeof(rx_fiber_stack),
(nano_fiber_entry_t)hci_rx_fiber, (int)cb, 0, 7, 0);

Expand Down
6 changes: 3 additions & 3 deletions subsys/bluetooth/host/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ struct bt_dev {
struct net_buf *sent_cmd;

/* Queue for incoming HCI events & ACL data */
struct nano_fifo rx_queue;
struct k_fifo rx_queue;

/* Queue for high priority HCI events which may unlock waiters
* in other fibers. Such events include Number of Completed
* Packets, as well as the Command Complete/Status events.
*/
struct nano_fifo rx_prio_queue;
struct k_fifo rx_prio_queue;

/* Queue for outgoing HCI commands */
struct nano_fifo cmd_tx_queue;
struct k_fifo cmd_tx_queue;

/* Registered HCI driver */
struct bt_hci_driver *drv;
Expand Down
6 changes: 3 additions & 3 deletions subsys/bluetooth/host/hci_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static const uint8_t debug_public_key[64] = {
};
#endif

static struct nano_fifo ecc_queue;
static struct k_fifo ecc_queue;
static bool ecc_queue_ready;
static int (*drv_send)(struct net_buf *buf);
static uint32_t private_key[8];
Expand Down Expand Up @@ -210,7 +210,7 @@ static void ecc_queue_init(void)
mask = irq_lock();

if (!ecc_queue_ready) {
nano_fifo_init(&ecc_queue);
k_fifo_init(&ecc_queue);
ecc_queue_ready = true;
}

Expand All @@ -224,7 +224,7 @@ static void ecc_task(void)
while (true) {
struct net_buf *buf;

buf = nano_task_fifo_get(&ecc_queue, TICKS_UNLIMITED);
buf = k_fifo_get(&ecc_queue, K_FOREVER);

switch (bt_hci_get_cmd_opcode(buf)) {
case BT_HCI_OP_LE_P256_PUBLIC_KEY:
Expand Down
8 changes: 4 additions & 4 deletions subsys/bluetooth/host/hci_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

#include "monitor.h"

static struct nano_fifo *raw_rx;
static struct k_fifo *raw_rx;

/* ACL incoming buffers */
static struct nano_fifo avail_acl_in;
static struct k_fifo avail_acl_in;
static NET_BUF_POOL(acl_in_pool, CONFIG_BLUETOOTH_ACL_IN_COUNT,
BT_BUF_ACL_IN_SIZE, &avail_acl_in, NULL,
sizeof(uint8_t));

/* HCI event buffers */
static struct nano_fifo avail_hci_evt;
static struct k_fifo avail_hci_evt;
static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT,
BT_BUF_EVT_SIZE, &avail_hci_evt, NULL,
sizeof(uint8_t));
Expand Down Expand Up @@ -113,7 +113,7 @@ int bt_send(struct net_buf *buf)
return bt_dev.drv->send(buf);
}

int bt_enable_raw(struct nano_fifo *rx_queue)
int bt_enable_raw(struct k_fifo *rx_queue)
{
struct bt_hci_driver *drv = bt_dev.drv;
int err;
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/hfp_hf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

struct bt_hfp_hf_cb *bt_hf;

static struct nano_fifo hf_fifo;
static struct k_fifo hf_fifo;
static NET_BUF_POOL(hf_pool, CONFIG_BLUETOOTH_MAX_CONN + 1,
BT_RFCOMM_BUF_SIZE(BLUETOOTH_HF_CLIENT_MAX_PDU),
&hf_fifo, NULL, BT_BUF_USER_DATA_MIN);
Expand Down
Loading

0 comments on commit 47eaaf9

Please sign in to comment.