From 9b0e4ee24ac51743af3335a61e86d11ce636b288 Mon Sep 17 00:00:00 2001 From: luomanruo Date: Mon, 4 Dec 2023 13:19:01 +0800 Subject: [PATCH] ble(fix): clear event queue when init event queue ble: update log module on ESP32C2, ESP32H2 and ESP32C6 --- components/bt/controller/esp32c2/Kconfig.in | 29 ++++++++++++++++--- components/bt/controller/esp32c2/bt.c | 7 +++-- components/bt/controller/esp32c6/Kconfig.in | 29 ++++++++++++++++--- components/bt/controller/esp32c6/bt.c | 6 ++-- components/bt/controller/esp32h2/Kconfig.in | 29 ++++++++++++++++--- components/bt/controller/esp32h2/bt.c | 6 ++-- .../bt/controller/lib_esp32c2/esp32c2-bt-lib | 2 +- .../bt/controller/lib_esp32c6/esp32c6-bt-lib | 2 +- .../bt/controller/lib_esp32h2/esp32h2-bt-lib | 2 +- .../bt/include/esp32c2/include/esp_bt.h | 4 +-- .../npl/freertos/src/npl_os_freertos.c | 4 +++ 11 files changed, 96 insertions(+), 24 deletions(-) diff --git a/components/bt/controller/esp32c2/Kconfig.in b/components/bt/controller/esp32c2/Kconfig.in index c480e4094e..088a90de68 100644 --- a/components/bt/controller/esp32c2/Kconfig.in +++ b/components/bt/controller/esp32c2/Kconfig.in @@ -253,7 +253,7 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -config BT_LE_CONTROLLER_LOG_ENABLED +menuconfig BT_LE_CONTROLLER_LOG_ENABLED bool "Controller log enable" default n help @@ -264,21 +264,42 @@ config BT_LE_CONTROLLER_LOG_CTRL_ENABLED depends on BT_LE_CONTROLLER_LOG_ENABLED default y help - Enable controller log module + 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 - Enable hci log module + 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 - Only operate in dump mode + Only operate in dump mode + +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 + 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 + Configure the size of the BLE HCI LOG buffer. config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 822cc70323..a22ff39d25 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -78,7 +78,6 @@ #define ACL_DATA_MBUF_LEADINGSPCAE 4 #endif // CONFIG_BT_BLUEDROID_ENABLED - /* Types definition ************************************************************************ */ @@ -127,6 +126,7 @@ extern int ble_controller_init(esp_bt_controller_config_t *cfg); extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create, uint8_t buffers, uint32_t *bufs_size); extern int ble_log_deinit_async(void); extern void ble_log_async_output_dump_all(bool output); +extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int ble_controller_deinit(void); extern int ble_controller_enable(uint8_t mode); @@ -201,7 +201,7 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {2048, 1024, 1024}; +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ @@ -1013,9 +1013,10 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b void esp_ble_controller_log_dump_all(bool output) { - portMUX_TYPE spinlock; + portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL_SAFE(&spinlock); + esp_panic_handler_reconfigure_wdts(5000); BT_ASSERT_PRINT("\r\n[DUMP_START:"); ble_log_async_output_dump_all(output); BT_ASSERT_PRINT("]\r\n"); diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 41619efd33..884a4740f1 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -269,7 +269,7 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -config BT_LE_CONTROLLER_LOG_ENABLED +menuconfig BT_LE_CONTROLLER_LOG_ENABLED bool "Controller log enable" default n help @@ -280,21 +280,42 @@ config BT_LE_CONTROLLER_LOG_CTRL_ENABLED depends on BT_LE_CONTROLLER_LOG_ENABLED default y help - Enable controller log module + 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 - Enable hci log module + 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 - Only operate in dump mode + Only operate in dump mode + +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 + 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 + Configure the size of the BLE HCI LOG buffer. config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 716337982f..5201c983a5 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -127,6 +127,7 @@ extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool extern int ble_log_deinit_async(void); extern void ble_log_async_select_dump_buffers(uint8_t buffers); extern void ble_log_async_output_dump_all(bool output); +extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int ble_controller_deinit(void); extern int ble_controller_enable(uint8_t mode); @@ -202,7 +203,7 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {6144, 1024, 2048}; +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ @@ -1183,9 +1184,10 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b void esp_ble_controller_log_dump_all(bool output) { - portMUX_TYPE spinlock; + portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL_SAFE(&spinlock); + esp_panic_handler_reconfigure_wdts(5000); BT_ASSERT_PRINT("\r\n[DUMP_START:"); ble_log_async_output_dump_all(output); BT_ASSERT_PRINT("]\r\n"); diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index a2ff7e8b76..b63d4aa865 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -260,7 +260,7 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE help This configures stack size of NimBLE controller task -config BT_LE_CONTROLLER_LOG_ENABLED +menuconfig BT_LE_CONTROLLER_LOG_ENABLED bool "Controller log enable" default n help @@ -271,21 +271,42 @@ config BT_LE_CONTROLLER_LOG_CTRL_ENABLED depends on BT_LE_CONTROLLER_LOG_ENABLED default y help - Enable controller log module + 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 - Enable hci log module + 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 - Only operate in dump mode + Only operate in dump mode + +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 + 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 + Configure the size of the BLE HCI LOG buffer. config BT_LE_LL_RESOLV_LIST_SIZE int "BLE LL Resolving list size" diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index d5b0c4bc1a..5cbce36508 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -121,6 +121,7 @@ extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool extern int ble_log_deinit_async(void); extern void ble_log_async_select_dump_buffers(uint8_t buffers); extern void ble_log_async_output_dump_all(bool output); +extern void esp_panic_handler_reconfigure_wdts(uint32_t timeout_ms); #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED extern int ble_controller_deinit(void); extern int ble_controller_enable(uint8_t mode); @@ -196,7 +197,7 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED -const static uint32_t log_bufs_size[] = {6144, 1024, 2048}; +const static uint32_t log_bufs_size[] = {CONFIG_BT_LE_LOG_CTRL_BUF1_SIZE, CONFIG_BT_LE_LOG_HCI_BUF_SIZE, CONFIG_BT_LE_LOG_CTRL_BUF2_SIZE}; #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED /* This variable tells if BLE is running */ @@ -1157,9 +1158,10 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, b void esp_ble_controller_log_dump_all(bool output) { - portMUX_TYPE spinlock; + portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL_SAFE(&spinlock); + esp_panic_handler_reconfigure_wdts(5000); BT_ASSERT_PRINT("\r\n[DUMP_START:"); ble_log_async_output_dump_all(output); BT_ASSERT_PRINT("]\r\n"); diff --git a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib index b25c2b9996..d238d53d4a 160000 --- a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib +++ b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib @@ -1 +1 @@ -Subproject commit b25c2b9996a829c012be9bf4d8b057c6ddf265d7 +Subproject commit d238d53d4aef846142e937b0bf344b36e4704080 diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index 848df55b08..0f0f3ff7e5 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit 848df55b08dcdad33c7dd9dbc25deacd2fc5e489 +Subproject commit 0f0f3ff7e54d9f5499781bc4f3afa2ac40892598 diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index 831e062f44..ef7a15381d 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit 831e062f4480a5311ab04b8f06fc7512680568f7 +Subproject commit ef7a15381de3b90b58fc2053f654edf4bd8c82e0 diff --git a/components/bt/include/esp32c2/include/esp_bt.h b/components/bt/include/esp32c2/include/esp_bt.h index 366c789218..175c115438 100644 --- a/components/bt/include/esp32c2/include/esp_bt.h +++ b/components/bt/include/esp32c2/include/esp_bt.h @@ -223,7 +223,7 @@ typedef struct { uint8_t cca_drop_mode; /*!< CCA drop mode */ int8_t cca_low_tx_pwr; /*!< Low TX power setting for CCA */ uint8_t main_xtal_freq; /*!< Main crystal frequency */ - uint32_t version_num; /*!< Version number */ + uint8_t version_num; /*!< Version number */ uint8_t ignore_wl_for_direct_adv; /*!< Ignore the white list for directed advertising */ uint32_t config_magic; /*!< Configuration magic value */ } esp_bt_controller_config_t; @@ -275,7 +275,7 @@ typedef struct { .dis_scan_backoff = NIMBLE_DISABLE_SCAN_BACKOFF, \ .ble_scan_classify_filter_enable = 0, \ .main_xtal_freq = CONFIG_XTAL_FREQ, \ - .version_num = efuse_hal_chip_revision(), \ + .version_num = esp_ble_get_chip_rev_version(), \ .ignore_wl_for_direct_adv = 0, \ .config_magic = CONFIG_MAGIC, \ } diff --git a/components/bt/porting/npl/freertos/src/npl_os_freertos.c b/components/bt/porting/npl/freertos/src/npl_os_freertos.c index f93b1fc18c..401cf408a2 100644 --- a/components/bt/porting/npl/freertos/src/npl_os_freertos.c +++ b/components/bt/porting/npl/freertos/src/npl_os_freertos.c @@ -133,6 +133,8 @@ npl_freertos_eventq_init(struct ble_npl_eventq *evq) memset(eventq, 0, sizeof(*eventq)); eventq->q = xQueueCreate(ble_freertos_total_event_cnt, sizeof(struct ble_npl_eventq *)); BLE_LL_ASSERT(eventq->q); + } else { + xQueueReset(eventq->q); } #else if(!evq->eventq) { @@ -142,6 +144,8 @@ npl_freertos_eventq_init(struct ble_npl_eventq *evq) memset(eventq, 0, sizeof(*eventq)); eventq->q = xQueueCreate(ble_freertos_total_event_cnt, sizeof(struct ble_npl_eventq *)); BLE_LL_ASSERT(eventq->q); + } else { + xQueueReset(eventq->q); } #endif }