fix(sleep_modem): fix lightsleep failure if enable lightsleep at phy disabled

pull/12330/head
liuning 2023-08-02 19:48:00 +08:00
rodzic 789569a982
commit 90698bf1f5
3 zmienionych plików z 43 dodań i 14 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -161,6 +161,25 @@ void esp_pm_register_light_sleep_default_params_config_callback(update_light_sle
*/
void esp_pm_unregister_light_sleep_default_params_config_callback(void);
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
/**
* @brief Init Wi-Fi modem state.
*
* This function init wifi modem state.
* @return
* - ESP_OK on success
* - ESP_ERR_NO_MEM if no memory for link
*/
esp_err_t sleep_modem_wifi_modem_state_init(void);
/**
* @brief Deinit Wi-Fi modem state.
*
* This function deinit wifi modem state.
*/
void sleep_modem_wifi_modem_state_deinit(void);
#endif
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -167,7 +167,7 @@ typedef struct sleep_modem_config {
static sleep_modem_config_t s_sleep_modem = { .wifi.phy_link = NULL, .wifi.flags = 0 };
static __attribute__((unused)) esp_err_t sleep_modem_wifi_modem_state_init(void)
__attribute__((unused)) esp_err_t sleep_modem_wifi_modem_state_init(void)
{
esp_err_t err = ESP_OK;
phy_i2c_master_command_attribute_t cmd;
@ -244,7 +244,7 @@ static __attribute__((unused)) esp_err_t sleep_modem_wifi_modem_state_init(void)
return err;
}
static __attribute__((unused)) void sleep_modem_wifi_modem_state_deinit(void)
__attribute__((unused)) void sleep_modem_wifi_modem_state_deinit(void)
{
if (s_sleep_modem.wifi.phy_link) {
regdma_link_destroy(s_sleep_modem.wifi.phy_link, 0);
@ -319,14 +319,13 @@ esp_err_t sleep_modem_configure(int max_freq_mhz, int min_freq_mhz, bool light_s
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
extern int esp_wifi_internal_mac_sleep_configure(bool, bool);
if (light_sleep_enable) {
if (sleep_modem_wifi_modem_state_init() == ESP_OK) {
if (sleep_modem_wifi_modem_state_enabled() == ESP_OK) {
esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
esp_wifi_internal_mac_sleep_configure(light_sleep_enable, true); /* require WiFi to enable automatically receives the beacon */
}
} else {
esp_wifi_internal_mac_sleep_configure(light_sleep_enable, false); /* require WiFi to disable automatically receives the beacon */
esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
sleep_modem_wifi_modem_state_deinit();
}
#endif
#if CONFIG_PM_SLP_DEFAULT_PARAMS_OPT

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -85,8 +85,10 @@ static bool s_is_phy_calibrated = false;
static bool s_is_phy_reg_stored = false;
/* Memory to store PHY digital registers */
static uint32_t* s_phy_digital_regs_mem = NULL;
static uint8_t s_phy_modem_init_ref = 0;
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
static uint8_t s_phy_modem_init_ref = 0;
#endif
#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
@ -349,23 +351,29 @@ void esp_wifi_bt_power_domain_off(void)
void esp_phy_modem_init(void)
{
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
_lock_acquire(&s_phy_access_lock);
s_phy_modem_init_ref++;
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
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);
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
sleep_modem_wifi_modem_state_init();
#endif // CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
_lock_release(&s_phy_access_lock);
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
}
void esp_phy_modem_deinit(void)
{
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
_lock_acquire(&s_phy_access_lock);
s_phy_modem_init_ref--;
if (s_phy_modem_init_ref == 0) {
#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
s_is_phy_reg_stored = false;
free(s_phy_digital_regs_mem);
s_phy_digital_regs_mem = NULL;
@ -374,11 +382,14 @@ void esp_phy_modem_deinit(void)
*/
#if CONFIG_IDF_TARGET_ESP32C3
phy_init_flag();
#endif
}
_lock_release(&s_phy_access_lock);
#endif // CONFIG_IDF_TARGET_ESP32C3
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
sleep_modem_wifi_modem_state_deinit();
#endif // CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
}
_lock_release(&s_phy_access_lock);
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
}
#if CONFIG_MAC_BB_PD