diff --git a/components/esp_driver_gptimer/src/gptimer.c b/components/esp_driver_gptimer/src/gptimer.c index 49f77e230b..40cd65d4eb 100644 --- a/components/esp_driver_gptimer/src/gptimer.c +++ b/components/esp_driver_gptimer/src/gptimer.c @@ -108,9 +108,11 @@ static void gptimer_unregister_from_group(gptimer_t *timer) static esp_err_t gptimer_destroy(gptimer_t *timer) { +#if CONFIG_PM_ENABLE if (timer->pm_lock) { ESP_RETURN_ON_ERROR(esp_pm_lock_delete(timer->pm_lock), TAG, "delete pm_lock failed"); } +#endif if (timer->intr) { ESP_RETURN_ON_ERROR(esp_intr_free(timer->intr), TAG, "delete interrupt service failed"); } @@ -347,10 +349,12 @@ esp_err_t gptimer_enable(gptimer_handle_t timer) ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&timer->fsm, &expected_fsm, GPTIMER_FSM_ENABLE), ESP_ERR_INVALID_STATE, TAG, "timer not in init state"); +#if CONFIG_PM_ENABLE // acquire power manager lock if (timer->pm_lock) { ESP_RETURN_ON_ERROR(esp_pm_lock_acquire(timer->pm_lock), TAG, "acquire pm_lock failed"); } +#endif // enable interrupt service if (timer->intr) { @@ -373,10 +377,12 @@ esp_err_t gptimer_disable(gptimer_handle_t timer) ESP_RETURN_ON_ERROR(esp_intr_disable(timer->intr), TAG, "disable interrupt service failed"); } +#if CONFIG_PM_ENABLE // release power manager lock if (timer->pm_lock) { ESP_RETURN_ON_ERROR(esp_pm_lock_release(timer->pm_lock), TAG, "release pm_lock failed"); } +#endif return ESP_OK; } diff --git a/components/esp_driver_gptimer/src/gptimer_common.c b/components/esp_driver_gptimer/src/gptimer_common.c index 6b89e8a957..3adae18d24 100644 --- a/components/esp_driver_gptimer/src/gptimer_common.c +++ b/components/esp_driver_gptimer/src/gptimer_common.c @@ -134,8 +134,7 @@ esp_err_t gptimer_select_periph_clock(gptimer_t *timer, gptimer_clock_source_t s #endif // CONFIG_IDF_TARGET_ESP32C2 if (need_pm_lock) { - sprintf(timer->pm_lock_name, "gptimer_%d_%d", group_id, timer_id); // e.g. gptimer_0_0 - ESP_RETURN_ON_ERROR(esp_pm_lock_create(pm_lock_type, 0, timer->pm_lock_name, &timer->pm_lock), + ESP_RETURN_ON_ERROR(esp_pm_lock_create(pm_lock_type, 0, timer_group_periph_signals.groups[group_id].module_name[timer_id], &timer->pm_lock), TAG, "create pm lock failed"); } #endif // CONFIG_PM_ENABLE @@ -165,12 +164,14 @@ esp_err_t gptimer_get_intr_handle(gptimer_handle_t timer, intr_handle_t *ret_int return ESP_OK; } +#if CONFIG_PM_ENABLE esp_err_t gptimer_get_pm_lock(gptimer_handle_t timer, esp_pm_lock_handle_t *ret_pm_lock) { ESP_RETURN_ON_FALSE(timer && ret_pm_lock, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); *ret_pm_lock = timer->pm_lock; return ESP_OK; } +#endif // CONFIG_PM_ENABLE int gptimer_get_group_id(gptimer_handle_t timer, int *group_id) { diff --git a/components/esp_driver_gptimer/src/gptimer_priv.h b/components/esp_driver_gptimer/src/gptimer_priv.h index a4a2114162..e9b1030fdc 100644 --- a/components/esp_driver_gptimer/src/gptimer_priv.h +++ b/components/esp_driver_gptimer/src/gptimer_priv.h @@ -51,8 +51,6 @@ extern "C" { #define GPTIMER_ALLOW_INTR_PRIORITY_MASK ESP_INTR_FLAG_LOWMED -#define GPTIMER_PM_LOCK_NAME_LEN_MAX 16 - #define GPTIMER_USE_RETENTION_LINK (SOC_TIMER_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP) #if SOC_PERIPH_CLK_CTRL_SHARED @@ -95,9 +93,8 @@ struct gptimer_t { gptimer_alarm_cb_t on_alarm; void *user_ctx; gptimer_clock_source_t clk_src; - esp_pm_lock_handle_t pm_lock; // power management lock #if CONFIG_PM_ENABLE - char pm_lock_name[GPTIMER_PM_LOCK_NAME_LEN_MAX]; // pm lock name + esp_pm_lock_handle_t pm_lock; // power management lock #endif struct { uint32_t intr_shared: 1; diff --git a/components/soc/esp32/timer_periph.c b/components/soc/esp32/timer_periph.c index b6ac0afb05..72c9ca2c8c 100644 --- a/components/soc/esp32/timer_periph.c +++ b/components/soc/esp32/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + [1] = "TIMG0T1", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, @@ -17,6 +21,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + [1] = "TIMG1T1", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32c2/timer_periph.c b/components/soc/esp32c2/timer_periph.c index 9b25afd355..1e477f66d6 100644 --- a/components/soc/esp32c2/timer_periph.c +++ b/components/soc/esp32c2/timer_periph.c @@ -9,6 +9,9 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32c3/timer_periph.c b/components/soc/esp32c3/timer_periph.c index e2be270b18..77049152ec 100644 --- a/components/soc/esp32c3/timer_periph.c +++ b/components/soc/esp32c3/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32c5/timer_periph.c b/components/soc/esp32c5/timer_periph.c index 8443db3490..cf16e20387 100644 --- a/components/soc/esp32c5/timer_periph.c +++ b/components/soc/esp32c5/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32c6/timer_periph.c b/components/soc/esp32c6/timer_periph.c index 8443db3490..cf16e20387 100644 --- a/components/soc/esp32c6/timer_periph.c +++ b/components/soc/esp32c6/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32c61/timer_periph.c b/components/soc/esp32c61/timer_periph.c index 18e719c817..d925e4474b 100644 --- a/components/soc/esp32c61/timer_periph.c +++ b/components/soc/esp32c61/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_INTR_SOURCE, diff --git a/components/soc/esp32h2/timer_periph.c b/components/soc/esp32h2/timer_periph.c index 8443db3490..cf16e20387 100644 --- a/components/soc/esp32h2/timer_periph.c +++ b/components/soc/esp32h2/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32h21/timer_periph.c b/components/soc/esp32h21/timer_periph.c index 08db6213f1..30062d0d1b 100644 --- a/components/soc/esp32h21/timer_periph.c +++ b/components/soc/esp32h21/timer_periph.c @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_INTR_SOURCE, diff --git a/components/soc/esp32h4/timer_periph.c b/components/soc/esp32h4/timer_periph.c index 08db6213f1..30062d0d1b 100644 --- a/components/soc/esp32h4/timer_periph.c +++ b/components/soc/esp32h4/timer_periph.c @@ -9,12 +9,18 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_INTR_SOURCE, } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_INTR_SOURCE, diff --git a/components/soc/esp32p4/timer_periph.c b/components/soc/esp32p4/timer_periph.c index 993f9b5c2c..1a0b55ae56 100644 --- a/components/soc/esp32p4/timer_periph.c +++ b/components/soc/esp32p4/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + [1] = "TIMG0T1", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_INTR_SOURCE, @@ -16,6 +20,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + [1] = "TIMG1T1", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_INTR_SOURCE, diff --git a/components/soc/esp32s2/timer_periph.c b/components/soc/esp32s2/timer_periph.c index 63313e6b17..58486e2937 100644 --- a/components/soc/esp32s2/timer_periph.c +++ b/components/soc/esp32s2/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + [1] = "TIMG0T1", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, @@ -16,6 +20,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + [1] = "TIMG1T1", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/esp32s3/timer_periph.c b/components/soc/esp32s3/timer_periph.c index 63313e6b17..58486e2937 100644 --- a/components/soc/esp32s3/timer_periph.c +++ b/components/soc/esp32s3/timer_periph.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { .groups = { [0] = { + .module_name = { + [0] = "TIMG0T0", + [1] = "TIMG0T1", + }, .module = PERIPH_TIMG0_MODULE, .timer_irq_id = { [0] = ETS_TG0_T0_LEVEL_INTR_SOURCE, @@ -16,6 +20,10 @@ const timer_group_signal_conn_t timer_group_periph_signals = { } }, [1] = { + .module_name = { + [0] = "TIMG1T0", + [1] = "TIMG1T1", + }, .module = PERIPH_TIMG1_MODULE, .timer_irq_id = { [0] = ETS_TG1_T0_LEVEL_INTR_SOURCE, diff --git a/components/soc/include/soc/timer_periph.h b/components/soc/include/soc/timer_periph.h index faa9bb7c45..465f048b90 100644 --- a/components/soc/include/soc/timer_periph.h +++ b/components/soc/include/soc/timer_periph.h @@ -23,6 +23,7 @@ extern "C" { typedef struct { struct { + const char *module_name[SOC_TIMER_GROUP_TIMERS_PER_GROUP]; const periph_module_t module; // Peripheral module const int timer_irq_id[SOC_TIMER_GROUP_TIMERS_PER_GROUP]; // interrupt source ID } groups[SOC_TIMER_GROUPS];