diff --git a/drivers/bluetooth/hci/h4.c b/drivers/bluetooth/hci/h4.c index 859858e5bf1..3d782c93b6f 100644 --- a/drivers/bluetooth/hci/h4.c +++ b/drivers/bluetooth/hci/h4.c @@ -37,6 +37,7 @@ #define H4_EVT 0x04 static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE); +static struct k_thread rx_thread_data; static struct { struct net_buf *buf; @@ -437,8 +438,9 @@ static int h4_open(void) uart_irq_callback_set(h4_dev, bt_uart_isr); - k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack), rx_thread, - NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&rx_thread_data, rx_thread_stack, + sizeof(rx_thread_stack), rx_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); return 0; } diff --git a/drivers/bluetooth/hci/h5.c b/drivers/bluetooth/hci/h5.c index 4b8ee250045..90f9a3ca0be 100644 --- a/drivers/bluetooth/hci/h5.c +++ b/drivers/bluetooth/hci/h5.c @@ -31,6 +31,9 @@ static BT_STACK_NOINIT(tx_stack, 256); static BT_STACK_NOINIT(rx_stack, 256); +static struct k_thread tx_thread_data; +static struct k_thread rx_thread_data; + static struct k_delayed_work ack_work; static struct k_delayed_work retx_work; @@ -713,12 +716,14 @@ static void h5_init(void) /* TX thread */ k_fifo_init(&h5.tx_queue); - k_thread_spawn(tx_stack, sizeof(tx_stack), (k_thread_entry_t)tx_thread, - NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&tx_thread_data, tx_stack, sizeof(tx_stack), + (k_thread_entry_t)tx_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); k_fifo_init(&h5.rx_queue); - k_thread_spawn(rx_stack, sizeof(rx_stack), (k_thread_entry_t)rx_thread, - NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&rx_thread_data, rx_stack, sizeof(rx_stack), + (k_thread_entry_t)rx_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); /* Unack queue */ k_fifo_init(&h5.unack_queue); diff --git a/drivers/bluetooth/hci/spi.c b/drivers/bluetooth/hci/spi.c index 85e43e768f5..e828406418a 100644 --- a/drivers/bluetooth/hci/spi.c +++ b/drivers/bluetooth/hci/spi.c @@ -74,6 +74,7 @@ static K_SEM_DEFINE(sem_request, 0, 1); static K_SEM_DEFINE(sem_busy, 1, 1); static BT_STACK_NOINIT(rx_stack, 448); +static struct k_thread rx_thread_data; static struct spi_config spi_conf = { .config = SPI_WORD(8), @@ -323,9 +324,9 @@ static int bt_spi_open(void) } /* Start RX thread */ - k_thread_spawn(rx_stack, sizeof(rx_stack), - (k_thread_entry_t)bt_spi_rx_thread, - NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&rx_thread_data, rx_stack, sizeof(rx_stack), + (k_thread_entry_t)bt_spi_rx_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); /* Take BLE out of reset */ gpio_pin_write(rst_dev, GPIO_RESET_PIN, 1); diff --git a/drivers/bluetooth/nble/uart.c b/drivers/bluetooth/nble/uart.c index de2e7c9ab8e..2dea88c0557 100644 --- a/drivers/bluetooth/nble/uart.c +++ b/drivers/bluetooth/nble/uart.c @@ -48,6 +48,8 @@ NET_BUF_POOL_DEFINE(tx_pool, NBLE_TX_BUF_COUNT, NBLE_BUF_SIZE, 0, NULL); static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE); +static struct k_thread rx_thread_data; + static struct device *nble_dev; static K_FIFO_DEFINE(rx_queue); @@ -204,9 +206,9 @@ int nble_open(void) BT_DBG(""); /* Initialize receive queue and start rx_thread */ - 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); + k_thread_create(&rx_thread_data, rx_thread_stack, + sizeof(rx_thread_stack), (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_tx_disable(nble_dev); diff --git a/include/bluetooth/log.h b/include/bluetooth/log.h index 9a037e2feb0..3aeb4b24eb7 100644 --- a/include/bluetooth/log.h +++ b/include/bluetooth/log.h @@ -89,11 +89,9 @@ static inline __printf_like(1, 2) void _bt_log_dummy(const char *fmt, ...) {}; } #define BT_STACK(name, size) \ - char __stack name[(size) + K_THREAD_SIZEOF + \ - BT_STACK_DEBUG_EXTRA] + char __stack name[(size) + BT_STACK_DEBUG_EXTRA] #define BT_STACK_NOINIT(name, size) \ - char __noinit __stack name[(size) + K_THREAD_SIZEOF + \ - BT_STACK_DEBUG_EXTRA] + char __noinit __stack name[(size) + BT_STACK_DEBUG_EXTRA] /* This helper is only available when BLUETOOTH_DEBUG is enabled */ const char *bt_hex(const void *buf, size_t len); diff --git a/include/bluetooth/rfcomm.h b/include/bluetooth/rfcomm.h index 20591a6fa28..aa0d84aa6c1 100644 --- a/include/bluetooth/rfcomm.h +++ b/include/bluetooth/rfcomm.h @@ -95,7 +95,8 @@ struct bt_rfcomm_dlc { u8_t state; u8_t rx_credit; - /* Stack for TX fiber */ + /* Stack & kernel data for TX thread */ + struct k_thread tx_thread; BT_STACK(stack, 256); }; diff --git a/subsys/bluetooth/controller/hci/hci_driver.c b/subsys/bluetooth/controller/hci/hci_driver.c index 0afb1994ae3..3a24029c404 100644 --- a/subsys/bluetooth/controller/hci/hci_driver.c +++ b/subsys/bluetooth/controller/hci/hci_driver.c @@ -46,8 +46,10 @@ static K_SEM_DEFINE(sem_prio_recv, 0, UINT_MAX); static K_FIFO_DEFINE(recv_fifo); +struct k_thread prio_recv_thread_data; static BT_STACK_NOINIT(prio_recv_thread_stack, CONFIG_BLUETOOTH_CONTROLLER_RX_PRIO_STACK_SIZE); +struct k_thread recv_thread_data; static BT_STACK_NOINIT(recv_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE); #if defined(CONFIG_INIT_STACKS) @@ -399,13 +401,13 @@ static int hci_driver_open(void) hci_init(NULL); #endif - k_thread_spawn(prio_recv_thread_stack, sizeof(prio_recv_thread_stack), - prio_recv_thread, NULL, NULL, NULL, K_PRIO_COOP(6), 0, - K_NO_WAIT); + k_thread_create(&prio_recv_thread_data, prio_recv_thread_stack, + sizeof(prio_recv_thread_stack), prio_recv_thread, + NULL, NULL, NULL, K_PRIO_COOP(6), 0, K_NO_WAIT); - k_thread_spawn(recv_thread_stack, sizeof(recv_thread_stack), - recv_thread, NULL, NULL, NULL, K_PRIO_COOP(7), 0, - K_NO_WAIT); + k_thread_create(&recv_thread_data, recv_thread_stack, + sizeof(recv_thread_stack), recv_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); BT_DBG("Success."); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 30823c6c67b..8d20b90094f 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -50,8 +50,10 @@ /* Stacks for the threads */ #if !defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD) +static struct k_thread rx_thread_data; static BT_STACK_NOINIT(rx_thread_stack, CONFIG_BLUETOOTH_RX_STACK_SIZE); #endif +static struct k_thread tx_thread_data; static BT_STACK_NOINIT(tx_thread_stack, CONFIG_BLUETOOTH_HCI_TX_STACK_SIZE); static void init_work(struct k_work *work); @@ -3944,15 +3946,16 @@ int bt_enable(bt_ready_cb_t cb) ready_cb = cb; /* TX thread */ - k_thread_spawn(tx_thread_stack, sizeof(tx_thread_stack), - hci_tx_thread, NULL, NULL, NULL, K_PRIO_COOP(7), 0, - K_NO_WAIT); + k_thread_create(&tx_thread_data, tx_thread_stack, + sizeof(tx_thread_stack), hci_tx_thread, NULL, NULL, + NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); #if !defined(CONFIG_BLUETOOTH_RECV_IS_RX_THREAD) /* RX thread */ - k_thread_spawn(rx_thread_stack, sizeof(rx_thread_stack), - (k_thread_entry_t)hci_rx_thread, NULL, NULL, NULL, - K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&rx_thread_data, rx_thread_stack, + sizeof(rx_thread_stack), + (k_thread_entry_t)hci_rx_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, K_NO_WAIT); #endif if (IS_ENABLED(CONFIG_BLUETOOTH_TINYCRYPT_ECC)) { diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index 0a80b65ab45..58b6b1b7900 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -33,6 +33,7 @@ #include "hci_core.h" #endif +static struct k_thread ecc_thread_data; static BT_STACK_NOINIT(ecc_thread_stack, 1060); /* based on Core Specification 4.2 Vol 3. Part H 2.3.5.6.1 */ @@ -307,7 +308,7 @@ int bt_hci_ecc_send(struct net_buf *buf) void bt_hci_ecc_init(void) { - k_thread_spawn(ecc_thread_stack, sizeof(ecc_thread_stack), - ecc_thread, NULL, NULL, NULL, - K_PRIO_PREEMPT(10), 0, K_NO_WAIT); + k_thread_create(&ecc_thread_data, ecc_thread_stack, + sizeof(ecc_thread_stack), ecc_thread, NULL, NULL, NULL, + K_PRIO_PREEMPT(10), 0, K_NO_WAIT); } diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c index 722c50301d8..f46e217cb37 100644 --- a/subsys/bluetooth/host/rfcomm.c +++ b/subsys/bluetooth/host/rfcomm.c @@ -750,8 +750,9 @@ static void rfcomm_dlc_connected(struct bt_rfcomm_dlc *dlc) k_delayed_work_cancel(&dlc->rtx_work); k_fifo_init(&dlc->tx_queue); - k_thread_spawn(dlc->stack, sizeof(dlc->stack), rfcomm_dlc_tx_thread, - dlc, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + k_thread_create(&dlc->tx_thread, dlc->stack, sizeof(dlc->stack), + rfcomm_dlc_tx_thread, dlc, NULL, NULL, K_PRIO_COOP(7), + 0, K_NO_WAIT); if (dlc->ops && dlc->ops->connected) { dlc->ops->connected(dlc);