diff --git a/components/esp_pm/include/esp_pm.h b/components/esp_pm/include/esp_pm.h index 4d5146316b..86a404286f 100644 --- a/components/esp_pm/include/esp_pm.h +++ b/components/esp_pm/include/esp_pm.h @@ -63,6 +63,14 @@ typedef enum { */ esp_err_t esp_pm_configure(const void* config); +/** + * @brief Get implementation-specific power management configuration + * @param config pointer to implementation-specific configuration structure (e.g. esp_pm_config_esp32) + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG if the pointer is null + */ +esp_err_t esp_pm_get_configuration(void* config); /** * @brief Opaque handle to the power management lock diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index 76215fc8bf..a0f360108f 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -323,6 +323,31 @@ esp_err_t esp_pm_configure(const void* vconfig) return ESP_OK; } +esp_err_t esp_pm_get_configuration(void* vconfig) +{ + if (vconfig == NULL) { + return ESP_ERR_INVALID_ARG; + } + +#if CONFIG_IDF_TARGET_ESP32 + esp_pm_config_esp32_t* config = (esp_pm_config_esp32_t*) vconfig; +#elif CONFIG_IDF_TARGET_ESP32S2 + esp_pm_config_esp32s2_t* config = (esp_pm_config_esp32s2_t*) vconfig; +#elif CONFIG_IDF_TARGET_ESP32S3 + esp_pm_config_esp32s3_t* config = (esp_pm_config_esp32s3_t*) vconfig; +#elif CONFIG_IDF_TARGET_ESP32C3 + esp_pm_config_esp32c3_t* config = (esp_pm_config_esp32c3_t*) vconfig; +#endif + + portENTER_CRITICAL(&s_switch_lock); + config->light_sleep_enable = s_light_sleep_en; + config->max_freq_mhz = s_cpu_freq_by_mode[PM_MODE_CPU_MAX].freq_mhz; + config->min_freq_mhz = s_cpu_freq_by_mode[PM_MODE_APB_MIN].freq_mhz; + portEXIT_CRITICAL(&s_switch_lock); + + return ESP_OK; +} + static pm_mode_t IRAM_ATTR get_lowest_allowed_mode(void) { /* TODO: optimize using ffs/clz */ diff --git a/components/esp_system/sleep_modes.c b/components/esp_system/sleep_modes.c index 470e5fa10f..d75462a141 100644 --- a/components/esp_system/sleep_modes.c +++ b/components/esp_system/sleep_modes.c @@ -702,6 +702,7 @@ esp_err_t esp_light_sleep_start(void) esp_clk_slowclk_cal_set(s_config.rtc_clk_cal_period); #else s_config.rtc_clk_cal_period = rtc_clk_cal(RTC_CAL_RTC_MUX, RTC_CLK_SRC_CAL_CYCLES); + esp_clk_slowclk_cal_set(s_config.rtc_clk_cal_period); #endif /*