From e357de54062b8271dfef9e4dd2e5086c340b832a Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 13 Mar 2023 20:45:48 +0800 Subject: [PATCH] deep sleep: close rf to optimize sleep current --- components/esp_hw_support/sleep_modes.c | 8 +++++++- components/esp_phy/include/esp_phy_init.h | 6 ++++++ components/esp_phy/src/phy_init.c | 5 +++++ docs/en/api-reference/system/sleep_modes.rst | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index c4de8ae020..fd74815448 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -427,7 +427,13 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) } #endif - if (!deep_sleep) { + if (deep_sleep) { + extern bool esp_phy_is_initialized(void); + if (esp_phy_is_initialized()){ + extern void phy_close_rf(void); + phy_close_rf(); + } + } else { misc_modules_sleep_prepare(); } diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index bcf3e289d3..1422b43245 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -150,6 +150,12 @@ esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_da */ esp_err_t esp_phy_erase_cal_data_in_nvs(void); +/** + * @brief Get phy initialize status + * @return return true if phy is already initialized. + */ +bool esp_phy_is_initialized(void); + /** * @brief Enable PHY and RF module * diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index da7d11bdf3..10f9c780bd 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -219,6 +219,11 @@ static inline void phy_digital_regs_load(void) } } +bool esp_phy_is_initialized(void) +{ + return s_is_phy_calibrated; +} + void esp_phy_enable(void) { _lock_acquire(&s_phy_access_lock); diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index f40ab7b619..a00e5e616a 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -31,7 +31,7 @@ Once wakeup sources are configured, application can enter sleep mode using :cpp: WiFi/BT and sleep modes ----------------------- - In deep sleep and light sleep modes, wireless peripherals are powered down. Before entering deep sleep or light sleep modes, applications must disable WiFi and BT using appropriate calls (:cpp:func:`esp_bluedroid_disable`, :cpp:func:`esp_bt_controller_disable`, :cpp:func:`esp_wifi_stop`). WiFi and BT connections will not be maintained in deep sleep or light sleep, even if these functions are not called. + In deep sleep and light sleep modes, wireless peripherals are powered down. Before entering light sleep modes, applications must disable WiFi and BT using appropriate calls (:cpp:func:`esp_bluedroid_disable`, :cpp:func:`esp_bt_controller_disable`, :cpp:func:`esp_wifi_stop`). WiFi and BT connections will not be maintained in deep sleep or light sleep, even if these functions are not called. .. only:: not SOC_BT_SUPPORTED