diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index 62f4ee0047..8faff44317 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -280,6 +280,22 @@ config BT_CTRL_SCAN_DUPL_CACHE_SIZE Maximum number of devices which can be recorded in scan duplicate filter. When the maximum amount of device in the filter is reached, the cache will be refreshed. +config BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD + int "Duplicate scan list refresh period" + depends on BT_CTRL_BLE_SCAN_DUPL + range 0 1000 + default 0 + help + If the period value is non-zero, the controller will periodically clear the device information + stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared + until the scanning is disabled. Duplicate advertisements for this period should not be sent to the + Host in advertising report events. + There are two scenarios where the ADV packet will be repeatedly reported: + 1. The duplicate scan cache is full, the controller will delete the oldest device information and + add new device information. + 2. When the refresh period is up, the controller will clear all device information and start filtering + again. + config BT_CTRL_BLE_MESH_SCAN_DUPL_EN bool "Special duplicate scan mechanism for BLE Mesh scan" depends on BT_CTRL_BLE_SCAN_DUPL diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 137e670b66..068789466a 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -313,6 +313,8 @@ static void btdm_slp_tmr_callback(void *arg); static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end); +static void bt_controller_deinit_internal(void); + /* Local variable definition *************************************************************************** */ @@ -1272,31 +1274,36 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) return ESP_OK; error: + + bt_controller_deinit_internal(); + + return err; +} + +esp_err_t esp_bt_controller_deinit(void) +{ + if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { + return ESP_ERR_INVALID_STATE; + } + + btdm_controller_deinit(); + + bt_controller_deinit_internal(); + + return ESP_OK; +} + +static void bt_controller_deinit_internal(void) +{ + periph_module_disable(PERIPH_BT_MODULE); + if (s_lp_stat.phy_enabled) { esp_phy_disable(); s_lp_stat.phy_enabled = 0; } + // deinit low power control resources do { - // deinit low power control resources -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - if (s_light_sleep_pm_lock != NULL) { - esp_pm_lock_delete(s_light_sleep_pm_lock); - s_light_sleep_pm_lock = NULL; - } - } - if (s_pm_lock != NULL) { - esp_pm_lock_delete(s_pm_lock); - s_pm_lock = NULL; - s_lp_stat.pm_lock_released = 0; - } - -#endif - if (s_lp_cntl.wakeup_timer_required && s_btdm_slp_tmr != NULL) { - esp_timer_delete(s_btdm_slp_tmr); - s_btdm_slp_tmr = NULL; - } #if CONFIG_MAC_BB_PD if (s_lp_cntl.mac_bb_pd) { @@ -1304,6 +1311,32 @@ error: s_lp_cntl.mac_bb_pd = 0; } #endif + +#ifdef CONFIG_PM_ENABLE + if (s_lp_cntl.no_light_sleep) { + if (s_light_sleep_pm_lock != NULL) { + esp_pm_lock_delete(s_light_sleep_pm_lock); + s_light_sleep_pm_lock = NULL; + } + } + + if (s_pm_lock != NULL) { + esp_pm_lock_delete(s_pm_lock); + s_pm_lock = NULL; + s_lp_stat.pm_lock_released = 0; + } + +#endif + + if (s_lp_cntl.wakeup_timer_required) { + if (s_lp_stat.wakeup_timer_started) { + esp_timer_stop(s_btdm_slp_tmr); + } + s_lp_stat.wakeup_timer_started = 0; + esp_timer_delete(s_btdm_slp_tmr); + s_btdm_slp_tmr = NULL; + } + if (s_lp_cntl.enable) { btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR); if (s_wakeup_req_sem != NULL) { @@ -1331,7 +1364,6 @@ error: #if CONFIG_MAC_BB_PD esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb); - esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif @@ -1345,89 +1377,8 @@ error: free(osi_funcs_p); osi_funcs_p = NULL; } - return err; -} - -esp_err_t esp_bt_controller_deinit(void) -{ - if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { - return ESP_ERR_INVALID_STATE; - } - - btdm_controller_deinit(); - periph_module_disable(PERIPH_BT_MODULE); - - if (s_lp_stat.phy_enabled) { - esp_phy_disable(); - s_lp_stat.phy_enabled = 0; - } else { - assert(0); - } - - // deinit low power control resources - do { -#if CONFIG_MAC_BB_PD - btdm_deep_sleep_mem_deinit(); -#endif - -#ifdef CONFIG_PM_ENABLE - if (s_lp_cntl.no_light_sleep) { - esp_pm_lock_delete(s_light_sleep_pm_lock); - s_light_sleep_pm_lock = NULL; - } - - esp_pm_lock_delete(s_pm_lock); - s_pm_lock = NULL; - s_lp_stat.pm_lock_released = 0; -#endif - if (s_lp_cntl.wakeup_timer_required) { - if (s_lp_stat.wakeup_timer_started) { - esp_timer_stop(s_btdm_slp_tmr); - } - s_lp_stat.wakeup_timer_started = 0; - esp_timer_delete(s_btdm_slp_tmr); - s_btdm_slp_tmr = NULL; - } - - if (s_lp_cntl.enable) { - btdm_vnd_offload_task_deregister(BTDM_VND_OL_SIG_WAKEUP_TMR); - - semphr_delete_wrapper(s_wakeup_req_sem); - s_wakeup_req_sem = NULL; - } - if (s_lp_cntl.lpclk_sel == BTDM_LPCLK_SEL_XTAL) { -#ifdef CONFIG_BT_CTRL_MAIN_XTAL_PU_DURING_LIGHT_SLEEP - if (s_lp_cntl.main_xtal_pu) { - ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF)); - s_lp_cntl.main_xtal_pu = 0; - } -#endif - btdm_lpclk_select_src(BTDM_LPCLK_SEL_RTC_SLOW); - btdm_lpclk_set_div(0); -#if CONFIG_SW_COEXIST_ENABLE - coex_update_lpclk_interval(); -#endif - } - - btdm_lpcycle_us = 0; - } while (0); - -#if CONFIG_MAC_BB_PD - esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb); - esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); -#endif - - esp_bt_power_domain_off(); -#if CONFIG_MAC_BB_PD - esp_mac_bb_pd_mem_deinit(); -#endif - esp_phy_modem_deinit(); - - free(osi_funcs_p); - osi_funcs_p = NULL; btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; - return ESP_OK; } esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index 5031203040..63f8d3aaad 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit 5031203040da20073bb5c9f32f3444333f30dce7 +Subproject commit 63f8d3aaad4f8352cd64de817986e152b7da16fe diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 0b9cae835b..d54b33a657 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -18,7 +18,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02209230 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02212090 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -129,6 +129,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #define MESH_DUPLICATE_SCAN_CACHE_SIZE 0 #endif +#ifndef CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD +#define DUPL_SCAN_CACHE_REFRESH_PERIOD 0 +#else +#define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD +#endif + #ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN #define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN #else @@ -187,6 +193,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .hw_recorrect_en = AGC_RECORRECT_EN, \ .cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL, \ .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ + .dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \ } #else @@ -255,6 +262,7 @@ typedef struct { uint8_t hw_recorrect_en; uint8_t cca_thresh; /*!< cca threshold*/ uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */ + uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */ } esp_bt_controller_config_t; /**