diff --git a/components/bt/controller/esp32c3/Kconfig.in b/components/bt/controller/esp32c3/Kconfig.in index 98274a2236..aa0446dcc3 100644 --- a/components/bt/controller/esp32c3/Kconfig.in +++ b/components/bt/controller/esp32c3/Kconfig.in @@ -78,15 +78,29 @@ config BT_CTRL_ADV_DUP_FILT_MAX help The maxinum number of suplicate scan filter -config BT_CTRL_HW_CCA - bool "HW CCA check enable" - default n +choice BT_BLE_CCA_MODE + prompt "BLE CCA mode" + default BT_BLE_CCA_MODE_NONE help - It enables HW CCA feature in controller + Define BT BLE CCA mode + + config BT_BLE_CCA_MODE_NONE + bool "NONE" + config BT_BLE_CCA_MODE_HW + bool "Hardware" + config BT_BLE_CCA_MODE_SW + bool "Software" +endchoice + +config BT_BLE_CCA_MODE + int + default 0 if BT_BLE_CCA_MODE_NONE + default 1 if BT_BLE_CCA_MODE_HW + default 2 if BT_BLE_CCA_MODE_SW config BT_CTRL_HW_CCA_VAL int "CCA threshold value" - range 20 60 + range 20 100 default 20 help It is the threshold value of HW CCA, if the value is 30, it means CCA threshold is -30 dBm. diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index db9c2fbf1c..d9c9618da4 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -112,7 +112,7 @@ do{\ } while(0) #define OSI_FUNCS_TIME_BLOCKING 0xffffffff -#define OSI_VERSION 0x00010006 +#define OSI_VERSION 0x00010007 #define OSI_MAGIC_VALUE 0xFADEBEAD /* Types definition @@ -193,6 +193,8 @@ struct osi_funcs_t { void (* _esp_hw_power_down)(void); void (* _esp_hw_power_up)(void); void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem); + void (* _ets_delay_us)(uint32_t us); + void (* _btdm_rom_table_ready)(void); }; @@ -251,6 +253,8 @@ extern void esp_mac_bb_power_up(void); extern void ets_backup_dma_copy(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); #endif +extern void btdm_cca_feature_enable(void); + extern uint32_t _bt_bss_start; extern uint32_t _bt_bss_end; extern uint32_t _btdm_bss_start; @@ -310,6 +314,7 @@ static void interrupt_off_wrapper(int intr_num); static void btdm_hw_mac_power_up_wrapper(void); static void btdm_hw_mac_power_down_wrapper(void); static void btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem); +static void btdm_funcs_table_ready_wrapper(void); static void btdm_slp_tmr_callback(void *arg); @@ -374,6 +379,8 @@ static const struct osi_funcs_t osi_funcs_ro = { ._esp_hw_power_down = btdm_hw_mac_power_down_wrapper, ._esp_hw_power_up = btdm_hw_mac_power_up_wrapper, ._ets_backup_dma_copy = btdm_backup_dma_copy_wrapper, + ._ets_delay_us = esp_rom_delay_us, + ._btdm_rom_table_ready = btdm_funcs_table_ready_wrapper, }; static DRAM_ATTR struct osi_funcs_t *osi_funcs_p; @@ -871,6 +878,13 @@ static void async_wakeup_request_end(int event) return; } +static void btdm_funcs_table_ready_wrapper(void) +{ +#if BT_BLE_CCA_MODE == 2 + btdm_cca_feature_enable(); +#endif +} + static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) { #if CONFIG_SW_COEXIST_ENABLE @@ -1299,14 +1313,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) periph_module_enable(PERIPH_BT_MODULE); periph_module_reset(PERIPH_BT_MODULE); - esp_phy_enable(); - s_lp_stat.phy_enabled = 1; - if (btdm_controller_init(cfg) != 0) { err = ESP_ERR_NO_MEM; goto error; } - coex_pti_v2(); btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; @@ -1336,11 +1346,6 @@ 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 { @@ -1434,6 +1439,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_ERR_INVALID_ARG; } + /* Enable PHY when enabling controller to reduce power dissipation after controller init + * Notice the init order: esp_phy_enable() -> bt_bb_v2_init_cmplx() -> coex_pti_v2() + */ + esp_phy_enable(); + s_lp_stat.phy_enabled = 1; + #if CONFIG_SW_COEXIST_ENABLE coex_enable(); #endif @@ -1458,6 +1469,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) goto error; } + coex_pti_v2(); + btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED; return ret; @@ -1480,6 +1493,10 @@ error: #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif + if (s_lp_stat.phy_enabled) { + esp_phy_disable(); + s_lp_stat.phy_enabled = 0; + } return ret; } @@ -1498,6 +1515,10 @@ esp_err_t esp_bt_controller_disable(void) #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif + if (s_lp_stat.phy_enabled) { + esp_phy_disable(); + s_lp_stat.phy_enabled = 0; + } btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; diff --git a/components/bt/controller/lib_esp32c3_family b/components/bt/controller/lib_esp32c3_family index b438f60a29..040cd0eafd 160000 --- a/components/bt/controller/lib_esp32c3_family +++ b/components/bt/controller/lib_esp32c3_family @@ -1 +1 @@ -Subproject commit b438f60a295183e7c67eb42ae05f4580f4b1ced0 +Subproject commit 040cd0eafd8c6ee52bc7f7d5d633c9dc1b99bba2 diff --git a/components/bt/include/esp32c3/include/esp_bt.h b/components/bt/include/esp32c3/include/esp_bt.h index 8ac68e06ec..a7e17f4aa1 100644 --- a/components/bt/include/esp32c3/include/esp_bt.h +++ b/components/bt/include/esp32c3/include/esp_bt.h @@ -19,7 +19,7 @@ extern "C" { #endif #define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5 -#define ESP_BT_CTRL_CONFIG_VERSION 0x02302140 +#define ESP_BT_CTRL_CONFIG_VERSION 0x02307120 #define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead #define ESP_BT_HCI_TL_VERSION 0x00010000 @@ -169,6 +169,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); #endif // (CONFIG_BT_BLUEDROID_ENABLED) || (CONFIG_BT_NIMBLE_ENABLED) #endif // (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) || (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT) +#if defined(CONFIG_BT_BLE_CCA_MODE) +#define BT_BLE_CCA_MODE (CONFIG_BT_BLE_CCA_MODE) +#else +#define BT_BLE_CCA_MODE (0) +#endif + #define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1)) #define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0) @@ -214,6 +220,7 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status); .scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX, \ .dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD, \ .ble_50_feat_supp = BT_CTRL_50_FEATURE_SUPPORT, \ + .ble_cca_mode = BT_BLE_CCA_MODE, \ } #else @@ -284,6 +291,7 @@ typedef struct { uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */ uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */ bool ble_50_feat_supp; /*!< BLE 5.0 feature support */ + uint8_t ble_cca_mode; /*!< BLE CCA mode */ } esp_bt_controller_config_t; /**