Skip to content

Commit

Permalink
Merge branch 'feature/bringup_esp32c6_light_sleep_pd_modem' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

esp32c6: support light_sleep (Stage 3: support Modem power down)

Closes WIFI-5150, WIFI-5151, and IDF-5679

See merge request espressif/esp-idf!22236
  • Loading branch information
esp-wzh committed Mar 5, 2023
2 parents 6987526 + 15eb193 commit af805df
Show file tree
Hide file tree
Showing 62 changed files with 1,323 additions and 660 deletions.
4 changes: 2 additions & 2 deletions components/esp_hw_support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if(NOT BOOTLOADER_BUILD)
"rtc_module.c"
"sleep_modes.c"
"sleep_gpio.c"
"sleep_mac_bb.c"
"sleep_modem.c"
"regi2c_ctrl.c"
"port/${target}/io_mux.c"
"port/${target}/clk_tree.c"
Expand All @@ -38,7 +38,7 @@ if(NOT BOOTLOADER_BUILD)
endif()

if(CONFIG_SOC_PAU_SUPPORTED)
list(APPEND srcs "sleep_retention.c" "sleep_peripheral.c" "sleep_clock.c")
list(APPEND srcs "sleep_retention.c" "sleep_system_peripheral.c" "sleep_clock.c")
endif()

