feat(ble): supported ble log v2 for ESP32-C2

This commit is contained in:
Zhou Xiao
2025-09-15 13:40:47 +08:00
parent 954e370bc0
commit 49bcc44e76
2 changed files with 116 additions and 59 deletions

View File

@@ -288,6 +288,14 @@ menu "Controller debug features"
help help
Enable controller log Enable controller log
config BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
bool "Utilize BLE Log v2 for controller log"
depends on BLE_LOG_ENABLED
default y
help
Utilize BLE Log v2 for controller log
if !BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
config BT_LE_CONTROLLER_LOG_CTRL_ENABLED config BT_LE_CONTROLLER_LOG_CTRL_ENABLED
bool "enable controller log module" bool "enable controller log module"
depends on BT_LE_CONTROLLER_LOG_ENABLED depends on BT_LE_CONTROLLER_LOG_ENABLED
@@ -356,6 +364,7 @@ menu "Controller debug features"
default 4096 default 4096
help help
Configure the size of the BLE HCI LOG buffer. Configure the size of the BLE HCI LOG buffer.
endif
config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE config BT_LE_CONTROLLER_LOG_WRAP_PANIC_HANDLER_ENABLE
bool "Enable wrap panic handler" bool "Enable wrap panic handler"

View File

@@ -66,9 +66,13 @@
#include "hal/efuse_ll.h" #include "hal/efuse_ll.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
#include "ble_log.h"
#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
#if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#include "ble_log/ble_log_spi_out.h" #include "ble_log/ble_log_spi_out.h"
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED #endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
/* Macro definition /* Macro definition
************************************************************************ ************************************************************************
@@ -207,12 +211,14 @@ static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv);
static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y, static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y,
const uint8_t *our_priv_key, uint8_t *out_dhkey); const uint8_t *our_priv_key, uint8_t *out_dhkey);
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
#if !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
#if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED
static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag); static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag);
#endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED #endif // !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED
#if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void); static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
/* Local variable definition /* Local variable definition
*************************************************************************** ***************************************************************************
@@ -224,9 +230,43 @@ void *g_ble_lll_rfmgmt_env_p;
static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE; static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED #if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
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};
static bool log_is_inited = false; static bool log_is_inited = false;
#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
/* TODO: Remove event handler dependency in lib */
static void void_handler(void) {}
/* TODO: Declare public interfaces in a public header */
void esp_bt_controller_log_deinit(void)
{
log_is_inited = false;
ble_log_deinit_simple();
ble_log_deinit();
}
esp_err_t esp_bt_controller_log_init(void)
{
if (log_is_inited) {
return ESP_OK;
}
if (!ble_log_init()) {
goto exit;
}
if (ble_log_init_simple(ble_log_write_hex_ll, void_handler) != 0) {
goto exit;
}
log_is_inited = true;
return ESP_OK;
exit:
esp_bt_controller_log_deinit();
return ESP_FAIL;
}
#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
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};
esp_err_t esp_bt_controller_log_init(void) esp_err_t esp_bt_controller_log_init(void)
{ {
if (log_is_inited) { if (log_is_inited) {
@@ -289,6 +329,7 @@ void esp_bt_controller_log_deinit(void)
log_is_inited = false; log_is_inited = false;
} }
#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
#if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #if CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
#include "esp_partition.h" #include "esp_partition.h"
@@ -413,6 +454,12 @@ void esp_bt_read_ctrl_log_from_flash(bool output)
} }
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE #endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
#if CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2
void esp_ble_controller_log_dump_all(bool output)
{
ble_log_dump_to_console();
}
#else /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
#if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED #if !CONFIG_BT_LE_CONTROLLER_LOG_SPI_OUT_ENABLED
static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag) static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, uint32_t len_append, const uint8_t *addr_append, uint32_t flag)
{ {
@@ -455,6 +502,7 @@ void esp_ble_controller_log_dump_all(bool output)
portEXIT_CRITICAL_SAFE(&spinlock); portEXIT_CRITICAL_SAFE(&spinlock);
#endif #endif
} }
#endif /* CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
#if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE #if CONFIG_BT_LE_CONTROLLER_LOG_TASK_WDT_USER_HANDLER_ENABLE
void esp_task_wdt_isr_user_handler(void) void esp_task_wdt_isr_user_handler(void)