diff --git a/components/esp_hw_support/include/esp_private/sleep_modem.h b/components/esp_hw_support/include/esp_private/sleep_modem.h index 7601aeebd82b..2e84830b6d4f 100644 --- a/components/esp_hw_support/include/esp_private/sleep_modem.h +++ b/components/esp_hw_support/include/esp_private/sleep_modem.h @@ -56,6 +56,13 @@ void sleep_modem_wifi_do_phy_retention(bool restore); */ bool sleep_modem_wifi_modem_state_enabled(void); +/** + * @brief Get WiFi modem link done state + * + * @return true or false for WiFi modem link can be used to enable RF by REGDMA or can not be used + */ +bool sleep_modem_wifi_modem_link_done(void); + #endif /* SOC_PM_SUPPORT_PMU_MODEM_STATE */ /** diff --git a/components/esp_hw_support/sleep_modem.c b/components/esp_hw_support/sleep_modem.c index 086aed667add..d73f32845c2b 100644 --- a/components/esp_hw_support/sleep_modem.c +++ b/components/esp_hw_support/sleep_modem.c @@ -256,18 +256,21 @@ static __attribute__((unused)) void sleep_modem_wifi_modem_state_deinit(void) void IRAM_ATTR sleep_modem_wifi_do_phy_retention(bool restore) { if (restore) { - if (s_sleep_modem.wifi.modem_state_phy_done == 1) { - pau_regdma_trigger_modem_link_restore(); - } + pau_regdma_trigger_modem_link_restore(); } else { pau_regdma_trigger_modem_link_backup(); s_sleep_modem.wifi.modem_state_phy_done = 1; } } -bool sleep_modem_wifi_modem_state_enabled(void) +inline __attribute__((always_inline)) bool sleep_modem_wifi_modem_state_enabled(void) +{ + return (s_sleep_modem.wifi.phy_link != NULL); +} + +inline __attribute__((always_inline)) bool sleep_modem_wifi_modem_link_done(void) { - return (s_sleep_modem.wifi.phy_link != NULL) ? true : false; + return (s_sleep_modem.wifi.modem_state_phy_done == 1); } #endif /* SOC_PM_SUPPORT_PMU_MODEM_STATE */ @@ -303,7 +306,10 @@ static __attribute__((unused)) bool IRAM_ATTR sleep_modem_wifi_modem_state_skip_ { bool skip = false; #if SOC_PM_SUPPORT_PMU_MODEM_STATE - skip = (s_sleep_modem.wifi.phy_link != NULL) && (s_sleep_modem.wifi.modem_state_phy_done == 0); + /* To block the system from entering sleep before modem link done. In light + * sleep mode, the system may switch to modem state, which will cause + * hardware to fail to enable RF */ + skip = sleep_modem_wifi_modem_state_enabled() && !sleep_modem_wifi_modem_link_done(); #endif return skip; } diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 0e8fabfc5180..642754e36412 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -251,7 +251,7 @@ void esp_phy_enable(void) #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP extern bool pm_mac_modem_rf_already_enabled(void); if (!pm_mac_modem_rf_already_enabled()) { - if (sleep_modem_wifi_modem_state_enabled()) { + if (sleep_modem_wifi_modem_state_enabled() && sleep_modem_wifi_modem_link_done()) { sleep_modem_wifi_do_phy_retention(true); } else { phy_wakeup_init();