fix the bug that some memory leaked in phy after wifi/ble deinit

This commit is contained in:
Jack 2022-06-16 20:27:59 +08:00
parent c8854b09e3
commit cb0dd5cc75
7 changed files with 57 additions and 8 deletions

View File

@ -1629,6 +1629,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error;
}
esp_phy_pd_mem_init();
esp_bt_power_domain_on();
btdm_controller_mem_init();
@ -1795,6 +1797,8 @@ esp_err_t esp_bt_controller_deinit(void)
esp_bt_power_domain_off();
esp_phy_pd_mem_deinit();
return ESP_OK;
}

View File

@ -639,6 +639,7 @@ esp_err_t esp_bt_controller_init(struct esp_bt_controller_config_t *cfg)
/* Initialize default event queue */
ble_npl_eventq_init(nimble_port_get_dflt_eventq());
#endif
esp_phy_pd_mem_init();
periph_module_enable(PERIPH_BT_MODULE);
// init phy
@ -705,6 +706,7 @@ esp_err_t esp_bt_controller_deinit(void)
npl_freertos_mempool_deinit();
esp_phy_disable();
esp_phy_pd_mem_deinit();
ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;

View File

@ -968,6 +968,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_init();
#endif
esp_phy_pd_mem_init();
esp_bt_power_domain_on();
btdm_controller_mem_init();
@ -1247,6 +1248,7 @@ esp_err_t esp_bt_controller_deinit(void)
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_deinit();
#endif
esp_phy_pd_mem_deinit();
free(osi_funcs_p);
osi_funcs_p = NULL;

View File

@ -936,6 +936,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_init();
#endif
esp_phy_pd_mem_init();
esp_bt_power_domain_on();
btdm_controller_mem_init();
@ -1207,6 +1208,10 @@ esp_err_t esp_bt_controller_deinit(void)
#endif
esp_bt_power_domain_off();
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_deinit();
#endif
esp_phy_pd_mem_deinit();
free(osi_funcs_p);
osi_funcs_p = NULL;

View File

@ -175,6 +175,16 @@ void esp_phy_disable(void);
*/
void esp_phy_load_cal_and_init(void);
/**
* @brief Initialize backup memory for Phy power up/down
*/
void esp_phy_pd_mem_init(void);
/**
* @brief Deinitialize backup memory for Phy power up/down
*/
void esp_phy_pd_mem_deinit(void);
#if CONFIG_MAC_BB_PD
/**
* @brief Initialize backup memory for MAC and Baseband power up/down

View File

@ -76,11 +76,12 @@ static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED;
/* Memory to store PHY digital registers */
static uint32_t* s_phy_digital_regs_mem = NULL;
static uint8_t s_phy_backup_mem_ref = 0;
#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;
static uint8_t s_macbb_backup_mem_ref = 0;
#endif
#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
@ -209,10 +210,6 @@ IRAM_ATTR void esp_phy_common_clock_disable(void)
static inline void phy_digital_regs_store(void)
{
if (s_phy_digital_regs_mem == NULL) {
s_phy_digital_regs_mem = (uint32_t *)malloc(SOC_PHY_DIG_REGS_MEM_SIZE);
}
if (s_phy_digital_regs_mem != NULL) {
phy_dig_reg_backup(true, s_phy_digital_regs_mem);
}
@ -314,12 +311,38 @@ void esp_wifi_bt_power_domain_off(void)
#endif
}
void esp_phy_pd_mem_init(void)
{
_lock_acquire(&s_phy_access_lock);
s_phy_backup_mem_ref++;
if (s_phy_digital_regs_mem == NULL) {
s_phy_digital_regs_mem = (uint32_t *)heap_caps_malloc(SOC_PHY_DIG_REGS_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
}
_lock_release(&s_phy_access_lock);
}
void esp_phy_pd_mem_deinit(void)
{
_lock_acquire(&s_phy_access_lock);
s_phy_backup_mem_ref--;
if (s_phy_backup_mem_ref == 0) {
free(s_phy_digital_regs_mem);
s_phy_digital_regs_mem = NULL;
}
_lock_release(&s_phy_access_lock);
}
#if CONFIG_MAC_BB_PD
void esp_mac_bb_pd_mem_init(void)
{
_lock_acquire(&s_phy_access_lock);
s_backup_mem_ref++;
s_macbb_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);
}
@ -331,8 +354,8 @@ void esp_mac_bb_pd_mem_deinit(void)
{
_lock_acquire(&s_phy_access_lock);
s_backup_mem_ref--;
if (s_backup_mem_ref == 0) {
s_macbb_backup_mem_ref--;
if (s_macbb_backup_mem_ref == 0) {
free(s_mac_bb_pd_mem);
s_mac_bb_pd_mem = NULL;
}

View File

@ -136,6 +136,8 @@ esp_err_t esp_wifi_deinit(void)
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_deinit();
#endif
esp_phy_pd_mem_deinit();
return err;
}
@ -245,6 +247,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
esp_mac_bb_pd_mem_init();
esp_wifi_internal_set_mac_sleep(true);
#endif
esp_phy_pd_mem_init();
#if CONFIG_IDF_TARGET_ESP32
s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time;
#endif