Просмотр исходного кода

Merge branch 'bugfix/fix_some_pm_issue' into 'master'

esp_pm: fix an issue and add an interface

Closes IDF-2984 and IDF-2944

See merge request espressif/esp-idf!12787
Jiang Jiang Jian 4 лет назад
Родитель
Сommit
d6a2a67006

+ 1 - 0
components/esp_hw_support/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
 
     /*

+ 8 - 0
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

+ 25 - 0
components/esp_pm/pm_impl.c

@@ -322,6 +322,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 */