Merge branch 'feature/bringup_esp32c6_light_sleep_pd_cpu' into 'master'
esp32c6: support light_sleep (Stage 1: support CPU power down) See merge request espressif/esp-idf!21985
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if SOC_PMU_SUPPORTED
|
||||
#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_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
|
||||
#define RTC_SLEEP_PD_INT_8M PMU_SLEEP_PD_RC_FAST //!< Power down Internal 20M oscillator
|
||||
#define RTC_SLEEP_PD_XTAL PMU_SLEEP_PD_XTAL //!< Power down main XTAL
|
||||
|
||||
//These flags are not power domains, but will affect some sleep parameters
|
||||
#define RTC_SLEEP_DIG_USE_8M BIT(16)
|
||||
#define RTC_SLEEP_USE_ADC_TESEN_MONITOR BIT(17)
|
||||
#define RTC_SLEEP_NO_ULTRA_LOW BIT(18) //!< Avoid using ultra low power in deep sleep, in which RTCIO cannot be used as input, and RTCMEM can't work under high temperature
|
||||
|
||||
#define RTC_GPIO_TRIG_EN PMU_GPIO_WAKEUP_EN //!< GPIO wakeup
|
||||
#define RTC_TIMER_TRIG_EN PMU_LP_TIMER_WAKEUP_EN //!< Timer wakeup
|
||||
#define RTC_WIFI_TRIG_EN PMU_WIFI_SOC_WAKEUP_EN //!< WIFI wakeup (light sleep only)
|
||||
#define RTC_UART0_TRIG_EN PMU_UART0_WAKEUP_EN //!< UART0 wakeup (light sleep only)
|
||||
#define RTC_UART1_TRIG_EN PMU_UART1_WAKEUP_EN //!< UART1 wakeup (light sleep only)
|
||||
#define RTC_BT_TRIG_EN PMU_BLE_SOC_WAKEUP_EN //!< BT wakeup (light sleep only)
|
||||
#define RTC_USB_TRIG_EN PMU_USB_WAKEUP_EN
|
||||
#define RTC_XTAL32K_DEAD_TRIG_EN 0 // TODO
|
||||
#define RTC_BROWNOUT_DET_TRIG_EN 0 // TODO
|
||||
|
||||
/**
|
||||
* RTC_SLEEP_REJECT_MASK records sleep reject sources supported by chip
|
||||
*/
|
||||
#define RTC_SLEEP_REJECT_MASK (RTC_GPIO_TRIG_EN | \
|
||||
RTC_TIMER_TRIG_EN | \
|
||||
RTC_WIFI_TRIG_EN | \
|
||||
RTC_UART0_TRIG_EN | \
|
||||
RTC_UART1_TRIG_EN | \
|
||||
RTC_BT_TRIG_EN | \
|
||||
RTC_XTAL32K_DEAD_TRIG_EN | \
|
||||
RTC_USB_TRIG_EN | \
|
||||
RTC_BROWNOUT_DET_TRIG_EN)
|
||||
|
||||
|
||||
#define PMU_GPIO_WAKEUP_EN BIT(2)
|
||||
#define PMU_WIFI_BEACON_WAKEUP_EN BIT(3)
|
||||
#define PMU_LP_TIMER_WAKEUP_EN BIT(4)
|
||||
#define PMU_WIFI_SOC_WAKEUP_EN BIT(5)
|
||||
#define PMU_UART0_WAKEUP_EN BIT(6)
|
||||
#define PMU_UART1_WAKEUP_EN BIT(7)
|
||||
#define PMU_SDIO_WAKEUP_EN BIT(8)
|
||||
#define PMU_BLE_SOC_WAKEUP_EN BIT(10)
|
||||
#define PMU_USB_WAKEUP_EN BIT(14)
|
||||
|
||||
|
||||
#define PMU_SLEEP_PD_TOP BIT(0)
|
||||
#define PMU_SLEEP_PD_VDDSDIO BIT(1)
|
||||
#define PMU_SLEEP_PD_MODEM BIT(2)
|
||||
#define PMU_SLEEP_PD_HP_PERIPH BIT(3)
|
||||
#define PMU_SLEEP_PD_CPU BIT(4)
|
||||
#define PMU_SLEEP_PD_AON BIT(5)
|
||||
#define PMU_SLEEP_PD_MEM_G0 BIT(6)
|
||||
#define PMU_SLEEP_PD_MEM_G1 BIT(7)
|
||||
#define PMU_SLEEP_PD_MEM_G2 BIT(8)
|
||||
#define PMU_SLEEP_PD_MEM_G3 BIT(9)
|
||||
#define PMU_SLEEP_PD_XTAL BIT(10)
|
||||
#define PMU_SLEEP_PD_RC_FAST BIT(11)
|
||||
#define PMU_SLEEP_PD_XTAL32K BIT(12)
|
||||
#define PMU_SLEEP_PD_RC32K BIT(13)
|
||||
#define PMU_SLEEP_PD_LP_PERIPH BIT(14)
|
||||
|
||||
typedef struct {
|
||||
pmu_hal_context_t *hal;
|
||||
void *mc;
|
||||
} pmu_context_t;
|
||||
|
||||
pmu_context_t * PMU_instance(void);
|
||||
|
||||
typedef enum pmu_hp_sysclk_src {
|
||||
PMU_HP_SYSCLK_XTAL = 0,
|
||||
PMU_HP_SYSCLK_PLL,
|
||||
PMU_HP_SYSCLK_FOSC
|
||||
} pmu_hp_sysclk_src_t;
|
||||
|
||||
typedef enum pmu_sleep_protect_mode {
|
||||
PMU_SLEEP_PROTECT_HP_SLEEP = 0,
|
||||
PMU_SLEEP_PROTECT_XTAL,
|
||||
PMU_SLEEP_PROTECT_HP_LP_SLEEP,
|
||||
PMU_SLEEP_PROTECT_DISABLE
|
||||
} pmu_sleep_protect_mode_t;
|
||||
|
||||
typedef enum pmu_sleep_regdma_entry {
|
||||
PMU_SLEEP_REGDMA_ENTRY_0 = 0,
|
||||
PMU_SLEEP_REGDMA_ENTRY_1,
|
||||
PMU_SLEEP_REGDMA_ENTRY_2,
|
||||
PMU_SLEEP_REGDMA_ENTRY_3,
|
||||
PMU_SLEEP_REGDMA_ENTRY_MAX
|
||||
} pmu_sleep_regdma_entry_t;
|
||||
|
||||
/**
|
||||
* @brief PMU ICG modem code of HP system
|
||||
*/
|
||||
typedef enum {
|
||||
PMU_HP_ICG_MODEM_CODE_SLEEP = 0,
|
||||
PMU_HP_ICG_MODEM_CODE_MODEM = 1,
|
||||
PMU_HP_ICG_MODEM_CODE_ACTIVE = 2,
|
||||
} pmu_hp_icg_modem_mode_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable_regdma_backup.
|
||||
*/
|
||||
void pmu_sleep_enable_regdma_backup(void);
|
||||
|
||||
/**
|
||||
* @brief Disable_regdma_backup.
|
||||
*/
|
||||
void pmu_sleep_disable_regdma_backup(void);
|
||||
|
||||
/**
|
||||
* @brief Calculate the hardware time overhead during sleep to compensate for sleep time
|
||||
*
|
||||
* @param pd_flags flags indicates the power domain that will be powered down
|
||||
* @param slowclk_period re-calibrated slow clock period
|
||||
* @param fastclk_period re-calibrated fast clock period
|
||||
*
|
||||
* @return hardware time overhead in us
|
||||
*/
|
||||
uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t pd_flags, uint32_t slowclk_period, uint32_t fastclk_period);
|
||||
|
||||
/**
|
||||
* @brief Get default sleep configuration
|
||||
* @param config pmu_sleep_config instance
|
||||
* @param pd_flags flags indicates the power domain that will be powered down
|
||||
* @param adjustment total software and hardware time overhead
|
||||
* @param slowclk_period re-calibrated slow clock period in microseconds,
|
||||
* Q13.19 fixed point format
|
||||
* @param fastclk_period re-calibrated fast clock period in microseconds,
|
||||
* Q13.19 fixed point format
|
||||
* @param dslp configuration for deep sleep mode
|
||||
|
||||
* @return hardware time overhead in us
|
||||
*/
|
||||
const pmu_sleep_config_t* pmu_sleep_config_default(pmu_sleep_config_t *config, uint32_t pd_flags, uint32_t adjustment, uint32_t slowclk_period, uint32_t fastclk_period, bool dslp);
|
||||
|
||||
/**
|
||||
* @brief Prepare the chip to enter sleep mode
|
||||
*
|
||||
* This function configures various power/analog parameters and lp/lp system configuration
|
||||
* used in sleep state machines
|
||||
*
|
||||
* This function does not actually enter sleep mode; this is done using
|
||||
* pmu_sleep_start function. Software may do some other actions between
|
||||
* pmu_sleep_init and pmu_sleep_start, such as set wakeup timer and configure
|
||||
* wakeup sources.
|
||||
*
|
||||
* @param config sleep mode configuration
|
||||
*
|
||||
* @param dslp is initialize for deep sleep mode
|
||||
*/
|
||||
void pmu_sleep_init(const pmu_sleep_config_t *config, bool dslp);
|
||||
|
||||
/**
|
||||
* @brief Enter deep or light sleep mode
|
||||
*
|
||||
* This function enters the sleep mode previously configured using pmu_sleep_init
|
||||
* function. Before entering sleep, software should configure wake up sources
|
||||
* appropriately (set up GPIO wakeup registers, timer wakeup registers,
|
||||
* and so on).
|
||||
*
|
||||
* If deep sleep mode was configured using pmu_sleep_init, and sleep is not
|
||||
* rejected by hardware (based on reject_opt flags), this function never returns.
|
||||
* When the chip wakes up from deep sleep, CPU is reset and execution starts
|
||||
* from ROM bootloader.
|
||||
*
|
||||
* If light sleep mode was configured using pmu_sleep_init, this function
|
||||
* returns on wakeup, or if sleep is rejected by hardware.
|
||||
*
|
||||
* @param wakeup_opt bit mask wake up reasons to enable (RTC_xxx_TRIG_EN flags
|
||||
* combined with OR)
|
||||
* @param reject_opt bit mask of sleep reject reasons, used to
|
||||
* prevent wakeup source set before the sleep request)
|
||||
* @param lslp_mem_inf_fpu If non-zero then the low power config is restored
|
||||
* immediately on wake. Recommended for light sleep,
|
||||
* has no effect if the system goes into deep sleep.
|
||||
*
|
||||
* @return non-zero if sleep was rejected by hardware
|
||||
*/
|
||||
uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp);
|
||||
|
||||
/**
|
||||
* @brief Initialize PMU related power/clock/digital parameters and functions
|
||||
*/
|
||||
void pmu_init(void);
|
||||
|
||||
|
||||
#endif //#if SOC_PMU_SUPPORTED
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file sleep_cpu.h
|
||||
*
|
||||
* This file contains declarations of cpu retention related functions in light sleep mode.
|
||||
*/
|
||||
|
||||
#if SOC_PM_SUPPORT_CPU_PD
|
||||
|
||||
/**
|
||||
* @brief Whether to allow the cpu power domain to be powered off.
|
||||
*
|
||||
* In light sleep mode, only when the system can provide enough memory
|
||||
* for cpu retention, the cpu power domain can be powered off.
|
||||
*/
|
||||
bool cpu_domain_pd_allowed(void);
|
||||
|
||||
#endif
|
||||
|
||||
#if SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_RTCCNTL
|
||||
|
||||
/**
|
||||
* @brief Enable cpu retention of some modules.
|
||||
*
|
||||
* In light sleep mode, before the system goes to sleep, enable the cpu
|
||||
* retention of modules such as CPU and I/D-cache tag memory.
|
||||
*/
|
||||
void sleep_enable_cpu_retention(void);
|
||||
|
||||
/**
|
||||
* @brief Disable cpu retention of some modules.
|
||||
*
|
||||
* In light sleep mode, after the system exits sleep, disable the cpu
|
||||
* retention of moudles such as CPU and I/D-cache tag memory.
|
||||
*/
|
||||
void sleep_disable_cpu_retention(void);
|
||||
|
||||
#endif // SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_RTCCNTL
|
||||
|
||||
|
||||
#if SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_SW
|
||||
|
||||
esp_err_t esp_sleep_cpu_retention(uint32_t (*goto_sleep)(uint32_t, uint32_t, uint32_t, bool),
|
||||
uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp);
|
||||
|
||||
#endif // SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_SW
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file sleep_retention.h
|
||||
*
|
||||
* This file contains declarations of memory retention related functions in light sleeo mode.
|
||||
*/
|
||||
|
||||
#if SOC_PM_SUPPORT_CPU_PD
|
||||
|
||||
/**
|
||||
* @brief Whether to allow the cpu power domain to be powered off.
|
||||
*
|
||||
* In light sleep mode, only when the system can provide enough memory
|
||||
* for cpu retention, the cpu power domain can be powered off.
|
||||
*/
|
||||
bool cpu_domain_pd_allowed(void);
|
||||
|
||||
#endif
|
||||
|
||||
#if SOC_PM_SUPPORT_CPU_PD || SOC_PM_SUPPORT_TAGMEM_PD
|
||||
|
||||
/**
|
||||
* @brief Enable memory retention of some modules.
|
||||
*
|
||||
* In light sleep mode, before the system goes to sleep, enable the memory
|
||||
* retention of modules such as CPU and I/D-cache tag memory.
|
||||
*/
|
||||
void sleep_enable_memory_retention(void);
|
||||
|
||||
/**
|
||||
* @brief Disable memory retention of some modules.
|
||||
*
|
||||
* In light sleep mode, after the system exits sleep, disable the memory
|
||||
* retention of moudles such as CPU and I/D-cache tag memory.
|
||||
*/
|
||||
void sleep_disable_memory_retention(void);
|
||||
|
||||
#endif // SOC_PM_SUPPORT_CPU_PD || SOC_PM_SUPPORT_TAGMEM_PD
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -48,10 +48,10 @@ typedef enum {
|
||||
#endif
|
||||
ESP_PD_DOMAIN_XTAL, //!< XTAL oscillator
|
||||
#if SOC_PM_SUPPORT_XTAL32K_PD
|
||||
ESP_PD_DOMAIN_XTAL32K,
|
||||
ESP_PD_DOMAIN_XTAL32K, //!< External 32 kHz XTAL oscillator
|
||||
#endif
|
||||
#if SOC_PM_SUPPORT_RC32K_PD
|
||||
ESP_PD_DOMAIN_RC32K,
|
||||
ESP_PD_DOMAIN_RC32K, //!< Internal 32 kHz RC oscillator
|
||||
#endif
|
||||
#if SOC_PM_SUPPORT_RC_FAST_PD
|
||||
ESP_PD_DOMAIN_RC_FAST, //!< Internal Fast oscillator
|
||||
@@ -59,7 +59,9 @@ typedef enum {
|
||||
#if SOC_PM_SUPPORT_CPU_PD
|
||||
ESP_PD_DOMAIN_CPU, //!< CPU core
|
||||
#endif
|
||||
#if SOC_PM_SUPPORT_VDDSDIO_PD
|
||||
ESP_PD_DOMAIN_VDDSDIO, //!< VDD_SDIO
|
||||
#endif
|
||||
ESP_PD_DOMAIN_MAX //!< Number of domains
|
||||
} esp_sleep_pd_domain_t;
|
||||
|
||||
@@ -484,15 +486,44 @@ void esp_default_wake_deep_sleep(void);
|
||||
void esp_deep_sleep_disable_rom_logging(void);
|
||||
|
||||
#ifdef SOC_PM_SUPPORT_CPU_PD
|
||||
|
||||
#if SOC_PM_CPU_RETENTION_BY_RTCCNTL
|
||||
/**
|
||||
* @brief CPU Power down low-level initialize
|
||||
*
|
||||
* @param enable enable or disable CPU power down during light sleep
|
||||
* @brief CPU Power down low-level initialize, enable CPU power down during light sleep
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM not enough retention memory
|
||||
*/
|
||||
esp_err_t esp_sleep_cpu_pd_low_init(bool enable);
|
||||
esp_err_t esp_sleep_cpu_pd_low_init(void);
|
||||
|
||||
/**
|
||||
* @brief CPU Power down low-level deinitialize, disable CPU power down during light sleep
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM not enough retention memory
|
||||
*/
|
||||
esp_err_t esp_sleep_cpu_pd_low_deinit(void);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief CPU Power down initialize
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NO_MEM not enough retention memory
|
||||
*/
|
||||
esp_err_t esp_sleep_cpu_retention_init(void);
|
||||
|
||||
/**
|
||||
* @brief CPU Power down de-initialize
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
*
|
||||
* Release system retention memory.
|
||||
*/
|
||||
esp_err_t esp_sleep_cpu_retention_deinit(void);
|
||||
#endif
|
||||
|
||||
#if SOC_GPIO_SUPPORT_SLP_SWITCH
|
||||
|
||||
Reference in New Issue
Block a user