From 725595c09bc8f3515954d4416123982237413a2b Mon Sep 17 00:00:00 2001 From: Marco Widmer Date: Wed, 11 Jun 2025 13:37:34 +0200 Subject: [PATCH] Bluetooth: Controller: Deinit ticker ticker_is_initialized() should only return true when the ticker is running (triggered regularly). Users like nrf_flash_sync_is_required() depend on this behavior. When the bluetooth controller driver is closed, ll_deinit() calls lll_deinit(), which stops the ticker from being triggered. Also deinitialize the ticker to ensure that ticker_is_initialized() returns false. Signed-off-by: Marco Widmer (cherry picked from commit 09691484eb19a53297dbcffb3a88616b3a706bdb) --- subsys/bluetooth/controller/ll_sw/ull.c | 12 ++++++++++- subsys/bluetooth/controller/ticker/ticker.c | 24 +++++++++++++++++++++ subsys/bluetooth/controller/ticker/ticker.h | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/controller/ll_sw/ull.c b/subsys/bluetooth/controller/ll_sw/ull.c index 41df97a29cbbf..e6cb588c11e0a 100644 --- a/subsys/bluetooth/controller/ll_sw/ull.c +++ b/subsys/bluetooth/controller/ll_sw/ull.c @@ -784,8 +784,18 @@ int ll_init(struct k_sem *sem_rx) int ll_deinit(void) { + int err; + ll_reset(); - return lll_deinit(); + + err = lll_deinit(); + if (err) { + return err; + } + + err = ticker_deinit(TICKER_INSTANCE_ID_CTLR); + + return err; } void ll_reset(void) diff --git a/subsys/bluetooth/controller/ticker/ticker.c b/subsys/bluetooth/controller/ticker/ticker.c index 7806956c630ac..e12088b6e6f32 100644 --- a/subsys/bluetooth/controller/ticker/ticker.c +++ b/subsys/bluetooth/controller/ticker/ticker.c @@ -3464,6 +3464,30 @@ uint8_t ticker_init(uint8_t instance_index, uint8_t count_node, void *node, return TICKER_STATUS_SUCCESS; } +/** + * @brief Deinitialize ticker instance + * + * @param instance_index Index of ticker instance + */ +int ticker_deinit(uint8_t instance_index) +{ + struct ticker_instance *instance; + + if (instance_index >= TICKER_INSTANCE_MAX) { + return -EINVAL; + } + + instance = &_instance[instance_index]; + + if (instance->ticker_id_head != TICKER_NULL) { + return -EBUSY; + } + + instance->count_node = 0U; + + return 0; +} + /** * @brief Check if ticker instance is initialized * diff --git a/subsys/bluetooth/controller/ticker/ticker.h b/subsys/bluetooth/controller/ticker/ticker.h index aa666036ab01c..578ce1c64be64 100644 --- a/subsys/bluetooth/controller/ticker/ticker.h +++ b/subsys/bluetooth/controller/ticker/ticker.h @@ -171,6 +171,7 @@ uint8_t ticker_init(uint8_t instance_index, uint8_t count_node, void *node, void *user_op, ticker_caller_id_get_cb_t caller_id_get_cb, ticker_sched_cb_t sched_cb, ticker_trigger_set_cb_t trigger_set_cb); +int ticker_deinit(uint8_t instance_index); bool ticker_is_initialized(uint8_t instance_index); void ticker_trigger(uint8_t instance_index); void ticker_worker(void *param);