diff --git a/samples/bluetooth/central_hr/prj_minimal.conf b/samples/bluetooth/central_hr/prj_minimal.conf index 3ea96d693c718..6c8e130c3ae2b 100644 --- a/samples/bluetooth/central_hr/prj_minimal.conf +++ b/samples/bluetooth/central_hr/prj_minimal.conf @@ -47,29 +47,29 @@ CONFIG_ARM_MPU=n # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y # CONFIG_THREAD_ANALYZER_USE_PRINTK=y # CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=20 -# CONFIG_CONSOLE=y -# CONFIG_UART_CONSOLE=y -# CONFIG_SERIAL=y -# CONFIG_PRINTK=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_PRINTK=y # Example output of thread analyzer -# BT RX : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -# BT RX pri : STACK: unused 260 usage 188 / 448 (41 %); CPU: 0 % -# BT ECC : STACK: unused 256 usage 888 / 1144 (77 %); CPU: 1 % -# BT TX : STACK: unused 296 usage 344 / 640 (53 %); CPU: 0 % -# thread_analyzer : STACK: unused 128 usage 384 / 512 (75 %); CPU: 1 % -# sysworkq : STACK: unused 856 usage 168 / 1024 (16 %); CPU: 0 % -# logging : STACK: unused 232 usage 536 / 768 (69 %); CPU: 0 % -# idle 00 : STACK: unused 208 usage 48 / 256 (18 %); CPU: 97 % -# main : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % +# BT CTLR RX : STACK: unused 16 usage 288 / 304 (94 %); CPU: 0 % +# BT CTLR RX pri : STACK: unused 24 usage 344 / 368 (93 %); CPU: 0 % +# BT WQ : STACK: unused 48 usage 976 / 1024 (95 %); CPU: 1 % +# thread_analyzer : STACK: unused 464 usage 560 / 1024 (54 %); CPU: 0 % +# BT LW WQ : STACK: unused 24 usage 1080 / 1104 (97 %); CPU: 19 % +# sysworkq : STACK: unused 96 usage 504 / 600 (84 %); CPU: 0 % +# idle : STACK: unused 40 usage 88 / 128 (68 %); CPU: 78 % +# main : STACK: unused 168 usage 432 / 600 (72 %); CPU: 0 % +# ISR0 : STACK: unused 200 usage 600 / 800 (75 %) CONFIG_BT_RX_STACK_SIZE=1024 CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y CONFIG_BT_HCI_TX_STACK_SIZE=640 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1100 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=600 CONFIG_BT_LONG_WQ_STACK_SIZE=1100 CONFIG_IDLE_STACK_SIZE=128 -CONFIG_MAIN_STACK_SIZE=640 -CONFIG_ISR_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=600 +CONFIG_ISR_STACK_SIZE=700 # Disable features not needed CONFIG_TIMESLICING=n diff --git a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf index 4874ce5676064..6bbfb3875c9f6 100644 --- a/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf +++ b/samples/bluetooth/mesh_demo/boards/bbc_microbit.conf @@ -1,17 +1,20 @@ -CONFIG_ISR_STACK_SIZE=768 +CONFIG_ISR_STACK_SIZE=700 CONFIG_MAIN_STACK_SIZE=512 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1200 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=256 CONFIG_GPIO=y CONFIG_DISPLAY=y CONFIG_MICROBIT_DISPLAY=y CONFIG_PWM=y -CONFIG_BT_RX_STACK_SIZE=1280 +CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=1 +CONFIG_BT_MESH_ADV_STACK_SIZE=200 + +CONFIG_BT_RX_STACK_SIZE=2000 CONFIG_BT_CTLR_DUP_FILTER_LEN=0 CONFIG_BT_PHY_UPDATE=n CONFIG_BT_DATA_LEN_UPDATE=n CONFIG_BT_EXT_ADV=n -CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=15 +CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT=1 CONFIG_BT_MESH_SEG_BUFS=6 CONFIG_BT_MESH_ADV_BUF_COUNT=3 diff --git a/samples/bluetooth/mesh_demo/src/microbit.c b/samples/bluetooth/mesh_demo/src/microbit.c index 38568d26c5a23..fd42dd20d4a78 100644 --- a/samples/bluetooth/mesh_demo/src/microbit.c +++ b/samples/bluetooth/mesh_demo/src/microbit.c @@ -20,21 +20,14 @@ #define SCROLL_SPEED 300 -#define BUZZER_PWM_CHANNEL 0 -#define BEEP_DURATION K_MSEC(60) - #define SEQ_PER_BIT 976 #define SEQ_PAGE (NRF_FICR->CODEPAGESIZE * (NRF_FICR->CODESIZE - 1)) #define SEQ_MAX (NRF_FICR->CODEPAGESIZE * 8 * SEQ_PER_BIT) static const struct gpio_dt_spec button_a = - GPIO_DT_SPEC_GET(DT_NODELABEL(buttona), gpios); + GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios); static const struct gpio_dt_spec button_b = - GPIO_DT_SPEC_GET(DT_NODELABEL(buttonb), gpios); -static const struct device *const nvm = - DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller)); -static const struct device *const pwm = - DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); + GPIO_DT_SPEC_GET(DT_ALIAS(sw1), gpios); static struct k_work button_work; @@ -64,6 +57,13 @@ static void button_pressed(const struct device *dev, struct gpio_callback *cb, } } +#if defined(CONFIG_PWM) +#define BUZZER_PWM_CHANNEL 0 +#define BEEP_DURATION K_MSEC(60) + +static const struct device *const pwm = + DEVICE_DT_GET_ANY(nordic_nrf_sw_pwm); + static const struct { char note; uint32_t period; @@ -139,6 +139,11 @@ void board_play_tune(const char *str) pwm_set(pwm, BUZZER_PWM_CHANNEL, 0, 0, 0); } } +#else +void board_play_tune(const char *str) +{ +} +#endif /* CONFIG_PWM */ void board_heartbeat(uint8_t hops, uint16_t feat) { @@ -267,13 +272,6 @@ int board_init(uint16_t *addr) { struct mb_display *disp = mb_display_get(); - if (!(device_is_ready(nvm) && device_is_ready(pwm) && - gpio_is_ready_dt(&button_a) && - gpio_is_ready_dt(&button_b))) { - printk("One or more devices are not ready\n"); - return -ENODEV; - } - *addr = NRF_UICR->CUSTOMER[0]; if (!*addr || *addr == 0xffff) { #if defined(NODE_ADDR) diff --git a/samples/bluetooth/peripheral_hr/prj_minimal.conf b/samples/bluetooth/peripheral_hr/prj_minimal.conf index 8f9c2b85cb142..1c8d353638040 100644 --- a/samples/bluetooth/peripheral_hr/prj_minimal.conf +++ b/samples/bluetooth/peripheral_hr/prj_minimal.conf @@ -53,29 +53,28 @@ CONFIG_ARM_MPU=n # CONFIG_THREAD_ANALYZER_RUN_UNLOCKED=y # CONFIG_THREAD_ANALYZER_USE_PRINTK=y # CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=20 -# CONFIG_CONSOLE=y -# CONFIG_UART_CONSOLE=y -# CONFIG_SERIAL=y -# CONFIG_PRINTK=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_PRINTK=y # Example output of thread analyzer -# BT RX : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -# BT RX pri : STACK: unused 260 usage 188 / 448 (41 %); CPU: 0 % -# BT ECC : STACK: unused 256 usage 888 / 1144 (77 %); CPU: 1 % -# BT TX : STACK: unused 296 usage 344 / 640 (53 %); CPU: 0 % -# thread_analyzer : STACK: unused 128 usage 384 / 512 (75 %); CPU: 1 % -# sysworkq : STACK: unused 856 usage 168 / 1024 (16 %); CPU: 0 % -# logging : STACK: unused 232 usage 536 / 768 (69 %); CPU: 0 % -# idle 00 : STACK: unused 208 usage 48 / 256 (18 %); CPU: 97 % -# main : STACK: unused 576 usage 448 / 1024 (43 %); CPU: 0 % -CONFIG_BT_RX_STACK_SIZE=1024 +# BT CTLR RX : STACK: unused 32 usage 288 / 320 (90 %); CPU: 0 % +# BT CTLR RX pri : STACK: unused 32 usage 344 / 376 (91 %); CPU: 0 % +# BT WQ : STACK: unused 32 usage 944 / 976 (96 %); CPU: 0 % +# BT LW WQ : STACK: unused 8 usage 1096 / 1104 (99 %); CPU: 8 % +# sysworkq : STACK: unused 40 usage 360 / 400 (90 %); CPU: 0 % +# idle : STACK: unused 40 usage 88 / 128 (68 %); CPU: 90 % +# main : STACK: unused 72 usage 608 / 680 (89 %); CPU: 0 % +# ISR0 : STACK: unused 104 usage 600 / 704 (85 %) +CONFIG_BT_RX_STACK_SIZE=976 CONFIG_BT_HCI_TX_STACK_SIZE_WITH_PROMPT=y CONFIG_BT_HCI_TX_STACK_SIZE=640 -CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=1100 -CONFIG_BT_LONG_WQ_STACK_SIZE=1100 +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=400 CONFIG_IDLE_STACK_SIZE=128 -CONFIG_MAIN_STACK_SIZE=640 -CONFIG_ISR_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=680 +CONFIG_ISR_STACK_SIZE=700 +CONFIG_BT_LONG_WQ_STACK_SIZE=1120 # Disable features not needed CONFIG_TIMESLICING=n diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index de2716918f483..b3a8a350672f9 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -127,6 +127,7 @@ config BT_CTLR_RX_PRIO_STACK_SIZE # Hidden int depends on !BT_HCI_RAW + default 376 if SOC_SERIES_NRF51X && !BT_EXT_ADV default 448 help Controller's Co-Operative high priority Rx thread stack size. @@ -141,6 +142,7 @@ config BT_CTLR_RX_PRIO_STACK_SIZE config BT_CTLR_RX_STACK_SIZE # Hidden, Controller's Co-Operative Rx thread stack size. int + default 320 if SOC_SERIES_NRF51X && !BT_EXT_ADV default 896 config BT_CTLR_SETTINGS diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 7611761bb4537..68a6f597406c0 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -76,7 +76,6 @@ config BT_HCI_TX_PRIO choice BT_RECV_CONTEXT prompt "BT RX Thread Selection" - default BT_RECV_WORKQ_SYS if SOC_SERIES_NRF51X default BT_RECV_WORKQ_BT help Selects in which context incoming low priority HCI packets are processed. @@ -86,7 +85,8 @@ choice BT_RECV_CONTEXT packets are processed. config BT_RECV_WORKQ_SYS - bool "Process low priority HCI packets in the system work queue" + bool "Process low priority HCI packets in the system work queue [DEPRECATED]" + select DEPRECATED help When this option is selected, the host will process incoming low priority HCI packets in the system work queue. @@ -128,6 +128,20 @@ config BT_RX_PRIO int default 8 +config BT_WQ + bool + default y if BT_RECV_WORKQ_BT + +if BT_WQ +config BT_WQ_STACK_SIZE + int + default BT_RX_STACK_SIZE + +config BT_WQ_PRIO + int + default BT_RX_PRIO +endif + config BT_DRIVER_RX_HIGH_PRIO # Hidden option for Co-Operative HCI driver RX thread priority int diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 78f3de1be653d..9ebf7db4ca260 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -1431,8 +1431,8 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, if (ad_is_limited(ad, ad_len)) { k_work_init_delayable(&adv->lim_adv_timeout_work, adv_timeout); - k_work_reschedule(&adv->lim_adv_timeout_work, - K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT)); + bt_work_reschedule(&adv->lim_adv_timeout_work, + K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT)); } return err; diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 98b310f4b4b08..0a75a8fef5d7a 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -630,7 +630,7 @@ static void chan_rebegin_att_timeout(struct bt_att_tx_meta_data *user_data) * in-flight. */ if (chan->req) { - k_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT); + bt_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT); } } @@ -3579,8 +3579,8 @@ static int att_schedule_eatt_connect(struct bt_conn *conn, uint8_t chans_to_conn att->eatt.chans_to_connect = chans_to_connect; - return k_work_reschedule(&att->eatt.connection_work, - credit_based_connection_delay(conn)); + return bt_work_reschedule(&att->eatt.connection_work, + credit_based_connection_delay(conn)); } static void handle_potential_collision(struct bt_att *att) diff --git a/subsys/bluetooth/host/classic/br.c b/subsys/bluetooth/host/classic/br.c index 994fcfbd22c77..85619ff1361c9 100644 --- a/subsys/bluetooth/host/classic/br.c +++ b/subsys/bluetooth/host/classic/br.c @@ -1218,8 +1218,8 @@ int bt_br_set_discoverable(bool enable, bool limited) err = write_scan_enable(BT_BREDR_SCAN_INQUIRY | BT_BREDR_SCAN_PAGE); if (!err && (limited == true)) { atomic_set_bit(bt_dev.flags, BT_DEV_LIMITED_DISCOVERABLE_MODE); - k_work_reschedule(&bt_br_limited_discoverable_timeout, - K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION)); + bt_work_reschedule(&bt_br_limited_discoverable_timeout, + K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION)); } return err; } diff --git a/subsys/bluetooth/host/classic/l2cap_br.c b/subsys/bluetooth/host/classic/l2cap_br.c index edea5c15c5ad3..9db42188ac326 100644 --- a/subsys/bluetooth/host/classic/l2cap_br.c +++ b/subsys/bluetooth/host/classic/l2cap_br.c @@ -438,29 +438,29 @@ static void l2cap_br_start_timer(struct bt_l2cap_br_chan *br_chan, enum l2cap_br if (type == BT_L2CAP_BR_TIMER_RET) { if (!atomic_test_and_set_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { k_work_cancel_delayable(&br_chan->monitor_work); - k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); LOG_DBG("Start ret timer"); } else { if (!restart) { return; } - k_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); LOG_DBG("Restart ret timer"); } } else { if (atomic_test_and_clear_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { k_work_cancel_delayable(&br_chan->ret_work); - k_work_schedule(&br_chan->monitor_work, - K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_schedule(&br_chan->monitor_work, + K_MSEC(br_chan->tx.monitor_timeout)); LOG_DBG("Start monitor timer"); } else { if (!restart) { return; } - k_work_reschedule(&br_chan->monitor_work, - K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_reschedule(&br_chan->monitor_work, + K_MSEC(br_chan->tx.monitor_timeout)); LOG_DBG("Restart monitor timer"); } } @@ -736,7 +736,7 @@ static void l2cap_br_ret_timeout(struct k_work *work) /* Restart the timer */ if (atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { - k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); + bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout)); } LOG_DBG("chan %p retransmission timeout", br_chan); @@ -805,7 +805,7 @@ static void l2cap_br_monitor_timeout(struct k_work *work) /* Restart the timer */ if (!atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) { - k_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout)); + bt_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout)); } LOG_DBG("chan %p monitor timeout", br_chan); @@ -962,7 +962,7 @@ static void l2cap_br_chan_send_req(struct bt_l2cap_br_chan *chan, * final expiration, when the response is received, or the physical * link is lost. */ - k_work_reschedule(&chan->rtx_work, timeout); + bt_work_reschedule(&chan->rtx_work, timeout); } #if defined(CONFIG_BT_L2CAP_RET_FC) @@ -4805,7 +4805,7 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident, struct n break; case BT_L2CAP_BR_PENDING: br_chan->ident = ident; - k_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT); + bt_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT); break; default: l2cap_br_chan_cleanup(chan); diff --git a/subsys/bluetooth/host/classic/rfcomm.c b/subsys/bluetooth/host/classic/rfcomm.c index cedf7f7a69c7a..5064f6520cefb 100644 --- a/subsys/bluetooth/host/classic/rfcomm.c +++ b/subsys/bluetooth/host/classic/rfcomm.c @@ -394,7 +394,7 @@ static void rfcomm_session_disconnect(struct bt_rfcomm_session *session) session->state = BT_RFCOMM_STATE_DISCONNECTING; rfcomm_send_disc(session, 0); - k_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT); } static struct net_buf *rfcomm_make_uih_msg(struct bt_rfcomm_session *session, @@ -475,7 +475,7 @@ static void rfcomm_dlc_init(struct bt_rfcomm_dlc *dlc, k_work_init_delayable(&dlc->rtx_work, rfcomm_dlc_rtx_timeout); /* Start a conn timer which includes auth as well */ - k_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT); + bt_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT); dlc->_next = session->dlcs; session->dlcs = dlc; @@ -644,7 +644,7 @@ static void rfcomm_dlc_tx_thread(void *p1, void *p2, void *p3) if (dlc->state == BT_RFCOMM_STATE_DISCONNECTING) { rfcomm_send_disc(dlc->session, dlc->dlci); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); } else { rfcomm_dlc_destroy(dlc); } @@ -917,7 +917,7 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc) case BT_RFCOMM_STATE_CONFIG: dlc->state = BT_RFCOMM_STATE_DISCONNECTING; rfcomm_send_disc(dlc->session, dlc->dlci); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); break; case BT_RFCOMM_STATE_CONNECTED: dlc->state = BT_RFCOMM_STATE_DISCONNECTING; @@ -1346,8 +1346,8 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, uint8_t dlci) if (!session->dlcs) { /* Start a session idle timer */ - k_work_reschedule(&dlc->session->rtx_work, - RFCOMM_IDLE_TIMEOUT); + bt_work_reschedule(&dlc->session->rtx_work, + RFCOMM_IDLE_TIMEOUT); } } else { /* Cancel idle timer */ @@ -1805,7 +1805,7 @@ int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc) k_fifo_put(&dlc->tx_queue, net_buf_alloc(&dummy_pool, K_NO_WAIT)); - k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); + bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT); return 0; } diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 9e9f18c040a04..734f4c860ab8f 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1208,8 +1208,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) } #endif /* CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS */ - k_work_schedule(&conn->deferred_work, - CONN_UPDATE_TIMEOUT); + k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT); } #endif /* CONFIG_BT_CONN */ @@ -1801,7 +1800,7 @@ static K_WORK_DEFINE(procedures_on_connect, auto_initiated_procedures); static void schedule_auto_initiated_procedures(struct bt_conn *conn) { LOG_DBG("[%p] Scheduling auto-init procedures", conn); - k_work_submit(&procedures_on_connect); + bt_work_submit(&procedures_on_connect); } void bt_conn_connected(struct bt_conn *conn) diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index be642fec9fe7f..c95294e475c31 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -1306,7 +1306,7 @@ static int gatt_register(struct bt_gatt_service *svc) static inline void sc_work_submit(k_timeout_t timeout) { #if defined(CONFIG_BT_GATT_SERVICE_CHANGED) - k_work_reschedule(&gatt_sc.work, timeout); + bt_work_reschedule(&gatt_sc.work, timeout); #endif } @@ -1468,8 +1468,8 @@ static void gatt_delayed_store_enqueue(uint8_t id, const bt_addr_le_t *peer_addr atomic_set_bit(el->flags, flag); - k_work_reschedule(&gatt_delayed_store.work, - K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); + bt_work_reschedule(&gatt_delayed_store.work, + K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS)); } } @@ -1539,7 +1539,7 @@ void bt_gatt_init(void) if (IS_ENABLED(CONFIG_BT_LONG_WQ)) { bt_long_wq_schedule(&db_hash.work, DB_HASH_TIMEOUT); } else { - k_work_schedule(&db_hash.work, DB_HASH_TIMEOUT); + bt_work_schedule(&db_hash.work, DB_HASH_TIMEOUT); } #endif /* CONFIG_BT_GATT_CACHING */ @@ -1625,7 +1625,7 @@ static void db_changed(void) if (IS_ENABLED(CONFIG_BT_LONG_WQ)) { bt_long_wq_reschedule(&db_hash.work, DB_HASH_TIMEOUT); } else { - k_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT); + bt_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT); } for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) { @@ -2496,8 +2496,8 @@ static int gatt_notify_mult(struct bt_conn *conn, uint16_t handle, /* Use `k_work_schedule` to keep the original deadline, instead of * re-setting the timeout whenever a new notification is appended. */ - k_work_schedule(&nfy_mult_work, - K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS)); + bt_work_schedule(&nfy_mult_work, + K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS)); return 0; } diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 11288fa9972b3..a295da81ca211 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -119,10 +119,29 @@ void bt_tx_irq_raise(void); /* Stacks for the threads */ static void rx_work_handler(struct k_work *work); static K_WORK_DEFINE(rx_work, rx_work_handler); -#if defined(CONFIG_BT_RECV_WORKQ_BT) -static struct k_work_q bt_workq; -static K_KERNEL_STACK_DEFINE(rx_thread_stack, CONFIG_BT_RX_STACK_SIZE); -#endif /* CONFIG_BT_RECV_WORKQ_BT */ + +#if defined(CONFIG_BT_WQ) +static struct k_work_q _bt_wq; +static K_KERNEL_STACK_DEFINE(bt_wq_stack, CONFIG_BT_WQ_STACK_SIZE); +static struct k_work_q * const bt_wq = &_bt_wq; +#else +static struct k_work_q * const bt_wq = &k_sys_work_q; +#endif /* CONFIG_BT_WQ */ + +int bt_work_submit(struct k_work *work) +{ + return k_work_submit_to_queue(bt_wq, work); +} + +int bt_work_schedule(struct k_work_delayable *work, k_timeout_t delay) +{ + return k_work_schedule_for_queue(bt_wq, work, delay); +} + +int bt_work_reschedule(struct k_work_delayable *work, k_timeout_t delay) +{ + return k_work_reschedule_for_queue(bt_wq, work, delay); +} static void init_work(struct k_work *work); @@ -472,10 +491,10 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf, /* TODO: disallow sending sync commands from syswq altogether */ - /* Since the commands are now processed in the syswq, we cannot suspend - * and wait. We have to send the command from the current context. + /* We cannot suspend and wait in the context that commands are processed in. + * We have to send the command from the current context. */ - if (k_current_get() == &k_sys_work_q.thread) { + if (k_current_get() == k_work_queue_thread_get(bt_wq)) { /* drain the command queue until we get to send the command of interest. */ struct net_buf *cmd = NULL; @@ -2029,8 +2048,8 @@ static void le_conn_update_complete(struct net_buf *buf) evt->status == BT_HCI_ERR_UNSUPP_LL_PARAM_VAL && conn->le.conn_param_retry_countdown) { conn->le.conn_param_retry_countdown--; - k_work_schedule(&conn->deferred_work, - K_MSEC(CONFIG_BT_CONN_PARAM_RETRY_TIMEOUT)); + bt_work_schedule(&conn->deferred_work, + K_MSEC(CONFIG_BT_CONN_PARAM_RETRY_TIMEOUT)); } else { atomic_clear_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_AUTO_UPDATE); @@ -4162,11 +4181,7 @@ static void rx_queue_put(struct net_buf *buf) { net_buf_slist_put(&bt_dev.rx_queue, buf); -#if defined(CONFIG_BT_RECV_WORKQ_SYS) - const int err = k_work_submit(&rx_work); -#elif defined(CONFIG_BT_RECV_WORKQ_BT) - const int err = k_work_submit_to_queue(&bt_workq, &rx_work); -#endif /* CONFIG_BT_RECV_WORKQ_SYS */ + const int err = bt_work_submit(&rx_work); if (err < 0) { LOG_ERR("Could not submit rx_work: %d", err); } @@ -4326,12 +4341,7 @@ static void rx_work_handler(struct k_work *work) * we used a while() loop with a k_yield() statement. */ if (!sys_slist_is_empty(&bt_dev.rx_queue)) { - -#if defined(CONFIG_BT_RECV_WORKQ_SYS) - err = k_work_submit(&rx_work); -#elif defined(CONFIG_BT_RECV_WORKQ_BT) - err = k_work_submit_to_queue(&bt_workq, &rx_work); -#endif + err = bt_work_submit(&rx_work); if (err < 0) { LOG_ERR("Could not submit rx_work: %d", err); } @@ -4342,7 +4352,7 @@ static void rx_work_handler(struct k_work *work) k_tid_t bt_testing_tx_tid_get(void) { /* We now TX everything from the syswq */ - return &k_sys_work_q.thread; + return k_work_queue_thread_get(bt_wq); } #if defined(CONFIG_BT_ISO) @@ -4400,13 +4410,11 @@ int bt_enable(bt_ready_cb_t cb) } k_fifo_init(&bt_dev.cmd_tx_queue); -#if defined(CONFIG_BT_RECV_WORKQ_BT) - /* RX thread */ - k_work_queue_init(&bt_workq); - k_work_queue_start(&bt_workq, rx_thread_stack, - CONFIG_BT_RX_STACK_SIZE, - K_PRIO_COOP(CONFIG_BT_RX_PRIO), NULL); - k_thread_name_set(&bt_workq.thread, "BT RX WQ"); +#if defined(CONFIG_BT_WQ) + k_work_queue_init(bt_wq); + k_work_queue_start(bt_wq, bt_wq_stack, CONFIG_BT_WQ_STACK_SIZE, + K_PRIO_COOP(CONFIG_BT_WQ_PRIO), NULL); + k_thread_name_set(k_work_queue_thread_get(bt_wq), "BT WQ"); #endif err = bt_hci_open(bt_dev.hci, bt_hci_recv); @@ -4421,7 +4429,7 @@ int bt_enable(bt_ready_cb_t cb) return bt_init(); } - k_work_submit(&bt_dev.init); + bt_work_submit(&bt_dev.init); return 0; } @@ -4484,9 +4492,9 @@ int bt_disable(void) return err; } -#if defined(CONFIG_BT_RECV_WORKQ_BT) - /* Abort RX thread */ - k_thread_abort(&bt_workq.thread); +#if defined(CONFIG_BT_WQ) + /* Abort Bluetooth thread */ + k_thread_abort(k_work_queue_thread_get(bt_wq)); #endif /* Some functions rely on checking this bitfield */ @@ -4822,5 +4830,5 @@ static K_WORK_DEFINE(tx_work, tx_processor); void bt_tx_irq_raise(void) { LOG_DBG("kick TX"); - k_work_submit(&tx_work); + bt_work_submit(&tx_work); } diff --git a/subsys/bluetooth/host/hci_core.h b/subsys/bluetooth/host/hci_core.h index b6ebdba31a7e4..10b7403cbc7bc 100644 --- a/subsys/bluetooth/host/hci_core.h +++ b/subsys/bluetooth/host/hci_core.h @@ -453,6 +453,10 @@ enum bt_security_err bt_security_err_get(uint8_t hci_err); int bt_hci_recv(const struct device *dev, struct net_buf *buf); +int bt_work_submit(struct k_work *work); +int bt_work_schedule(struct k_work_delayable *work, k_timeout_t delay); +int bt_work_reschedule(struct k_work_delayable *work, k_timeout_t delay); + /* Data type to store state related with command to be updated * when command completes successfully. */ diff --git a/subsys/bluetooth/host/id.c b/subsys/bluetooth/host/id.c index dca77cd0b055e..96703b16740d4 100644 --- a/subsys/bluetooth/host/id.c +++ b/subsys/bluetooth/host/id.c @@ -342,7 +342,7 @@ static void le_rpa_timeout_submit(void) le_rpa_timeout_update(); #endif - (void)k_work_schedule(&bt_dev.rpa_update, K_SECONDS(bt_dev.rpa_timeout)); + (void)bt_work_schedule(&bt_dev.rpa_update, K_SECONDS(bt_dev.rpa_timeout)); } /* this function sets new RPA only if current one is no longer valid */ diff --git a/subsys/bluetooth/host/keys.c b/subsys/bluetooth/host/keys.c index 1205494e856f0..b4901723c14a0 100644 --- a/subsys/bluetooth/host/keys.c +++ b/subsys/bluetooth/host/keys.c @@ -448,7 +448,7 @@ static void id_add(struct bt_keys *keys, void *user_data) __ASSERT_NO_MSG(keys != NULL); bt_id_pending_keys_update_set(keys, BT_KEYS_ID_PENDING_ADD); - k_work_submit(&add_id_work); + bt_work_submit(&add_id_work); } static int keys_commit(void) diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index ac6fc60dbad6a..d951fd039c007 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -515,7 +515,7 @@ static void l2cap_chan_send_req(struct bt_l2cap_chan *chan, * final expiration, when the response is received, or the physical * link is lost. */ - k_work_reschedule(&(BT_L2CAP_LE_CHAN(chan)->rtx_work), timeout); + bt_work_reschedule(&(BT_L2CAP_LE_CHAN(chan)->rtx_work), timeout); } static int l2cap_le_conn_req(struct bt_l2cap_le_chan *ch) @@ -2712,7 +2712,7 @@ static void l2cap_chan_recv_queue(struct bt_l2cap_le_chan *chan, } k_fifo_put(&chan->rx_queue, buf); - k_work_submit(&chan->rx_work); + bt_work_submit(&chan->rx_work); } #endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */ diff --git a/subsys/bluetooth/host/settings.c b/subsys/bluetooth/host/settings.c index 84b4f1eb4b6a8..ada0937841e87 100644 --- a/subsys/bluetooth/host/settings.c +++ b/subsys/bluetooth/host/settings.c @@ -447,7 +447,7 @@ K_WORK_DEFINE(store_id_work, do_store_id); int bt_settings_store_id(void) { - k_work_submit(&store_id_work); + bt_work_submit(&store_id_work); return 0; } @@ -473,7 +473,7 @@ K_WORK_DEFINE(store_irk_work, do_store_irk); int bt_settings_store_irk(void) { #if defined(CONFIG_BT_PRIVACY) - k_work_submit(&store_irk_work); + bt_work_submit(&store_irk_work); #endif /* defined(CONFIG_BT_PRIVACY) */ return 0; } diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 113ed60f12c06..3e69095c108b6 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -1002,7 +1002,7 @@ static void smp_br_send(struct bt_smp_br *smp, struct net_buf *buf, return; } - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); } static void bt_smp_br_connected(struct bt_l2cap_chan *chan) @@ -2046,7 +2046,7 @@ static void smp_send(struct bt_smp *smp, struct net_buf *buf, return; } - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); } static int smp_error(struct bt_smp *smp, uint8_t reason) @@ -4735,7 +4735,7 @@ static uint8_t smp_keypress_notif(struct bt_smp *smp, struct net_buf *buf) } /* Reset SMP timeout, like the spec says. */ - k_work_reschedule(&smp->work, SMP_TIMEOUT); + bt_work_reschedule(&smp->work, SMP_TIMEOUT); if (smp_auth_cb->passkey_display_keypress) { smp_auth_cb->passkey_display_keypress(conn, type);