]> granicus.if.org Git - esp-idf/commitdiff
esp32: initialize PM at startup, add Kconfig options
authorIvan Grokhotkov <ivan@espressif.com>
Fri, 22 Sep 2017 15:02:58 +0000 (23:02 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 18 Oct 2017 06:19:17 +0000 (14:19 +0800)
components/esp32/Kconfig
components/esp32/cpu_start.c

index 4867912c9d59d18b5f5588620d377e7192061a9d..06ab28d69fc73587c3ad9c8f333a3409a023a7f4 100644 (file)
@@ -945,3 +945,55 @@ config ESP32_PHY_MAX_TX_POWER
        default ESP32_PHY_MAX_WIFI_TX_POWER
 
 endmenu  # PHY
+
+
+menu "Power Management"
+
+config PM_ENABLE
+       bool "Support for power management"
+       default n
+       help
+               If enabled, application is compiled with support for power management.
+               This option has run-time overhead (increased interrupt latency,
+               longer time to enter idle state), and it also reduces accuracy of
+               RTOS ticks and timers used for timekeeping.
+               Enable this option if application uses power management APIs. 
+
+config PM_DFS_INIT_AUTO
+       bool "Enable dynamic frequency scaling (DFS) at startup"
+       depends on PM_ENABLE
+       default n
+       help
+               If enabled, startup code configures dynamic frequency scaling.
+               Max CPU frequency is set to CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ setting,
+               min frequency is set to XTAL frequency.
+               If disabled, DFS will not be active until the application
+               configures it using esp_pm_configure function.
+
+config PM_PROFILING
+       bool "Enable profiling counters for PM locks"
+       depends on PM_ENABLE
+       default n
+       help
+               If enabled, esp_pm_* functions will keep track of the amount of time
+               each of the power management locks has been held, and esp_pm_dump_locks
+               function will print this information.
+               This feature can be used to analyze which locks are preventing the chip
+               from going into a lower power state, and see what time the chip spends
+               in each power saving mode. This feature does incur some run-time
+               overhead, so should typically be disabled in production builds. 
+
+config PM_TRACE
+       bool "Enable debug tracing of PM using GPIOs"
+       depends on PM_ENABLE
+       default n
+       help
+               If enabled, some GPIOs will be used to signal events such as RTOS ticks,
+               frequency switching, entry/exit from idle state. Refer to pm_trace.c
+               file for the list of GPIOs.
+               This feature is intended to be used when analyzing/debugging behavior
+               of power management implementation, and should be kept disabled in
+               applications.
+       
+
+endmenu # "Power Management"
\ No newline at end of file
index ccf8a1d4bc553f62dc40c2e4ae7c4112efa650b7..4a56143cfd11ea7df432b2b1b7e3e9e8027b65e4 100644 (file)
@@ -66,6 +66,8 @@
 #include "esp_spiram.h"
 #include "esp_clk_internal.h"
 #include "esp_timer.h"
+#include "esp_pm.h"
+#include "pm_impl.h"
 #include "trax.h"
 
 #define STRINGIFY(s) STRINGIFY2(s)
@@ -337,6 +339,18 @@ void start_cpu0_default(void)
     spi_flash_init();
     /* init default OS-aware flash access critical section */
     spi_flash_guard_set(&g_flash_guard_default_ops);
+#ifdef CONFIG_PM_ENABLE
+    esp_pm_impl_init();
+#ifdef CONFIG_PM_DFS_INIT_AUTO
+    rtc_cpu_freq_t max_freq;
+    rtc_clk_cpu_freq_from_mhz(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ, &max_freq);
+    esp_pm_config_esp32_t cfg = {
+            .max_cpu_freq = max_freq,
+            .min_cpu_freq = RTC_CPU_FREQ_XTAL
+    };
+    esp_pm_configure(&cfg);
+#endif //CONFIG_PM_DFS_INIT_AUTO
+#endif //CONFIG_PM_ENABLE
 
 #if CONFIG_ESP32_ENABLE_COREDUMP
     esp_core_dump_init();