deinit BB MAC back memory when they are not used

This commit is contained in:
Jack 2022-05-29 00:13:32 +08:00
parent 1781ce3b98
commit 7a8b63869f
4 changed files with 27 additions and 0 deletions

View File

@ -1244,6 +1244,9 @@ esp_err_t esp_bt_controller_deinit(void)
phy_init_flag();
esp_bt_power_domain_off();
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_deinit();
#endif
free(osi_funcs_p);
osi_funcs_p = NULL;

View File

@ -181,6 +181,11 @@ void esp_phy_load_cal_and_init(void);
*/
void esp_mac_bb_pd_mem_init(void);
/**
* @brief Deinitialize backup memory for MAC and Baseband power up/down
*/
void esp_mac_bb_pd_mem_deinit(void);
/**
* @brief Power up MAC and Baseband
*/

View File

@ -79,6 +79,8 @@ static uint32_t* s_phy_digital_regs_mem = NULL;
#if CONFIG_MAC_BB_PD
uint32_t* s_mac_bb_pd_mem = NULL;
/* Reference count of MAC BB backup memory */
static uint8_t s_backup_mem_ref = 0;
#endif
#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
@ -317,6 +319,7 @@ void esp_mac_bb_pd_mem_init(void)
{
_lock_acquire(&s_phy_access_lock);
s_backup_mem_ref++;
if (s_mac_bb_pd_mem == NULL) {
s_mac_bb_pd_mem = (uint32_t *)heap_caps_malloc(SOC_MAC_BB_PD_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
}
@ -324,6 +327,19 @@ void esp_mac_bb_pd_mem_init(void)
_lock_release(&s_phy_access_lock);
}
void esp_mac_bb_pd_mem_deinit(void)
{
_lock_acquire(&s_phy_access_lock);
s_backup_mem_ref--;
if (s_backup_mem_ref == 0) {
free(s_mac_bb_pd_mem);
s_mac_bb_pd_mem = NULL;
}
_lock_release(&s_phy_access_lock);
}
IRAM_ATTR void esp_mac_bb_power_up(void)
{
if (s_mac_bb_pd_mem == NULL) {

View File

@ -129,6 +129,9 @@ esp_err_t esp_wifi_deinit(void)
phy_init_flag();
#endif
esp_wifi_power_domain_off();
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_deinit();
#endif
return err;
}