mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 20:54:32 +02:00
feat(ble): support memory allocation check debug feature on ESP32-C2
(cherry picked from commit 7ef90d4113
)
Co-authored-by: cjin <jinchen@espressif.com>
This commit is contained in:
@@ -281,94 +281,103 @@ 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
|
||||
Enable controller log module
|
||||
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
|
||||
Enable hci 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
|
||||
|
||||
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_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
|
||||
Store ble controller logs to flash memory.
|
||||
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
|
||||
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_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
|
||||
Configure the size of the first BLE controller LOG buffer.
|
||||
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_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_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_MEM_CHECK_ENABLED
|
||||
bool "Enable memory allocation check"
|
||||
default n
|
||||
help
|
||||
Used in internal tests only. Enable the memory allocation check.
|
||||
endmenu
|
||||
|
||||
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_LL_RESOLV_LIST_SIZE
|
||||
int "BLE LL Resolving list size"
|
||||
range 1 5
|
||||
|
@@ -1573,3 +1573,10 @@ 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)
|
||||
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
void ble_memory_count_limit_set(uint16_t count_limit)
|
||||
{
|
||||
bt_osi_mem_count_limit_set(count_limit);
|
||||
}
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
|
@@ -446,6 +446,10 @@ uint32_t esp_bt_get_lpclk_freq(void);
|
||||
|
||||
void esp_bt_set_lpclk_freq(uint32_t clk_freq);
|
||||
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
void ble_memory_count_limit_set(uint16_t count_limit);
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -19,3 +19,7 @@ void *bt_osi_mem_malloc_internal(size_t size);
|
||||
void *bt_osi_mem_calloc_internal(size_t n, size_t size);
|
||||
|
||||
void bt_osi_mem_free(void *ptr);
|
||||
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
void bt_osi_mem_count_limit_set(uint16_t count_limit);
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -11,6 +11,10 @@
|
||||
#include <assert.h>
|
||||
|
||||
static uint8_t log_count;
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
static uint16_t mem_count_limit = 0;
|
||||
static uint16_t curr_mem_count;
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
IRAM_ATTR void *bt_osi_mem_malloc(size_t size)
|
||||
{
|
||||
void *mem = NULL;
|
||||
@@ -49,11 +53,27 @@ IRAM_ATTR void *bt_osi_mem_calloc(size_t n, size_t size)
|
||||
|
||||
IRAM_ATTR void *bt_osi_mem_malloc_internal(size_t size)
|
||||
{
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
if (mem_count_limit) {
|
||||
if (curr_mem_count > mem_count_limit) {
|
||||
return NULL;
|
||||
}
|
||||
curr_mem_count ++;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA);
|
||||
}
|
||||
|
||||
IRAM_ATTR void *bt_osi_mem_calloc_internal(size_t n, size_t size)
|
||||
{
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
if (mem_count_limit) {
|
||||
if (curr_mem_count > mem_count_limit) {
|
||||
return NULL;
|
||||
}
|
||||
curr_mem_count ++;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA);
|
||||
}
|
||||
|
||||
@@ -61,3 +81,11 @@ IRAM_ATTR void bt_osi_mem_free(void *ptr)
|
||||
{
|
||||
heap_caps_free(ptr);
|
||||
}
|
||||
|
||||
#if CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
void bt_osi_mem_count_limit_set(uint16_t count_limit)
|
||||
{
|
||||
mem_count_limit = count_limit;
|
||||
curr_mem_count = 0;
|
||||
}
|
||||
#endif // CONFIG_BT_LE_MEM_CHECK_ENABLED
|
||||
|
Reference in New Issue
Block a user