From 0f6cda1dd30a550c52c656ebb6aaa87d0b22121c Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Mon, 7 Nov 2022 22:10:22 +0800 Subject: [PATCH] Power Management: support DFS --- components/driver/twai.c | 4 ++-- components/esp_pm/Kconfig | 8 ++++---- components/esp_pm/pm_impl.c | 7 +++++++ components/soc/esp32c6/include/soc/soc.h | 1 + examples/wifi/itwt/main/itwt.c | 8 +++----- examples/wifi/power_save/main/power_save.c | 2 ++ 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/components/driver/twai.c b/components/driver/twai.c index 418f4b24fe..40092377a1 100644 --- a/components/driver/twai.c +++ b/components/driver/twai.c @@ -470,7 +470,7 @@ esp_err_t twai_driver_install(const twai_general_config_t *g_config, const twai_ p_twai_obj_dummy->module = twai_controller_periph_signals.controllers[controller_id].module; -#ifdef CONFIG_PM_ENABLE +#if CONFIG_PM_ENABLE && SOC_TWAI_CLK_SUPPORT_APB if (clk_src == TWAI_CLK_SRC_APB) { // TODO: pm_lock name should also reflect the controller ID ret = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "twai", &(p_twai_obj_dummy->pm_lock)); @@ -478,7 +478,7 @@ esp_err_t twai_driver_install(const twai_general_config_t *g_config, const twai_ goto err; } } -#endif //CONFIG_PM_ENABLE +#endif //CONFIG_PM_ENABLE && SOC_TWAI_CLK_SUPPORT_APB //Initialize TWAI peripheral registers, and allocate interrupt TWAI_ENTER_CRITICAL(); diff --git a/components/esp_pm/Kconfig b/components/esp_pm/Kconfig index a92fa47ad0..2e073b0b3a 100644 --- a/components/esp_pm/Kconfig +++ b/components/esp_pm/Kconfig @@ -2,10 +2,10 @@ menu "Power Management" config PM_ENABLE bool "Support for power management" # SMP FreeRTOS currently does not support power management IDF-4997 - # ESP32C6 currently does not support power management IDF-5347 IDF-6270 - # Note. Disabling this option for C6 will also cause all sdkconfig.release test cases run without pm enabled - # ORed with __DOXYGEN__ to pass C6 docs build, need to remove when pm is supported on C6 - depends on (!FREERTOS_SMP && !IDF_TARGET_ESP32C6 && !IDF_TARGET_ESP32H2) || __DOXYGEN__ + # ESP32H2 currently does not support power management IDF-6270 + # Note. Disabling this option for H2 will also cause all sdkconfig.release test cases run without pm enabled + # ORed with __DOXYGEN__ to pass H2 docs build, need to remove when pm is supported on H2 + depends on (!FREERTOS_SMP && !IDF_TARGET_ESP32H2) || __DOXYGEN__ default n help If enabled, application is compiled with support for power management. diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index 4384fa1eb1..3d5b435597 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -288,6 +288,13 @@ esp_err_t esp_pm_configure(const void* vconfig) */ apb_max_freq = 80; } +#elif CONFIG_IDF_TARGET_ESP32C6 + /* Maximum SOC APB clock frequency is 40 MHz, maximum Modem (WiFi, + * Bluetooth, etc..) APB clock frequency is 80 MHz */ + const int soc_apb_clk_freq = esp_clk_apb_freq() / MHZ; + const int modem_apb_clk_freq = MODEM_APB_CLK_FREQ / MHZ; + const int apb_clk_freq = MAX(soc_apb_clk_freq, modem_apb_clk_freq); + int apb_max_freq = MIN(max_freq_mhz, apb_clk_freq); /* CPU frequency in APB_MAX mode */ #else int apb_max_freq = MIN(max_freq_mhz, 80); /* CPU frequency in APB_MAX mode */ #endif diff --git a/components/soc/esp32c6/include/soc/soc.h b/components/soc/esp32c6/include/soc/soc.h index e782be8996..8adccb044b 100644 --- a/components/soc/esp32c6/include/soc/soc.h +++ b/components/soc/esp32c6/include/soc/soc.h @@ -141,6 +141,7 @@ #define EFUSE_CLK_FREQ_ROM ( 20*1000000) #define CPU_CLK_FREQ APB_CLK_FREQ #define APB_CLK_FREQ ( 40*1000000 ) +#define MODEM_APB_CLK_FREQ ( 80*1000000 ) #define REF_CLK_FREQ ( 1000000 ) #define RTC_CLK_FREQ (20*1000000) #define XTAL_CLK_FREQ (40*1000000) diff --git a/examples/wifi/itwt/main/itwt.c b/examples/wifi/itwt/main/itwt.c index ab6ee1d8e7..8ce6db7e26 100644 --- a/examples/wifi/itwt/main/itwt.c +++ b/examples/wifi/itwt/main/itwt.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -27,6 +27,7 @@ #include "cmd_system.h" #include "wifi_cmd.h" #include "esp_wifi_he.h" +#include "esp_pm.h" /******************************************************* * Constants @@ -244,10 +245,7 @@ void app_main(void) } // TODO: WIFI-5150 -#if CONFIG_PM_ENABLE - io_toggle_pmu_internal_signal_map_to_io_init(); - io_toggle_gpio_init(); - +#if CONFIG_PM_ENABLE && 0 sleep_clock_system_retention_init(); sleep_clock_modem_retention_init(); sleep_peripheral_retention_init(); diff --git a/examples/wifi/power_save/main/power_save.c b/examples/wifi/power_save/main/power_save.c index 653e67607c..bd39b47d76 100644 --- a/examples/wifi/power_save/main/power_save.c +++ b/examples/wifi/power_save/main/power_save.c @@ -105,6 +105,8 @@ void app_main(void) esp_pm_config_esp32s3_t pm_config = { #elif CONFIG_IDF_TARGET_ESP32C2 esp_pm_config_esp32c2_t pm_config = { +#elif CONFIG_IDF_TARGET_ESP32C6 + esp_pm_config_esp32c6_t pm_config = { #endif .max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ, .min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,