Bluetooth: Use k_thread_spawn() instead of deprecated nano_fiber_start()
Switch to using the unified kernel k_thread_spawn() API instead of nano_fiber_start(). Change-Id: I325cf467ae2a52c6aec8fc166397c323929e3013 Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
b0f0742b6e
commit
918a8e6bac
7 changed files with 52 additions and 48 deletions
|
@ -589,7 +589,7 @@ static int h5_queue(struct net_buf *buf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tx_fiber(void)
|
static void tx_thread(void)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
BT_DBG("");
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ static void h5_set_txwin(uint8_t *conf)
|
||||||
conf[2] = h5.tx_win & 0x07;
|
conf[2] = h5.tx_win & 0x07;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rx_fiber(void)
|
static void rx_thread(void)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
BT_DBG("");
|
||||||
|
|
||||||
|
@ -701,17 +701,17 @@ static void h5_init(void)
|
||||||
h5.rx_state = START;
|
h5.rx_state = START;
|
||||||
h5.tx_win = 4;
|
h5.tx_win = 4;
|
||||||
|
|
||||||
/* TX fiber */
|
/* TX thread */
|
||||||
k_fifo_init(&h5.tx_queue);
|
k_fifo_init(&h5.tx_queue);
|
||||||
fiber_start(tx_stack, sizeof(tx_stack), (nano_fiber_entry_t)tx_fiber,
|
k_thread_spawn(tx_stack, sizeof(tx_stack), (k_thread_entry_t)tx_thread,
|
||||||
0, 0, 7, 0);
|
NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||||
|
|
||||||
/* RX fiber */
|
/* RX thread */
|
||||||
net_buf_pool_init(signal_pool);
|
net_buf_pool_init(signal_pool);
|
||||||
|
|
||||||
k_fifo_init(&h5.rx_queue);
|
k_fifo_init(&h5.rx_queue);
|
||||||
fiber_start(rx_stack, sizeof(rx_stack), (nano_fiber_entry_t)rx_fiber,
|
k_thread_spawn(rx_stack, sizeof(rx_stack), (k_thread_entry_t)rx_thread,
|
||||||
0, 0, 7, 0);
|
NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||||
|
|
||||||
/* Unack queue */
|
/* Unack queue */
|
||||||
k_fifo_init(&h5.unack_queue);
|
k_fifo_init(&h5.unack_queue);
|
||||||
|
|
|
@ -67,11 +67,11 @@ config BLUETOOTH_MAX_PAIRED
|
||||||
default 7
|
default 7
|
||||||
|
|
||||||
config BLUETOOTH_RX_STACK_SIZE
|
config BLUETOOTH_RX_STACK_SIZE
|
||||||
int "Size of the receiving fiber stack"
|
int "Size of the receiving thread stack"
|
||||||
default 1024
|
default 1024
|
||||||
range 1024 65536
|
range 1024 65536
|
||||||
help
|
help
|
||||||
Size of the receiving fiber stack. This is the context from
|
Size of the receiving thread stack. This is the context from
|
||||||
which all event callbacks to the application occur. The
|
which all event callbacks to the application occur. The
|
||||||
default value is sufficient for basic operation, but if the
|
default value is sufficient for basic operation, but if the
|
||||||
application needs to do advanced things in its callbacks that
|
application needs to do advanced things in its callbacks that
|
||||||
|
|
|
@ -63,13 +63,13 @@ static NET_BUF_POOL(rx_pool, NBLE_RX_BUF_COUNT, NBLE_BUF_SIZE, &rx, NULL, 0);
|
||||||
static struct k_fifo tx;
|
static struct k_fifo tx;
|
||||||
static NET_BUF_POOL(tx_pool, NBLE_TX_BUF_COUNT, NBLE_BUF_SIZE, &tx, NULL, 0);
|
static NET_BUF_POOL(tx_pool, NBLE_TX_BUF_COUNT, NBLE_BUF_SIZE, &tx, NULL, 0);
|
||||||
|
|
||||||
static BT_STACK_NOINIT(rx_fiber_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);
|
static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);
|
||||||
|
|
||||||
static struct device *nble_dev;
|
static struct device *nble_dev;
|
||||||
|
|
||||||
static struct k_fifo rx_queue;
|
static struct k_fifo rx_queue;
|
||||||
|
|
||||||
static void rx_fiber(void)
|
static void rx_thread(void)
|
||||||
{
|
{
|
||||||
BT_DBG("Started");
|
BT_DBG("Started");
|
||||||
|
|
||||||
|
@ -218,10 +218,11 @@ int nble_open(void)
|
||||||
{
|
{
|
||||||
BT_DBG("");
|
BT_DBG("");
|
||||||
|
|
||||||
/* Initialize receive queue and start rx_fiber */
|
/* Initialize receive queue and start rx_thread */
|
||||||
k_fifo_init(&rx_queue);
|
k_fifo_init(&rx_queue);
|
||||||
fiber_start(rx_fiber_stack, sizeof(rx_fiber_stack),
|
k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack),
|
||||||
(nano_fiber_entry_t)rx_fiber, 0, 0, 7, 0);
|
(k_thread_entry_t)rx_thread,
|
||||||
|
NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||||
|
|
||||||
uart_irq_rx_disable(nble_dev);
|
uart_irq_rx_disable(nble_dev);
|
||||||
uart_irq_tx_disable(nble_dev);
|
uart_irq_tx_disable(nble_dev);
|
||||||
|
|
|
@ -111,11 +111,11 @@ config BLUETOOTH_INTERNAL_STORAGE
|
||||||
an internal default handler is used for this.
|
an internal default handler is used for this.
|
||||||
|
|
||||||
config BLUETOOTH_RX_STACK_SIZE
|
config BLUETOOTH_RX_STACK_SIZE
|
||||||
int "Size of the receiving fiber stack"
|
int "Size of the receiving thread stack"
|
||||||
default 1024
|
default 1024
|
||||||
range 1024 65536
|
range 1024 65536
|
||||||
help
|
help
|
||||||
Size of the receiving fiber stack. This is the context from
|
Size of the receiving thread stack. This is the context from
|
||||||
which all event callbacks to the application occur. The
|
which all event callbacks to the application occur. The
|
||||||
default value is sufficient for basic operation, but if the
|
default value is sufficient for basic operation, but if the
|
||||||
application needs to do advanced things in its callbacks that
|
application needs to do advanced things in its callbacks that
|
||||||
|
|
|
@ -1004,9 +1004,9 @@ static bool send_buf(struct bt_conn *conn, struct net_buf *buf)
|
||||||
return send_frag(conn, buf, BT_ACL_CONT, false);
|
return send_frag(conn, buf, BT_ACL_CONT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void conn_tx_fiber(int arg1, int arg2)
|
static void conn_tx_thread(void *p1, void *p2, void *p3)
|
||||||
{
|
{
|
||||||
struct bt_conn *conn = (struct bt_conn *)arg1;
|
struct bt_conn *conn = p1;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
|
||||||
BT_DBG("Started for handle %u", conn->handle);
|
BT_DBG("Started for handle %u", conn->handle);
|
||||||
|
@ -1060,11 +1060,12 @@ struct bt_conn *bt_conn_add_le(const bt_addr_le_t *peer)
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timeout_fiber(int arg1, int arg2)
|
static void timeout_thread(void *p1, void *p2, void *p3)
|
||||||
{
|
{
|
||||||
struct bt_conn *conn = (struct bt_conn *)arg1;
|
struct bt_conn *conn = p1;
|
||||||
|
|
||||||
ARG_UNUSED(arg2);
|
ARG_UNUSED(p2);
|
||||||
|
ARG_UNUSED(p3);
|
||||||
|
|
||||||
conn->timeout = NULL;
|
conn->timeout = NULL;
|
||||||
|
|
||||||
|
@ -1097,7 +1098,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
break;
|
break;
|
||||||
case BT_CONN_CONNECT:
|
case BT_CONN_CONNECT:
|
||||||
if (conn->timeout) {
|
if (conn->timeout) {
|
||||||
fiber_delayed_start_cancel(conn->timeout);
|
k_thread_cancel(conn->timeout);
|
||||||
conn->timeout = NULL;
|
conn->timeout = NULL;
|
||||||
|
|
||||||
/* Drop the reference taken by timeout fiber */
|
/* Drop the reference taken by timeout fiber */
|
||||||
|
@ -1112,8 +1113,9 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
switch (conn->state) {
|
switch (conn->state) {
|
||||||
case BT_CONN_CONNECTED:
|
case BT_CONN_CONNECTED:
|
||||||
k_fifo_init(&conn->tx_queue);
|
k_fifo_init(&conn->tx_queue);
|
||||||
fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber,
|
k_thread_spawn(conn->stack, sizeof(conn->stack), conn_tx_thread,
|
||||||
(int)bt_conn_ref(conn), 0, 7, 0);
|
bt_conn_ref(conn), NULL, NULL, K_PRIO_COOP(7),
|
||||||
|
0, K_NO_WAIT);
|
||||||
|
|
||||||
bt_l2cap_connected(conn);
|
bt_l2cap_connected(conn);
|
||||||
notify_connected(conn);
|
notify_connected(conn);
|
||||||
|
@ -1165,11 +1167,10 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add LE Create Connection timeout */
|
/* Add LE Create Connection timeout */
|
||||||
conn->timeout = fiber_delayed_start(conn->stack,
|
conn->timeout = k_thread_spawn(conn->stack, sizeof(conn->stack),
|
||||||
sizeof(conn->stack),
|
timeout_thread,
|
||||||
timeout_fiber,
|
bt_conn_ref(conn), NULL, NULL,
|
||||||
(int)bt_conn_ref(conn),
|
K_PRIO_COOP(7), 0, CONN_TIMEOUT);
|
||||||
0, 7, 0, CONN_TIMEOUT);
|
|
||||||
break;
|
break;
|
||||||
case BT_CONN_DISCONNECT:
|
case BT_CONN_DISCONNECT:
|
||||||
break;
|
break;
|
||||||
|
@ -1345,7 +1346,7 @@ static int bt_hci_disconnect(struct bt_conn *conn, uint8_t reason)
|
||||||
static int bt_hci_connect_le_cancel(struct bt_conn *conn)
|
static int bt_hci_connect_le_cancel(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
if (conn->timeout) {
|
if (conn->timeout) {
|
||||||
fiber_delayed_start_cancel(conn->timeout);
|
k_thread_cancel(conn->timeout);
|
||||||
conn->timeout = NULL;
|
conn->timeout = NULL;
|
||||||
|
|
||||||
/* Drop the reference took by timeout fiber */
|
/* Drop the reference took by timeout fiber */
|
||||||
|
|
|
@ -106,8 +106,8 @@ struct bt_conn {
|
||||||
|
|
||||||
bt_conn_state_t state;
|
bt_conn_state_t state;
|
||||||
|
|
||||||
/* Handle allowing to cancel timeout fiber */
|
/* Handle allowing to cancel timeout thread */
|
||||||
nano_thread_id_t timeout;
|
k_tid_t timeout;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct bt_conn_le le;
|
struct bt_conn_le le;
|
||||||
|
|
|
@ -57,9 +57,9 @@
|
||||||
#define CONN_UPDATE_TIMEOUT (5 * MSEC_PER_SEC)
|
#define CONN_UPDATE_TIMEOUT (5 * MSEC_PER_SEC)
|
||||||
#define RPA_TIMEOUT (CONFIG_BLUETOOTH_RPA_TIMEOUT * MSEC_PER_SEC)
|
#define RPA_TIMEOUT (CONFIG_BLUETOOTH_RPA_TIMEOUT * MSEC_PER_SEC)
|
||||||
|
|
||||||
/* Stacks for the fibers */
|
/* Stacks for the threads */
|
||||||
static BT_STACK_NOINIT(rx_fiber_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);
|
static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE);
|
||||||
static BT_STACK_NOINIT(cmd_tx_fiber_stack, 256);
|
static BT_STACK_NOINIT(cmd_tx_thread_stack, 256);
|
||||||
|
|
||||||
struct bt_dev bt_dev;
|
struct bt_dev bt_dev;
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ static NET_BUF_POOL(hci_evt_pool, CONFIG_BLUETOOTH_HCI_EVT_COUNT,
|
||||||
* This priority pool is to handle HCI events that must not be dropped
|
* This priority pool is to handle HCI events that must not be dropped
|
||||||
* (currently this is Command Status, Command Complete and Number of
|
* (currently this is Command Status, Command Complete and Number of
|
||||||
* Complete Packets) if running low on buffers. Buffers from this pool are not
|
* 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().
|
* allowed to be passed to RX thread and must be returned from bt_recv().
|
||||||
*/
|
*/
|
||||||
static struct k_fifo avail_prio_hci_evt;
|
static struct k_fifo avail_prio_hci_evt;
|
||||||
static NET_BUF_POOL(hci_evt_prio_pool, 1,
|
static NET_BUF_POOL(hci_evt_prio_pool, 1,
|
||||||
|
@ -598,9 +598,9 @@ static void hci_disconn_complete(struct net_buf *buf)
|
||||||
conn->err = evt->reason;
|
conn->err = evt->reason;
|
||||||
|
|
||||||
/* Check stacks usage (no-ops if not enabled) */
|
/* Check stacks usage (no-ops if not enabled) */
|
||||||
stack_analyze("rx stack", rx_fiber_stack, sizeof(rx_fiber_stack));
|
stack_analyze("rx stack", rx_thread_stack, sizeof(rx_thread_stack));
|
||||||
stack_analyze("cmd tx stack", cmd_tx_fiber_stack,
|
stack_analyze("cmd tx stack", cmd_tx_thread_stack,
|
||||||
sizeof(cmd_tx_fiber_stack));
|
sizeof(cmd_tx_thread_stack));
|
||||||
stack_analyze("conn tx stack", conn->stack, sizeof(conn->stack));
|
stack_analyze("conn tx stack", conn->stack, sizeof(conn->stack));
|
||||||
|
|
||||||
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
|
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
|
||||||
|
@ -2714,7 +2714,7 @@ static void hci_event(struct net_buf *buf)
|
||||||
net_buf_unref(buf);
|
net_buf_unref(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_cmd_tx_fiber(void)
|
static void hci_cmd_tx_thread(void)
|
||||||
{
|
{
|
||||||
BT_DBG("started");
|
BT_DBG("started");
|
||||||
|
|
||||||
|
@ -3581,7 +3581,7 @@ static int bt_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_rx_fiber(bt_ready_cb_t ready_cb)
|
static void hci_rx_thread(bt_ready_cb_t ready_cb)
|
||||||
{
|
{
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
|
||||||
|
@ -3652,15 +3652,17 @@ int bt_enable(bt_ready_cb_t cb)
|
||||||
k_sem_give(&bt_dev.ncmd_sem);
|
k_sem_give(&bt_dev.ncmd_sem);
|
||||||
#endif /* !CONFIG_BLUETOOTH_WAIT_NOP */
|
#endif /* !CONFIG_BLUETOOTH_WAIT_NOP */
|
||||||
|
|
||||||
/* TX fiber */
|
/* TX thread */
|
||||||
k_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),
|
k_thread_spawn(cmd_tx_thread_stack, sizeof(cmd_tx_thread_stack),
|
||||||
(nano_fiber_entry_t)hci_cmd_tx_fiber, 0, 0, 7, 0);
|
(k_thread_entry_t)hci_cmd_tx_thread, NULL, NULL, NULL,
|
||||||
|
K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||||
|
|
||||||
/* RX fiber */
|
/* RX thread */
|
||||||
k_fifo_init(&bt_dev.rx_queue);
|
k_fifo_init(&bt_dev.rx_queue);
|
||||||
fiber_start(rx_fiber_stack, sizeof(rx_fiber_stack),
|
k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack),
|
||||||
(nano_fiber_entry_t)hci_rx_fiber, (int)cb, 0, 7, 0);
|
(k_thread_entry_t)hci_rx_thread, cb, NULL, NULL,
|
||||||
|
K_PRIO_COOP(7), 0, K_NO_WAIT);
|
||||||
|
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
return bt_init();
|
return bt_init();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue