From a92f4ed389314e2f472eede3949b176cbc81a0e0 Mon Sep 17 00:00:00 2001 From: Shen Weilong Date: Mon, 17 Feb 2025 19:38:39 +0800 Subject: [PATCH 1/6] change(ble): Supported cuttable architecture for ble --- components/bt/CMakeLists.txt | 1 + components/bt/controller/esp32c5/Kconfig.in | 166 ++++++++++---------- components/bt/controller/esp32c5/ble.c | 106 +++++++++++++ components/bt/controller/esp32c5/ble_priv.h | 12 ++ components/bt/controller/esp32c5/bt.c | 19 ++- components/bt/controller/esp32c6/Kconfig.in | 166 ++++++++++---------- components/bt/controller/esp32c6/ble.c | 106 +++++++++++++ components/bt/controller/esp32c6/ble_priv.h | 12 ++ components/bt/controller/esp32c6/bt.c | 19 ++- components/bt/controller/esp32h2/Kconfig.in | 166 ++++++++++---------- components/bt/controller/esp32h2/ble.c | 106 +++++++++++++ components/bt/controller/esp32h2/ble_priv.h | 12 ++ components/bt/controller/esp32h2/bt.c | 19 ++- 13 files changed, 667 insertions(+), 243 deletions(-) create mode 100644 components/bt/controller/esp32c5/ble.c create mode 100644 components/bt/controller/esp32c5/ble_priv.h create mode 100644 components/bt/controller/esp32c6/ble.c create mode 100644 components/bt/controller/esp32c6/ble_priv.h create mode 100644 components/bt/controller/esp32h2/ble.c create mode 100644 components/bt/controller/esp32h2/ble_priv.h diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 59cd9e94c2..568635f51f 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -91,6 +91,7 @@ if(CONFIG_BT_ENABLED) endif() set(ldscripts "linker_esp32c2.lf") else() + list(APPEND srcs "controller/${target_name}/ble.c") list(APPEND ldscripts "linker_esp_ble_controller.lf") endif() diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 988dc38d0b..d458140efd 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -283,110 +283,116 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -menuconfig BT_LE_CONTROLLER_LOG_ENABLED - bool "Controller log enable" - default n - help - Enable controller log +menu "Controller debug features" + menuconfig BT_LE_CONTROLLER_LOG_ENABLED + bool "Controller log enable" + default n + help + Enable controller log -config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable controller log module -config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable hci log module -config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Only operate in dump mode -config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus -config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help Store ble controller logs to flash memory. -config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help The size of ble controller log partition shall be a multiples of 4K. The name of log partition shall be "bt_ctrl_log". The partition type shall be ESP_PARTITION_TYPE_DATA. The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. -config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the first BLE controller LOG buffer. -config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help Configure the size of the second BLE controller LOG buffer. -config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the BLE HCI LOG buffer. -config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE - bool "Enable wrap panic handler" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. -config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE - bool "Enable esp_task_wdt_isr_user_handler implementation" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. -config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL - int "The output level of controller log" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 5 - default 1 - help - The output level of controller log. + config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. -config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH - hex "The switch of module log output" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 0xFFFFFFFF - default 0xFFFFFFFF - help - The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + + config BT_LE_ERROR_SIM_ENABLED + bool "Enable controller features for internal testing" + default n +endmenu config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32c5/ble.c b/components/bt/controller/esp32c5/ble.c new file mode 100644 index 0000000000..3aca469ee1 --- /dev/null +++ b/components/bt/controller/esp32c5/ble.c @@ -0,0 +1,106 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +#include "sdkconfig.h" +#include "esp_bt_cfg.h" + +/* External functions or variables + ************************************************************************ + */ +int base_stack_initEnv(void); +void base_stack_deinitEnv(void); +int base_stack_enable(void); +void base_stack_disable(void); + +int conn_stack_initEnv(void); +void conn_stack_deinitEnv(void); +int conn_stack_enable(void); +void conn_stack_disable(void); + +#if CONFIG_BT_LE_ERROR_SIM_ENABLED +int conn_errorSim_initEnv(void); +void conn_errorSim_deinitEnv(void); +int conn_errorSim_enable(void); +void conn_errorSim_disable(void); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + +/* Local functions definition + *************************************************************************** + */ +int ble_stack_initEnv(void) +{ + int rc; + + rc = base_stack_initEnv(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_initEnv(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_initEnv(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_deinitEnv(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_deinitEnv(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_deinitEnv(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_deinitEnv(); +} + +int ble_stack_enable(void) +{ + int rc; + + rc = base_stack_enable(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_enable(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_enable(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_disable(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_disable(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_disable(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_disable(); +} diff --git a/components/bt/controller/esp32c5/ble_priv.h b/components/bt/controller/esp32c5/ble_priv.h new file mode 100644 index 0000000000..82dc4d1694 --- /dev/null +++ b/components/bt/controller/esp32c5/ble_priv.h @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +int ble_stack_initEnv(void); + +void ble_stack_deinitEnv(void); + +int ble_stack_enable(void); + +void ble_stack_disable(void); diff --git a/components/bt/controller/esp32c5/bt.c b/components/bt/controller/esp32c5/bt.c index d3a92bc81a..cfbff2a6f9 100644 --- a/components/bt/controller/esp32c5/bt.c +++ b/components/bt/controller/esp32c5/bt.c @@ -34,6 +34,7 @@ #include "os/endian.h" #include "esp_bt.h" +#include "ble_priv.h" #include "esp_intr_alloc.h" #include "esp_sleep.h" #include "esp_pm.h" @@ -925,13 +926,19 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto modem_deint; } + ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = r_ble_controller_init(cfg); if (ret != ESP_OK) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "r_ble_controller_init failed %d", ret); goto modem_deint; } - ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = ble_stack_initEnv(); + if (ret != ESP_OK) { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_stack_initEnv failed %d", ret); + goto free_controller; + } ble_controller_scan_duplicate_config(); @@ -971,6 +978,7 @@ free_controller: hci_transport_deinit(); controller_sleep_deinit(); os_msys_deinit(); + ble_stack_deinitEnv(); r_ble_controller_deinit(); modem_deint: esp_ble_unregister_bb_funcs(); @@ -1008,6 +1016,7 @@ esp_err_t esp_bt_controller_deinit(void) // modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_module_disable(PERIPH_BT_MODULE); + ble_stack_deinitEnv(); r_ble_controller_deinit(); esp_ble_unregister_bb_funcs(); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED @@ -1061,6 +1070,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) r_ble_ll_scan_start_time_init_compensation(500); r_priv_sdk_config_insert_proc_time_set(500); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY + + if (ble_stack_enable() != 0) { + ret = ESP_FAIL; + goto error; + } + if (r_ble_controller_enable(mode) != 0) { ret = ESP_FAIL; goto error; @@ -1069,6 +1084,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_OK; error: + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif @@ -1092,6 +1108,7 @@ esp_err_t esp_bt_controller_disable(void) if (r_ble_controller_disable() != 0) { return ESP_FAIL; } + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index da55dc877b..230fbb08f5 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -315,110 +315,116 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -menuconfig BT_LE_CONTROLLER_LOG_ENABLED - bool "Controller log enable" - default n - help - Enable controller log +menu "Controller debug features" + menuconfig BT_LE_CONTROLLER_LOG_ENABLED + bool "Controller log enable" + default n + help + Enable controller log -config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable controller log module -config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable hci log module -config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Only operate in dump mode -config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus -config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help Store ble controller logs to flash memory. -config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help The size of ble controller log partition shall be a multiples of 4K. The name of log partition shall be "bt_ctrl_log". The partition type shall be ESP_PARTITION_TYPE_DATA. The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. -config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the first BLE controller LOG buffer. -config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help Configure the size of the second BLE controller LOG buffer. -config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the BLE HCI LOG buffer. -config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE - bool "Enable wrap panic handler" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. -config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE - bool "Enable esp_task_wdt_isr_user_handler implementation" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. -config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL - int "The output level of controller log" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 5 - default 1 - help - The output level of controller log. + config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. -config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH - hex "The switch of module log output" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 0xFFFFFFFF - default 0xFFFFFFFF - help - The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + + config BT_LE_ERROR_SIM_ENABLED + bool "Enable controller features for internal testing" + default n +endmenu config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32c6/ble.c b/components/bt/controller/esp32c6/ble.c new file mode 100644 index 0000000000..3aca469ee1 --- /dev/null +++ b/components/bt/controller/esp32c6/ble.c @@ -0,0 +1,106 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +#include "sdkconfig.h" +#include "esp_bt_cfg.h" + +/* External functions or variables + ************************************************************************ + */ +int base_stack_initEnv(void); +void base_stack_deinitEnv(void); +int base_stack_enable(void); +void base_stack_disable(void); + +int conn_stack_initEnv(void); +void conn_stack_deinitEnv(void); +int conn_stack_enable(void); +void conn_stack_disable(void); + +#if CONFIG_BT_LE_ERROR_SIM_ENABLED +int conn_errorSim_initEnv(void); +void conn_errorSim_deinitEnv(void); +int conn_errorSim_enable(void); +void conn_errorSim_disable(void); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + +/* Local functions definition + *************************************************************************** + */ +int ble_stack_initEnv(void) +{ + int rc; + + rc = base_stack_initEnv(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_initEnv(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_initEnv(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_deinitEnv(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_deinitEnv(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_deinitEnv(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_deinitEnv(); +} + +int ble_stack_enable(void) +{ + int rc; + + rc = base_stack_enable(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_enable(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_enable(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_disable(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_disable(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_disable(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_disable(); +} diff --git a/components/bt/controller/esp32c6/ble_priv.h b/components/bt/controller/esp32c6/ble_priv.h new file mode 100644 index 0000000000..82dc4d1694 --- /dev/null +++ b/components/bt/controller/esp32c6/ble_priv.h @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +int ble_stack_initEnv(void); + +void ble_stack_deinitEnv(void); + +int ble_stack_enable(void); + +void ble_stack_disable(void); diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 54b09ca762..983764e767 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -35,6 +35,7 @@ #include "esp_bt.h" #include "esp_intr_alloc.h" +#include "ble_priv.h" #include "esp_sleep.h" #include "esp_pm.h" #ifdef CONFIG_ESP_PHY_ENABLED @@ -963,13 +964,19 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto modem_deint; } + ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = r_ble_controller_init(cfg); if (ret != ESP_OK) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "r_ble_controller_init failed %d", ret); goto modem_deint; } - ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = ble_stack_initEnv(); + if (ret != ESP_OK) { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_stack_initEnv failed %d", ret); + goto free_controller; + } ble_controller_scan_duplicate_config(); @@ -1012,6 +1019,7 @@ free_controller: hci_transport_deinit(); controller_sleep_deinit(); os_msys_deinit(); + ble_stack_deinitEnv(); r_ble_controller_deinit(); modem_deint: esp_ble_unregister_bb_funcs(); @@ -1049,6 +1057,7 @@ esp_err_t esp_bt_controller_deinit(void) modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_module_disable(PERIPH_BT_MODULE); + ble_stack_deinitEnv(); r_ble_controller_deinit(); esp_ble_unregister_bb_funcs(); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED @@ -1102,6 +1111,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) r_ble_ll_scan_start_time_init_compensation(500); r_priv_sdk_config_insert_proc_time_set(500); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY + + if (ble_stack_enable() != 0) { + ret = ESP_FAIL; + goto error; + } + if (r_ble_controller_enable(mode) != 0) { ret = ESP_FAIL; goto error; @@ -1110,6 +1125,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_OK; error: + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif @@ -1133,6 +1149,7 @@ esp_err_t esp_bt_controller_disable(void) if (r_ble_controller_disable() != 0) { return ESP_FAIL; } + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 5e9929a2dc..8aaed93f0e 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -306,110 +306,116 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -menuconfig BT_LE_CONTROLLER_LOG_ENABLED - bool "Controller log enable" - default n - help - Enable controller log +menu "Controller debug features" + menuconfig BT_LE_CONTROLLER_LOG_ENABLED + bool "Controller log enable" + default n + help + Enable controller log -config BT_LE_CONTROLLER_LOG_CTRL_ENABLED - bool "enable controller log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_CTRL_ENABLED + bool "enable controller log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable controller log module -config BT_LE_CONTROLLER_LOG_HCI_ENABLED - bool "enable HCI log module" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_HCI_ENABLED + bool "enable HCI log module" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Enable hci log module -config BT_LE_CONTROLLER_LOG_DUMP_ONLY - bool "Controller log dump mode only" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default y - help + config BT_LE_CONTROLLER_LOG_DUMP_ONLY + bool "Controller log dump mode only" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default y + help Only operate in dump mode -config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED - bool "Output ble controller logs to SPI bus (Experimental)" - depends on BT_LE_CONTROLLER_LOG_ENABLED - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - select BT_BLE_LOG_SPI_OUT_ENABLED - default n - help - Output ble controller logs to SPI bus + config BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED + bool "Output ble controller logs to SPI bus (Experimental)" + depends on BT_LE_CONTROLLER_LOG_ENABLED + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + select BT_BLE_LOG_SPI_OUT_ENABLED + default n + help + Output ble controller logs to SPI bus -config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - bool "Store ble controller logs to flash(Experimental)" - depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help + config BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + bool "Store ble controller logs to flash(Experimental)" + depends on !BT_LE_CONTROLLER_LOG_DUMP_ONLY + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help Store ble controller logs to flash memory. -config BT_LE_CONTROLLER_LOG_PARTITION_SIZE - int "size of ble controller log partition(Multiples of 4K)" - depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE - default 65536 - help + config BT_LE_CONTROLLER_LOG_PARTITION_SIZE + int "size of ble controller log partition(Multiples of 4K)" + depends on BT_LE_CONTROLLER_LOG_STORAGE_ENABLE + default 65536 + help The size of ble controller log partition shall be a multiples of 4K. The name of log partition shall be "bt_ctrl_log". The partition type shall be ESP_PARTITION_TYPE_DATA. The partition sub_type shall be ESP_PARTITION_SUBTYPE_ANY. -config BT_LE_LOG_CTRL_BUF1_SIZE - int "size of the first BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_CTRL_BUF1_SIZE + int "size of the first BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the first BLE controller LOG buffer. -config BT_LE_LOG_CTRL_BUF2_SIZE - int "size of the second BLE controller LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 1024 - help + config BT_LE_LOG_CTRL_BUF2_SIZE + int "size of the second BLE controller LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 1024 + help Configure the size of the second BLE controller LOG buffer. -config BT_LE_LOG_HCI_BUF_SIZE - int "size of the BLE HCI LOG buffer" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default 4096 - help + config BT_LE_LOG_HCI_BUF_SIZE + int "size of the BLE HCI LOG buffer" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default 4096 + help Configure the size of the BLE HCI LOG buffer. -config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE - bool "Enable wrap panic handler" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. + config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE + bool "Enable wrap panic handler" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Wrap esp_panic_handler to get controller logs when PC pointer exception crashes. -config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE - bool "Enable esp_task_wdt_isr_user_handler implementation" - depends on BT_LE_CONTROLLER_LOG_ENABLED - default n - help - Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. + config BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE + bool "Enable esp_task_wdt_isr_user_handler implementation" + depends on BT_LE_CONTROLLER_LOG_ENABLED + default n + help + Implement esp_task_wdt_isr_user_handler to get controller logs when task wdt issue is triggered. -config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL - int "The output level of controller log" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 5 - default 1 - help - The output level of controller log. + config BT_LE_CONTROLLER_LOG_OUTPUT_LEVEL + int "The output level of controller log" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 5 + default 1 + help + The output level of controller log. -config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH - hex "The switch of module log output" - depends on BT_LE_CONTROLLER_LOG_ENABLED - range 0 0xFFFFFFFF - default 0xFFFFFFFF - help - The switch of module log output, this is an unsigned 32-bit hexadecimal value. + config BT_LE_CONTROLLER_LOG_MOD_OUTPUT_SWITCH + hex "The switch of module log output" + depends on BT_LE_CONTROLLER_LOG_ENABLED + range 0 0xFFFFFFFF + default 0xFFFFFFFF + help + The switch of module log output, this is an unsigned 32-bit hexadecimal value. + + config BT_LE_ERROR_SIM_ENABLED + bool "Enable controller features for internal testing" + default n +endmenu config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32h2/ble.c b/components/bt/controller/esp32h2/ble.c new file mode 100644 index 0000000000..3aca469ee1 --- /dev/null +++ b/components/bt/controller/esp32h2/ble.c @@ -0,0 +1,106 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +#include "sdkconfig.h" +#include "esp_bt_cfg.h" + +/* External functions or variables + ************************************************************************ + */ +int base_stack_initEnv(void); +void base_stack_deinitEnv(void); +int base_stack_enable(void); +void base_stack_disable(void); + +int conn_stack_initEnv(void); +void conn_stack_deinitEnv(void); +int conn_stack_enable(void); +void conn_stack_disable(void); + +#if CONFIG_BT_LE_ERROR_SIM_ENABLED +int conn_errorSim_initEnv(void); +void conn_errorSim_deinitEnv(void); +int conn_errorSim_enable(void); +void conn_errorSim_disable(void); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + +/* Local functions definition + *************************************************************************** + */ +int ble_stack_initEnv(void) +{ + int rc; + + rc = base_stack_initEnv(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_initEnv(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_initEnv(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_deinitEnv(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_deinitEnv(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_deinitEnv(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_deinitEnv(); +} + +int ble_stack_enable(void) +{ + int rc; + + rc = base_stack_enable(); + if (rc) { + return rc; + } + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_enable(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_enable(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + return 0; +} + +void ble_stack_disable(void) +{ +#if DEFAULT_BT_LE_MAX_CONNECTIONS +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_errorSim_disable(); +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED + conn_stack_disable(); +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + + base_stack_disable(); +} diff --git a/components/bt/controller/esp32h2/ble_priv.h b/components/bt/controller/esp32h2/ble_priv.h new file mode 100644 index 0000000000..82dc4d1694 --- /dev/null +++ b/components/bt/controller/esp32h2/ble_priv.h @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +int ble_stack_initEnv(void); + +void ble_stack_deinitEnv(void); + +int ble_stack_enable(void); + +void ble_stack_disable(void); diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 4599263193..9a7e115a97 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -34,6 +34,7 @@ #include "os/endian.h" #include "esp_bt.h" +#include "ble_priv.h" #include "esp_intr_alloc.h" #include "esp_sleep.h" #include "esp_pm.h" @@ -939,13 +940,19 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto modem_deint; } + ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = r_ble_controller_init(cfg); if (ret != ESP_OK) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "r_ble_controller_init failed %d", ret); goto modem_deint; } - ESP_LOGI(NIMBLE_PORT_LOG_TAG, "ble controller commit:[%s]", ble_controller_get_compile_version()); + ret = ble_stack_initEnv(); + if (ret != ESP_OK) { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_stack_initEnv failed %d", ret); + goto free_controller; + } ble_controller_scan_duplicate_config(); @@ -988,6 +995,7 @@ free_controller: hci_transport_deinit(); controller_sleep_deinit(); os_msys_deinit(); + ble_stack_deinitEnv(); r_ble_controller_deinit(); modem_deint: esp_ble_unregister_bb_funcs(); @@ -1023,6 +1031,7 @@ esp_err_t esp_bt_controller_deinit(void) modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE); modem_clock_module_disable(PERIPH_BT_MODULE); + ble_stack_deinitEnv(); r_ble_controller_deinit(); esp_ble_unregister_bb_funcs(); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED @@ -1076,6 +1085,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) r_ble_ll_scan_start_time_init_compensation(500); r_priv_sdk_config_insert_proc_time_set(500); #endif // CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY + + if (ble_stack_enable() != 0) { + ret = ESP_FAIL; + goto error; + } + if (r_ble_controller_enable(mode) != 0) { ret = ESP_FAIL; goto error; @@ -1084,6 +1099,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_OK; error: + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif @@ -1107,6 +1123,7 @@ esp_err_t esp_bt_controller_disable(void) if (r_ble_controller_disable() != 0) { return ESP_FAIL; } + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif From aeff03bac4ea7a96acb1b74f37a5f56752a3bb8c Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 18 Feb 2025 11:46:07 +0800 Subject: [PATCH 2/6] feat(ble): implement ble capture info user handler on ESP32-C6 and ESP32-H2 --- components/bt/controller/esp32c6/Kconfig.in | 8 +++++-- components/bt/controller/esp32c6/bt.c | 26 +++++++++++++++++++++ components/bt/controller/esp32h2/Kconfig.in | 8 +++++-- components/bt/controller/esp32h2/bt.c | 26 +++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 230fbb08f5..77ad51cf02 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -424,6 +424,10 @@ menu "Controller debug features" config BT_LE_ERROR_SIM_ENABLED bool "Enable controller features for internal testing" default n + + config BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + bool "When ACL disconnects abnormally, assertion processing is performed(Experimental)" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE @@ -782,14 +786,14 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX The value of upperlimitmax needs to be a power of 2. config BT_LE_CTRL_CHAN_ASS_EN - bool "Enable channel assessment" + bool "Enable channel assessment(Experimental)" default n help If this option is enabled, The Controller will records the communication quality for each channel and then start a timer to check and update the channel map every 4 seconds. config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX - bool "Enable aux packet when ext adv data length is zero" + bool "Enable aux packet when ext adv data length is zero(Experimental)" default y help When this option is enabled, auxiliary packets will be present in the events of diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 983764e767..5af71a487b 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -115,6 +115,7 @@ typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int r_ble_controller_init(esp_bt_controller_config_t *cfg); +extern void esp_ble_controller_info_capture(uint32_t cycle_times); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); @@ -1659,3 +1660,28 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv) #endif // CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC #endif // (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) + +int IRAM_ATTR +ble_capture_info_user_handler(uint8_t type, uint32_t reason) +{ + int i; + + switch(type) { + case 0: + for (i = 0; i < 2; i++) { + esp_ble_controller_info_capture(0x010101); + } + + break; +#if CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + case 1: + if ((reason == 0x08) || (reason == 0x3d) || (reason == 0x28)) { + osi_assert_wrapper(__LINE__,__func__, type, reason); + } + break; +#endif // CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + default: + break; + } + return 0; +} diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index 8aaed93f0e..92299131fe 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -415,6 +415,10 @@ menu "Controller debug features" config BT_LE_ERROR_SIM_ENABLED bool "Enable controller features for internal testing" default n + + config BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + bool "When ACL disconnects abnormally, assertion processing is performed(Experimental)" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE @@ -783,14 +787,14 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX The value of upperlimitmax needs to be a power of 2. config BT_LE_CTRL_CHAN_ASS_EN - bool "Enable channel assessment" + bool "Enable channel assessment(Experimental)" default n help If this option is enabled, The Controller will records the communication quality for each channel and then start a timer to check and update the channel map every 4 seconds. config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX - bool "Enable aux packet when ext adv data length is zero" + bool "Enable aux packet when ext adv data length is zero(Experimental)" default y help When this option is enabled, auxiliary packets will be present in the events of diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 9a7e115a97..cc4220d163 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -110,6 +110,7 @@ typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int r_ble_controller_init(esp_bt_controller_config_t *cfg); +extern void esp_ble_controller_info_capture(uint32_t cycle_times); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); @@ -1632,3 +1633,28 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv) #endif // CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC #endif // (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) + +int IRAM_ATTR +ble_capture_info_user_handler(uint8_t type, uint32_t reason) +{ + int i; + + switch(type) { + case 0: + for (i = 0; i < 2; i++) { + esp_ble_controller_info_capture(0x010101); + } + + break; +#if CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + case 1: + if ((reason == 0x08) || (reason == 0x3d) || (reason == 0x28)) { + osi_assert_wrapper(__LINE__,__func__, type, reason); + } + break; +#endif // CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + default: + break; + } + return 0; +} From 18ce40a23a71dfc07aea7adf812e5eeddd1a5f83 Mon Sep 17 00:00:00 2001 From: zwl Date: Tue, 18 Feb 2025 11:47:03 +0800 Subject: [PATCH 3/6] feat(ble): implement ble capture info user handler on ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 8 +++++-- components/bt/controller/esp32c5/bt.c | 26 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index d458140efd..79aecce76c 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -392,6 +392,10 @@ menu "Controller debug features" config BT_LE_ERROR_SIM_ENABLED bool "Enable controller features for internal testing" default n + + config BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + bool "When ACL disconnects abnormally, assertion processing is performed(Experimental)" + default n endmenu config BT_LE_LL_RESOLV_LIST_SIZE @@ -757,14 +761,14 @@ config BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX The value of upperlimitmax needs to be a power of 2. config BT_LE_CTRL_CHAN_ASS_EN - bool "Enable channel assessment" + bool "Enable channel assessment(Experimental)" default n help If this option is enabled, The Controller will records the communication quality for each channel and then start a timer to check and update the channel map every 4 seconds. config BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX - bool "Enable aux packet when ext adv data length is zero" + bool "Enable aux packet when ext adv data length is zero(Experimental)" default y help When this option is enabled, auxiliary packets will be present in the events of diff --git a/components/bt/controller/esp32c5/bt.c b/components/bt/controller/esp32c5/bt.c index cfbff2a6f9..d9114ccc19 100644 --- a/components/bt/controller/esp32c5/bt.c +++ b/components/bt/controller/esp32c5/bt.c @@ -105,6 +105,7 @@ typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end); */ extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs); extern int r_ble_controller_init(esp_bt_controller_config_t *cfg); +extern void esp_ble_controller_info_capture(uint32_t cycle_times); #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int r_ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int r_ble_log_deinit_async(void); @@ -1618,3 +1619,28 @@ int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv) #endif // CONFIG_BT_LE_SM_LEGACY || CONFIG_BT_LE_SM_SC #endif // (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED) + +int IRAM_ATTR +ble_capture_info_user_handler(uint8_t type, uint32_t reason) +{ + int i; + + switch(type) { + case 0: + for (i = 0; i < 2; i++) { + esp_ble_controller_info_capture(0x010101); + } + + break; +#if CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + case 1: + if ((reason == 0x08) || (reason == 0x3d) || (reason == 0x28)) { + osi_assert_wrapper(__LINE__,__func__, type, reason); + } + break; +#endif // CONFIG_BT_LE_ASSERT_WHEN_ABNORMAL_DISCONN_ENABLED + default: + break; + } + return 0; +} From 49164ce77f716f0b0d011ed5980e5b20994f87ca Mon Sep 17 00:00:00 2001 From: cjin Date: Wed, 19 Feb 2025 11:43:59 +0800 Subject: [PATCH 4/6] change(ble): update esp32h2 lib to 7ead2d29 --- components/bt/controller/lib_esp32h2/esp32h2-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index 7d35fc30e8..e755a65597 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit 7d35fc30e8cada9567f97378e24608bc63b080e4 +Subproject commit e755a655979177c9551d5fb3613ebb4885aab3a5 From bbb160a0832299ed5a1677b264a3395457d5102d Mon Sep 17 00:00:00 2001 From: cjin Date: Wed, 19 Feb 2025 11:48:28 +0800 Subject: [PATCH 5/6] change(ble): update esp32c5 lib to 7ead2d29 --- components/bt/controller/lib_esp32c5/esp32c5-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib index 5fedf4bb0e..e17ca05e5e 160000 --- a/components/bt/controller/lib_esp32c5/esp32c5-bt-lib +++ b/components/bt/controller/lib_esp32c5/esp32c5-bt-lib @@ -1 +1 @@ -Subproject commit 5fedf4bb0e11e11d54d5f712ec17b72cc2c95fdc +Subproject commit e17ca05e5e0acf39212811a08174d5c1c69cf165 From f2330fd2fbab26a1883a1957e313f50433817215 Mon Sep 17 00:00:00 2001 From: cjin Date: Wed, 19 Feb 2025 11:48:40 +0800 Subject: [PATCH 6/6] change(ble): update esp32c6 lib to 7ead2d29 --- components/bt/controller/lib_esp32c6/esp32c6-bt-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index 4cb60b2cd1..08946905ec 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit 4cb60b2cd1c560a85effde18465b0412e715b048 +Subproject commit 08946905ec0dfcbfc7dd2919b27e43cbcbde66ed