mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 02:37:19 +02:00
support BLE memory release on ESP32C3 and ESP32S3
This commit is contained in:
@ -249,24 +249,18 @@ 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 char _bss_start_btdm;
|
||||
extern char _bss_end_btdm;
|
||||
extern char _data_start_btdm;
|
||||
extern char _data_end_btdm;
|
||||
extern uint32_t _data_start_btdm_rom;
|
||||
extern uint32_t _data_end_btdm_rom;
|
||||
|
||||
extern uint32_t _bt_bss_start;
|
||||
extern uint32_t _bt_bss_end;
|
||||
extern uint32_t _btdm_bss_start;
|
||||
extern uint32_t _btdm_bss_end;
|
||||
extern uint32_t _nimble_bss_start;
|
||||
extern uint32_t _nimble_bss_end;
|
||||
extern uint32_t _bt_data_start;
|
||||
extern uint32_t _bt_data_end;
|
||||
extern uint32_t _btdm_data_start;
|
||||
extern uint32_t _btdm_data_end;
|
||||
|
||||
extern char _bt_tmp_bss_start;
|
||||
extern char _bt_tmp_bss_end;
|
||||
extern uint32_t _nimble_data_start;
|
||||
extern uint32_t _nimble_data_end;
|
||||
|
||||
/* Local Function Declare
|
||||
*********************************************************************
|
||||
@ -316,6 +310,9 @@ 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_slp_tmr_callback(void *arg);
|
||||
|
||||
static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end);
|
||||
|
||||
/* Local variable definition
|
||||
***************************************************************************
|
||||
*/
|
||||
@ -876,13 +873,142 @@ static void btdm_controller_mem_init(void)
|
||||
|
||||
esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode)
|
||||
{
|
||||
ESP_LOGW(BTDM_LOG_TAG, "%s not implemented, return OK", __func__);
|
||||
intptr_t mem_start=(intptr_t) NULL, mem_end=(intptr_t) NULL;
|
||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (mode & ESP_BT_MODE_BLE) {
|
||||
/* if the addresses of rom btdm .data and .bss are consecutive,
|
||||
they are registered in the system heap as a piece of memory
|
||||
*/
|
||||
if(ets_rom_layout_p->data_end_btdm == ets_rom_layout_p->bss_start_btdm) {
|
||||
mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
} else {
|
||||
mem_start = (intptr_t)ets_rom_layout_p->bss_start_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->bss_end_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
|
||||
mem_start = (intptr_t)ets_rom_layout_p->data_start_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->data_end_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
}
|
||||
/* if the addresses of rom interface btdm .data and .bss are consecutive,
|
||||
they are registered in the system heap as a piece of memory
|
||||
*/
|
||||
if(ets_rom_layout_p->data_end_interface_btdm == ets_rom_layout_p->bss_start_interface_btdm) {
|
||||
mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
} else {
|
||||
mem_start = (intptr_t)ets_rom_layout_p->data_start_interface_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->data_end_interface_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
|
||||
mem_start = (intptr_t)ets_rom_layout_p->bss_start_interface_btdm;
|
||||
mem_end = (intptr_t)ets_rom_layout_p->bss_end_interface_btdm;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release rom interface btdm BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_mem_release(esp_bt_mode_t mode)
|
||||
{
|
||||
ESP_LOGW(BTDM_LOG_TAG, "%s not implemented, return OK", __func__);
|
||||
int ret;
|
||||
intptr_t mem_start, mem_end;
|
||||
|
||||
ret = esp_bt_controller_mem_release(mode);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (mode & ESP_BT_MODE_BLE) {
|
||||
/* if the addresses of btdm .bss and bt .bss are consecutive,
|
||||
they are registered in the system heap as a piece of memory
|
||||
*/
|
||||
if(_bt_bss_end == _btdm_bss_start) {
|
||||
mem_start = (intptr_t)&_bt_bss_start;
|
||||
mem_end = (intptr_t)&_btdm_bss_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
} else {
|
||||
mem_start = (intptr_t)&_bt_bss_start;
|
||||
mem_end = (intptr_t)&_bt_bss_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release BT BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
|
||||
mem_start = (intptr_t)&_btdm_bss_start;
|
||||
mem_end = (intptr_t)&_btdm_bss_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release BTDM BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
}
|
||||
/* if the addresses of btdm .data and bt .data are consecutive,
|
||||
they are registered in the system heap as a piece of memory
|
||||
*/
|
||||
if(_bt_data_end == _btdm_data_start) {
|
||||
mem_start = (intptr_t)&_bt_data_start;
|
||||
mem_end = (intptr_t)&_btdm_data_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
} else {
|
||||
mem_start = (intptr_t)&_bt_data_start;
|
||||
mem_end = (intptr_t)&_bt_data_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release BT Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
|
||||
mem_start = (intptr_t)&_btdm_data_start;
|
||||
mem_end = (intptr_t)&_btdm_data_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release BTDM Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
}
|
||||
|
||||
mem_start = (intptr_t)&_nimble_bss_start;
|
||||
mem_end = (intptr_t)&_nimble_bss_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release NimBLE BSS [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
mem_start = (intptr_t)&_nimble_data_start;
|
||||
mem_end = (intptr_t)&_nimble_data_end;
|
||||
if (mem_start != mem_end) {
|
||||
ESP_LOGD(BTDM_LOG_TAG, "Release NimBLE Data [0x%08x] - [0x%08x], len %d", mem_start, mem_end, mem_end - mem_start);
|
||||
ESP_ERROR_CHECK(try_heap_caps_add_region(mem_start, mem_end));
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user