Skip to content

Commit

Permalink
Applications: nrf5340_audio: Ctlr poll in separate work q
Browse files Browse the repository at this point in the history
OCT-2917
Now performing hci_sync call in separate work q
to avoid blocking system work q

Signed-off-by: Kristoffer Rist Skøien <[email protected]>
  • Loading branch information
koffes authored and rlubos committed Feb 22, 2024
1 parent c6461ed commit eef7486
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
11 changes: 11 additions & 0 deletions applications/nrf5340_audio/src/bluetooth/bt_management/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ config BLE_ADV_TX_POWER_DBM

endmenu # Power control

menu "Thread priorities"

config CTLR_POLL_WORK_Q_PRIO
int "Work queue priority for controller poll"
default 6
help
This is a preemptible work queue.
This work queue will poll the controller to check it is alive.

endmenu # Thread priorities

rsource "dfu/Kconfig"
rsource "advertising/Kconfig"
rsource "scanning/Kconfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ LOG_MODULE_REGISTER(bt_mgmt_ctlr_cfg, CONFIG_BT_MGMT_CTLR_CFG_LOG_LEVEL);
#define COMPANY_ID_NORDIC 0x0059
#define COMPANY_ID_PACKETCRAFT 0x07E8

#define WDT_TIMEOUT_MS 1200
#define CTLR_POLL_INTERVAL_MS (WDT_TIMEOUT_MS - 200)
#define WDT_TIMEOUT_MS 1500
#define CTLR_POLL_INTERVAL_MS (WDT_TIMEOUT_MS - 500)

static struct k_work work_ctlr_poll;

#define CTLR_POLL_WORK_STACK_SIZE 1024

K_THREAD_STACK_DEFINE(ctlr_poll_stack_area, CTLR_POLL_WORK_STACK_SIZE);

struct k_work_q ctrl_poll_work_q;

struct k_work_queue_config ctrl_poll_work_q_config = {
.name = "ctlr_poll",
.no_yield = false,
};

static void ctlr_poll_timer_handler(struct k_timer *timer_id);
static int wdt_ch_id;

Expand Down Expand Up @@ -139,12 +151,17 @@ static void work_ctlr_poll_handler(struct k_work *work)

static void ctlr_poll_timer_handler(struct k_timer *timer_id)
{
k_work_submit(&work_ctlr_poll);
int ret;

ret = k_work_submit_to_queue(&ctrl_poll_work_q, &work_ctlr_poll);
if (ret < 0) {
LOG_ERR("Work q submit failed: %d", ret);
}
}

static void wdt_timeout_cb(int channel_id, void *user_data)
{
ERR_CHK_MSG(-ETIMEDOUT, "Controller not responsive");
ERR_CHK_MSG(-ETIMEDOUT, "No response from IPC or controller");
}

int bt_mgmt_ctlr_cfg_manufacturer_get(bool print_version, uint16_t *manufacturer)
Expand Down Expand Up @@ -216,6 +233,12 @@ int bt_mgmt_ctlr_cfg_init(bool watchdog_enable)
if (wdt_ch_id < 0) {
return wdt_ch_id;
}
k_work_queue_init(&ctrl_poll_work_q);

k_work_queue_start(&ctrl_poll_work_q, ctlr_poll_stack_area,
K_THREAD_STACK_SIZEOF(ctlr_poll_stack_area),
K_PRIO_PREEMPT(CONFIG_CTLR_POLL_WORK_Q_PRIO),
&ctrl_poll_work_q_config);

k_work_init(&work_ctlr_poll, work_ctlr_poll_handler);
k_timer_start(&ctlr_poll_timer, K_MSEC(CTLR_POLL_INTERVAL_MS),
Expand Down

0 comments on commit eef7486

Please sign in to comment.