# [refactor-todo]: requires "driver" for GPIO and RTC (by sleep_gpio and sleep_modes)
Expand Down
13 changes: 9 additions & 4 deletions components/esp_hw_support/include/esp_private/esp_pmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ extern "C" {
#include "hal/pmu_hal.h"
#include "pmu_param.h"

#define RTC_SLEEP_PD_DIG PMU_SLEEP_PD_TOP //!< Deep sleep (power down digital domain)
#define RTC_SLEEP_PD_DIG PMU_SLEEP_PD_TOP //!< Deep sleep (power down digital domain, includes all power domains
// except CPU, Modem, LP peripheral, AON,VDDSDIO, MEM and clock power domains)
#define RTC_SLEEP_PD_RTC_PERIPH PMU_SLEEP_PD_LP_PERIPH //!< Power down RTC peripherals
// #define RTC_SLEEP_PD_RTC_SLOW_MEM BIT(2) //!< Power down RTC SLOW memory
// #define RTC_SLEEP_PD_RTC_FAST_MEM BIT(3) //!< Power down RTC FAST memory
// #define RTC_SLEEP_PD_RTC_MEM_FOLLOW_CPU BIT(4) //!< RTC FAST and SLOW memories are automatically powered up and down along with the CPU
#define RTC_SLEEP_PD_VDDSDIO PMU_SLEEP_PD_VDDSDIO //!< Power down VDDSDIO regulator
#define RTC_SLEEP_PD_CPU PMU_SLEEP_PD_CPU //!< Power down CPU when in lightsleep, but not restart
#define RTC_SLEEP_PD_DIG_PERIPH PMU_SLEEP_PD_HP_PERIPH //!< Power down DIG peripherals
Expand Down Expand Up @@ -151,6 +149,13 @@ void pmu_sleep_enable_regdma_backup(void);
*/
void pmu_sleep_disable_regdma_backup(void);

/**
* @brief Get sleep PLL enable status
*
* @return true if PLL is enabled by PMU in modem state
*/
bool pmu_sleep_pll_already_enabled(void);

/**
* @brief Calculate the hardware time overhead during sleep to compensate for sleep time
*
Expand Down
2 changes: 2 additions & 0 deletions components/esp_hw_support/include/esp_private/esp_regdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {

#define ENTRY(n) (BIT(n))

#define REGDMA_PHY_LINK(_pri) ((0x00 << 8) | _pri)
#define REGDMA_PCR_LINK(_pri) ((0x01 << 8) | _pri)
#define REGDMA_MODEMSYSCON_LINK(_pri) ((0x02 << 8) | _pri)

Expand All @@ -38,6 +39,7 @@ extern "C" {
#define REGDMA_IOMUX_LINK(_pri) ((0x12 << 8) | _pri)
#define REGDMA_SPIMEM_LINK(_pri) ((0x13 << 8) | _pri)
#define REGDMA_SYSTIMER_LINK(_pri) ((0x14 << 8) | _pri)
#define REGDMA_MODEM_FE_LINK(_pri) ((0xFF << 8) | _pri)

typedef enum {
REGDMA_LINK_PRI_0 = 0,
Expand Down
10 changes: 10 additions & 0 deletions components/esp_hw_support/include/esp_private/sleep_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ extern "C" {
*/
bool cpu_domain_pd_allowed(void);

/**
* @brief Configure the parameters of the CPU domain during the sleep process
*
* @param light_sleep_enable true for enable light sleep mode, false for disable light sleep mode
*
* @return
* - ESP_OK on success
*/
esp_err_t sleep_cpu_configure(bool light_sleep_enable);

#endif

#if SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_RTCCNTL
Expand Down
43 changes: 0 additions & 43 deletions components/esp_hw_support/include/esp_private/sleep_mac_bb.h

This file was deleted.

152 changes: 152 additions & 0 deletions components/esp_hw_support/include/esp_private/sleep_modem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "sdkconfig.h"
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file sleep_modem.h
*
* This file contains declarations of MAC and baseband power consumption related functions in light sleep mode.
*/

#if CONFIG_MAC_BB_PD

/**
* @brief A callback function completes MAC and baseband power down operation
*
* In light sleep mode, execute Wi-Fi and Bluetooth module MAC and baseband
* power down and backup register configuration information operations.
*/
void mac_bb_power_down_cb_execute(void);

/**
* @brief A callback function completes MAC and baseband power up operation
*
* In light sleep mode, execute Wi-Fi and Bluetooth module MAC and baseband
* power up and restore register configuration information operations.
*/
void mac_bb_power_up_cb_execute(void);

#endif // CONFIG_MAC_BB_PD

#if SOC_PM_SUPPORT_PMU_MODEM_STATE

/**
* @brief Get WiFi modem state
*
* @return true or false for WiFi modem state is enabled or disabled
*/
bool sleep_modem_wifi_modem_state_enabled(void);

#endif /* SOC_PM_SUPPORT_PMU_MODEM_STATE */

/**
* @brief Whether the current target allows Modem or the TOP power domain to be powered off during light sleep
*
* During light sleep on some targets, it is possible to power OFF the Modem or TOP
* power domains in order to further lower power power consumption. However, this
* can only occur on targets that support REGDMA for modem (WiFi, Bluetooth,
* IEEE802.15.4) retention.
*/
bool modem_domain_pd_allowed(void);

/**
* @brief Get the reject trigger signal of Modem system
*
* @return the reject trigger signal of Modem system.
*/
uint32_t sleep_modem_reject_triggers(void);

/**
* @brief Configure the parameters of the modem subsytem during the sleep process
*
* In light sleep mode, the wake-up early time of the WiFi module and the TBTT
* interrupt early time (trigger enabling RF) are determined by the maximum and
* minimum frequency of system (higher system frequency means less time to wake
* up and enable RF).
* For the esp32c6 SOC, the modem state is strongly dependent on the light sleep
* mode, and the modem state will be enabled only when light sleep is enabled
* and the `CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP` is configured in menuconfig.
*
* @param max_freq_mhz the maximum frequency of system
* @param min_freq_mhz the minimum frequency of system
* @param light_sleep_enable ture or false for enable or disable light sleep mode, respectively
*
* @return
* - ESP_OK on success
*/
esp_err_t sleep_modem_configure(int max_freq_mhz, int min_freq_mhz, bool light_sleep_enable);

/**
* @brief Callback function type for peripherals to know light sleep wakeup overhead.
*
*/
typedef void (* inform_out_light_sleep_overhead_cb_t)(uint32_t);

/**
* @brief Register informing peripherals light sleep wakeup overhead time callback
*
* This function allows you to register a callback that informs the peripherals of
* the wakeup overhead time of light sleep.
* @param cb function to inform time
* @return
* - ESP_OK on success
* - ESP_ERR_NO_MEM if no more callback slots are available
*/
esp_err_t esp_pm_register_inform_out_light_sleep_overhead_callback(inform_out_light_sleep_overhead_cb_t cb);

/**
* @brief Unregister informing peripherals light sleep wakeup overhead time callback
*
* This function allows you to unregister a callback that informs the peripherals of
* the wakeup overhead time of light sleep.
* @param cb function to inform time
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if the given callback hasn't been registered before
*/
esp_err_t esp_pm_unregister_inform_out_light_sleep_overhead_callback(inform_out_light_sleep_overhead_cb_t cb);

/**
* @brief A callback that informs the peripherals of the wakeup overhead time of light sleep
*
* @param out_light_sleep_time wakeup overhead time of light sleep
*/
void periph_inform_out_light_sleep_overhead(uint32_t out_light_sleep_time);

/**
* @brief Callback function type for peripherals to know light sleep default parameters
*/
typedef void (* update_light_sleep_default_params_config_cb_t)(int, int);

/**
* @brief Register peripherals light sleep default parameters configure callback
*
* This function allows you to register a callback that configure the peripherals
* of default parameters of light sleep
* @param cb function to update default parameters
*/
void esp_pm_register_light_sleep_default_params_config_callback(update_light_sleep_default_params_config_cb_t cb);

/**
* @brief Unregister peripherals light sleep default parameters configure Callback
*
* This function allows you to unregister a callback that configure the peripherals
* of default parameters of light sleep
*/
void esp_pm_unregister_light_sleep_default_params_config_callback(void);

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
#endif

/**
* @file sleep_peripheral.h
* @file sleep_sys_periph.h
*
* This file contains declarations of digital peripheral retention related functions in light sleep mode.
*/
Expand All @@ -30,13 +30,13 @@ extern "C" {
bool peripheral_domain_pd_allowed(void);

/**
* @brief Digital peripheral power down initialize\
* @brief Digital peripheral power down initialize
*
* @return ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid sleep_retention_entries_create args
* No memory for the retention link
*/
void sleep_peripheral_retention_init(void);
void sleep_sys_periph_retention_init(void);

#ifdef __cplusplus
}
Expand Down
17 changes: 17 additions & 0 deletions components/esp_hw_support/include/esp_sleep.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ typedef enum {
#if SOC_PM_SUPPORT_VDDSDIO_PD
ESP_PD_DOMAIN_VDDSDIO, //!< VDD_SDIO
#endif
#if SOC_PM_SUPPORT_MODEM_PD
ESP_PD_DOMAIN_MODEM, //!< MODEM, includes WiFi, Bluetooth and IEEE802.15.4
#endif
#if SOC_PM_SUPPORT_TOP_PD
ESP_PD_DOMAIN_TOP, //!< SoC TOP
#endif
Expand Down Expand Up @@ -356,6 +359,20 @@ esp_err_t esp_sleep_enable_wifi_wakeup(void);
*/
esp_err_t esp_sleep_disable_wifi_wakeup(void);

/**
* @brief Enable beacon wakeup by WiFi MAC, it will wake up the system into modem state
* @return
* - ESP_OK on success
*/
esp_err_t esp_sleep_enable_wifi_beacon_wakeup(void);

/**
* @brief Disable beacon wakeup by WiFi MAC
* @return
* - ESP_OK on success
*/
esp_err_t esp_sleep_disable_wifi_beacon_wakeup(void);

/**
* @brief Get the bit mask of GPIOs which caused wakeup (ext1)
*
Expand Down
2 changes: 2 additions & 0 deletions components/esp_hw_support/linker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ entries:
rtc_time (noflash_text)
if SOC_PMU_SUPPORTED = y:
pmu_sleep (noflash)
if PM_SLP_IRAM_OPT = y && IDF_TARGET_ESP32 = n:
sleep_modem:periph_inform_out_light_sleep_overhead (noflash)
if IDF_TARGET_ESP32 = y || IDF_TARGET_ESP32S2 = y:
rtc_wdt (noflash_text)
if PERIPH_CTRL_FUNC_IN_IRAM = y:
Expand Down
2 changes: 1 addition & 1 deletion components/esp_hw_support/port/esp32c6/pmu_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ const pmu_hp_system_analog_param_t * pmu_hp_system_analog_param_default(pmu_hp_m
.hp_sleep2active_retention_en = 0, \
.hp_modem2active_retention_en = 0, \
.hp_sleep2active_backup_clk_sel = 0, \
.hp_modem2active_backup_clk_sel = 0, \
.hp_modem2active_backup_clk_sel = 1, \
.hp_sleep2active_backup_mode = PMU_HP_RETENTION_REGDMA_CONFIG(0, 0), \
.hp_modem2active_backup_mode = PMU_HP_RETENTION_REGDMA_CONFIG(0, 2), \
.hp_sleep2active_backup_en = 0, \
Expand Down
Loading

0 comments on commit af805df

Please sign in to comment.