From 6c1d98d55631d5368b2af243c0ec1750502b29da Mon Sep 17 00:00:00 2001 From: morris Date: Tue, 10 Jan 2023 15:13:19 +0800 Subject: [PATCH] systimer: assign counter and alarm in esp_hw_support --- .../include/esp_private/systimer.h | 9 +++++- .../esp_hw_support/port/esp32h2/systimer.c | 6 ++-- components/esp_system/systick_etm.c | 6 ++-- components/esp_timer/src/esp_timer_etm.c | 6 ++-- .../esp_timer/src/esp_timer_impl_systimer.c | 32 +++++++++---------- .../FreeRTOS-Kernel-SMP/portable/riscv/port.c | 24 +++++++------- .../portable/xtensa/port.c | 24 +++++++------- .../FreeRTOS-Kernel/portable/port_systick.c | 22 ++++++------- .../hal/esp32c2/include/hal/systimer_ll.h | 5 --- .../hal/esp32c3/include/hal/systimer_ll.h | 5 --- .../hal/esp32c6/include/hal/systimer_ll.h | 7 +--- .../hal/esp32h2/include/hal/systimer_ll.h | 7 +--- .../hal/esp32h4/include/hal/systimer_ll.h | 5 --- .../hal/esp32s2/include/hal/systimer_ll.h | 3 -- .../hal/esp32s3/include/hal/systimer_ll.h | 6 ---- components/soc/esp32c6/include/soc/soc_caps.h | 1 - .../esp32h2/include/soc/Kconfig.soc_caps.in | 8 +++++ components/soc/esp32h2/include/soc/soc_caps.h | 5 +-- 18 files changed, 81 insertions(+), 100 deletions(-) diff --git a/components/esp_hw_support/include/esp_private/systimer.h b/components/esp_hw_support/include/esp_private/systimer.h index da31530af2..068b3fa91c 100644 --- a/components/esp_hw_support/include/esp_private/systimer.h +++ b/components/esp_hw_support/include/esp_private/systimer.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,6 +8,13 @@ #include +// we assign the systimer resources statically +#define SYSTIMER_COUNTER_ESPTIMER 0 // Counter used by esptimer, to generate the system level wall clock +#define SYSTIMER_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick +#define SYSTIMER_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 +#define SYSTIMER_ALARM_OS_TICK_CORE1 1 // Alarm used by OS tick, dedicated for core 1 +#define SYSTIMER_ALARM_ESPTIMER 2 // Alarm used by esptimer + #ifdef __cplusplus extern "C" { #endif diff --git a/components/esp_hw_support/port/esp32h2/systimer.c b/components/esp_hw_support/port/esp32h2/systimer.c index a5769445d3..c8a2327cea 100644 --- a/components/esp_hw_support/port/esp32h2/systimer.c +++ b/components/esp_hw_support/port/esp32h2/systimer.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: Apache-2.0 */ @@ -7,8 +7,8 @@ #include "esp_private/systimer.h" /** - * @brief systimer's clock source is fixed to XTAL (32MHz), and has a fixed fractional divider (2). - * So the resolution of the systimer is 32MHz/2 = 16MHz. Please check again: IDF-6484 + * @brief When systimer's clock source is XTAL (32MHz), it has a fixed fractional divider (2). + * So the resolution of the systimer is 32MHz/2 = 16MHz. */ uint64_t systimer_ticks_to_us(uint64_t ticks) { diff --git a/components/esp_system/systick_etm.c b/components/esp_system/systick_etm.c index 45327eae9e..a5a1dc7922 100644 --- a/components/esp_system/systick_etm.c +++ b/components/esp_system/systick_etm.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: Apache-2.0 */ @@ -10,7 +10,7 @@ #include "esp_systick_etm.h" #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#include "hal/systimer_ll.h" +#include "esp_private/systimer.h" #include "esp_private/etm_interface.h" #define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT @@ -32,7 +32,7 @@ esp_err_t esp_systick_new_etm_alarm_event(int core_id, esp_etm_event_handle_t *o ESP_GOTO_ON_FALSE(event, ESP_ERR_NO_MEM, err, TAG, "no memory for ETM event"); // fill the ETM event object - uint32_t event_id = SYSTIMER_EVT_CNT_CMP0 + SYSTIMER_LL_ALARM_OS_TICK_CORE0 + core_id; + uint32_t event_id = SYSTIMER_EVT_CNT_CMP0 + SYSTIMER_ALARM_OS_TICK_CORE0 + core_id; event->event_id = event_id; event->trig_periph = ETM_TRIG_PERIPH_SYSTIMER; event->del = systick_etm_event_del; diff --git a/components/esp_timer/src/esp_timer_etm.c b/components/esp_timer/src/esp_timer_etm.c index 3803821582..6996a5a710 100644 --- a/components/esp_timer/src/esp_timer_etm.c +++ b/components/esp_timer/src/esp_timer_etm.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: Apache-2.0 */ @@ -9,7 +9,7 @@ #include "esp_heap_caps.h" #include "esp_timer.h" #include "soc/soc_etm_source.h" -#include "hal/systimer_ll.h" +#include "esp_private/systimer.h" #include "esp_private/etm_interface.h" #define ETM_MEM_ALLOC_CAPS MALLOC_CAP_DEFAULT @@ -31,7 +31,7 @@ esp_err_t esp_timer_new_etm_alarm_event(esp_etm_event_handle_t *out_event) ESP_GOTO_ON_FALSE(event, ESP_ERR_NO_MEM, err, TAG, "no memory for ETM event"); // fill the ETM event object - uint32_t event_id = SYSTIMER_EVT_CNT_CMP0 + SYSTIMER_LL_ALARM_CLOCK; + uint32_t event_id = SYSTIMER_EVT_CNT_CMP0 + SYSTIMER_ALARM_ESPTIMER; event->event_id = event_id; event->trig_periph = ETM_TRIG_PERIPH_SYSTIMER; event->del = esp_timer_etm_event_del; diff --git a/components/esp_timer/src/esp_timer_impl_systimer.c b/components/esp_timer/src/esp_timer_impl_systimer.c index c3ae050df9..c946eed706 100644 --- a/components/esp_timer/src/esp_timer_impl_systimer.c +++ b/components/esp_timer/src/esp_timer_impl_systimer.c @@ -62,14 +62,14 @@ void esp_timer_impl_unlock(void) uint64_t IRAM_ATTR esp_timer_impl_get_counter_reg(void) { - return systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK); + return systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_COUNTER_ESPTIMER); } int64_t IRAM_ATTR esp_timer_impl_get_time(void) { // we hope the execution time of this function won't > 1us // thus, to save one function call, we didn't use the existing `systimer_hal_get_time` - return systimer_hal.ticks_to_us(systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK)); + return systimer_hal.ticks_to_us(systimer_hal_get_counter_value(&systimer_hal, SYSTIMER_COUNTER_ESPTIMER)); } int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time"))); @@ -80,7 +80,7 @@ void IRAM_ATTR esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id portENTER_CRITICAL_SAFE(&s_time_update_lock); timestamp_id[alarm_id] = timestamp; timestamp = MIN(timestamp_id[0], timestamp_id[1]); - systimer_hal_set_alarm_target(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK, timestamp); + systimer_hal_set_alarm_target(&systimer_hal, SYSTIMER_ALARM_ESPTIMER, timestamp); portEXIT_CRITICAL_SAFE(&s_time_update_lock); } @@ -92,7 +92,7 @@ void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp) static void IRAM_ATTR timer_alarm_isr(void *arg) { // clear the interrupt - systimer_ll_clear_alarm_int(systimer_hal.dev, SYSTIMER_LL_ALARM_CLOCK); + systimer_ll_clear_alarm_int(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER); /* Call the upper layer handler */ (*s_alarm_handler)(arg); } @@ -110,15 +110,15 @@ void esp_timer_impl_set(uint64_t new_us) systimer_counter_value_t new_count = { .val = systimer_hal.us_to_ticks(new_us), }; - systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_CLOCK, new_count.val); - systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_CLOCK); + systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_ESPTIMER, new_count.val); + systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_ESPTIMER); portEXIT_CRITICAL_SAFE(&s_time_update_lock); } void esp_timer_impl_advance(int64_t time_diff_us) { portENTER_CRITICAL_SAFE(&s_time_update_lock); - systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK, time_diff_us); + systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_COUNTER_ESPTIMER, time_diff_us); portEXIT_CRITICAL_SAFE(&s_time_update_lock); } @@ -139,9 +139,9 @@ esp_err_t esp_timer_impl_early_init(void) systimer_hal_set_steps_per_tick(&systimer_hal, 1, 1); // for pll #endif - systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_CLOCK); - systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK, SYSTIMER_ALARM_MODE_ONESHOT); - systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK, SYSTIMER_LL_COUNTER_CLOCK); + systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_ESPTIMER); + systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_ALARM_ESPTIMER, SYSTIMER_ALARM_MODE_ONESHOT); + systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_ALARM_ESPTIMER, SYSTIMER_COUNTER_ESPTIMER); return ESP_OK; } @@ -168,7 +168,7 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) * protected by a shared spinlock. Since this code runs as part of early startup, this * is practically not an issue. */ - systimer_hal_enable_alarm_int(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK); + systimer_hal_enable_alarm_int(&systimer_hal, SYSTIMER_ALARM_ESPTIMER); err = esp_intr_enable(s_timer_interrupt_handle); if (err != ESP_OK) { @@ -178,9 +178,9 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) return ESP_OK; err_intr_en: - systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_LL_ALARM_CLOCK, false); + systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER, false); /* TODO: may need a spinlock, see the note related to SYSTIMER_INT_ENA_REG in systimer_hal_init */ - systimer_ll_enable_alarm_int(systimer_hal.dev, SYSTIMER_LL_ALARM_CLOCK, false); + systimer_ll_enable_alarm_int(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER, false); esp_intr_free(s_timer_interrupt_handle); err_intr_alloc: s_alarm_handler = NULL; @@ -190,9 +190,9 @@ err_intr_alloc: void esp_timer_impl_deinit(void) { esp_intr_disable(s_timer_interrupt_handle); - systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_LL_ALARM_CLOCK, false); + systimer_ll_enable_alarm(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER, false); /* TODO: may need a spinlock, see the note related to SYSTIMER_INT_ENA_REG in systimer_hal_init */ - systimer_ll_enable_alarm_int(systimer_hal.dev, SYSTIMER_LL_ALARM_CLOCK, false); + systimer_ll_enable_alarm_int(systimer_hal.dev, SYSTIMER_ALARM_ESPTIMER, false); esp_intr_free(s_timer_interrupt_handle); s_timer_interrupt_handle = NULL; s_alarm_handler = NULL; @@ -206,7 +206,7 @@ uint64_t IRAM_ATTR esp_timer_impl_get_min_period_us(void) uint64_t esp_timer_impl_get_alarm_reg(void) { portENTER_CRITICAL_SAFE(&s_time_update_lock); - uint64_t val = systimer_hal_get_alarm_value(&systimer_hal, SYSTIMER_LL_ALARM_CLOCK); + uint64_t val = systimer_hal_get_alarm_value(&systimer_hal, SYSTIMER_ALARM_ESPTIMER); portEXIT_CRITICAL_SAFE(&s_time_update_lock); return val; } diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c index a0354a3799..450c56152f 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.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: Apache-2.0 */ @@ -149,32 +149,32 @@ void vPortSetupTimer(void) .us_to_ticks = systimer_us_to_ticks, }; systimer_hal_set_tick_rate_ops(&systimer_hal, &ops); - systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK, 0); - systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK, 0); + systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, false); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; /* configure the timer */ - systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_COUNTER_OS_TICK); systimer_hal_set_alarm_period(&systimer_hal, alarm_id, 1000000UL / CONFIG_FREERTOS_HZ); systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_PERIOD); - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, true); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, true); if (cpuid == 0) { systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); - systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_OS_TICK); #ifndef CONFIG_FREERTOS_UNICORE // SysTick of core 0 and core 1 are shifted by half of period - systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); + systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); #endif } } } else { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); } } @@ -193,11 +193,11 @@ IRAM_ATTR void SysTickIsrHandler(void *arg) ESP_PM_TRACE_ENTER(TICK, cpuid); #endif - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; do { systimer_ll_clear_alarm_int(systimer_hal->dev, alarm_id); - uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; + uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; if (diff > 0) { if (s_handled_systicks[cpuid] == 0) { s_handled_systicks[cpuid] = diff; diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index ec6fe28915..1417166b3f 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.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: Apache-2.0 */ @@ -239,32 +239,32 @@ void vPortSetupTimer(void) .us_to_ticks = systimer_us_to_ticks, }; systimer_hal_set_tick_rate_ops(&systimer_hal, &ops); - systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK, 0); - systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK, 0); + systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, false); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; /* configure the timer */ - systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_COUNTER_OS_TICK); systimer_hal_set_alarm_period(&systimer_hal, alarm_id, 1000000UL / CONFIG_FREERTOS_HZ); systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_PERIOD); - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, true); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, true); if (cpuid == 0) { systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); - systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_OS_TICK); #ifndef CONFIG_FREERTOS_UNICORE // SysTick of core 0 and core 1 are shifted by half of period - systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); + systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); #endif } } } else { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); } } @@ -283,11 +283,11 @@ IRAM_ATTR void SysTickIsrHandler(void *arg) ESP_PM_TRACE_ENTER(TICK, cpuid); #endif - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; do { systimer_ll_clear_alarm_int(systimer_hal->dev, alarm_id); - uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; + uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; if (diff > 0) { if (s_handled_systicks[cpuid] == 0) { s_handled_systicks[cpuid] = diff; diff --git a/components/freertos/FreeRTOS-Kernel/portable/port_systick.c b/components/freertos/FreeRTOS-Kernel/portable/port_systick.c index 4cdb71f9eb..810f0b535d 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/port_systick.c +++ b/components/freertos/FreeRTOS-Kernel/portable/port_systick.c @@ -88,32 +88,32 @@ void vPortSetupTimer(void) .us_to_ticks = systimer_us_to_ticks, }; systimer_hal_set_tick_rate_ops(&systimer_hal, &ops); - systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK, 0); - systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK, 0); + systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, false); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; /* configure the timer */ - systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, SYSTIMER_COUNTER_OS_TICK); systimer_hal_set_alarm_period(&systimer_hal, alarm_id, 1000000UL / CONFIG_FREERTOS_HZ); systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_PERIOD); - systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, cpuid, true); + systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, true); if (cpuid == 0) { systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); - systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK); + systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_OS_TICK); #ifndef CONFIG_FREERTOS_UNICORE // SysTick of core 0 and core 1 are shifted by half of period - systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); + systimer_hal_counter_value_advance(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, 1000000UL / CONFIG_FREERTOS_HZ / 2); #endif } } } else { - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; systimer_hal_enable_alarm_int(&systimer_hal, alarm_id); } } @@ -132,11 +132,11 @@ IRAM_ATTR void SysTickIsrHandler(void *arg) ESP_PM_TRACE_ENTER(TICK, cpuid); #endif - uint32_t alarm_id = SYSTIMER_LL_ALARM_OS_TICK_CORE0 + cpuid; + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; do { systimer_ll_clear_alarm_int(systimer_hal->dev, alarm_id); - uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; + uint32_t diff = systimer_hal_get_counter_value(systimer_hal, SYSTIMER_COUNTER_OS_TICK) / systimer_ll_get_alarm_period(systimer_hal->dev, alarm_id) - s_handled_systicks[cpuid]; if (diff > 0) { if (s_handled_systicks[cpuid] == 0) { s_handled_systicks[cpuid] = diff; diff --git a/components/hal/esp32c2/include/hal/systimer_ll.h b/components/hal/esp32c2/include/hal/systimer_ll.h index fb881e8588..f5bb4d1ffd 100644 --- a/components/hal/esp32c2/include/hal/systimer_ll.h +++ b/components/hal/esp32c2/include/hal/systimer_ll.h @@ -11,11 +11,6 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32c3/include/hal/systimer_ll.h b/components/hal/esp32c3/include/hal/systimer_ll.h index fb881e8588..f5bb4d1ffd 100644 --- a/components/hal/esp32c3/include/hal/systimer_ll.h +++ b/components/hal/esp32c3/include/hal/systimer_ll.h @@ -11,11 +11,6 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32c6/include/hal/systimer_ll.h b/components/hal/esp32c6/include/hal/systimer_ll.h index 618787be5d..74dedc721f 100644 --- a/components/hal/esp32c6/include/hal/systimer_ll.h +++ b/components/hal/esp32c6/include/hal/systimer_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,11 +12,6 @@ #include "soc/pcr_struct.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32h2/include/hal/systimer_ll.h b/components/hal/esp32h2/include/hal/systimer_ll.h index a485504a18..74dedc721f 100644 --- a/components/hal/esp32h2/include/hal/systimer_ll.h +++ b/components/hal/esp32h2/include/hal/systimer_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,11 +12,6 @@ #include "soc/pcr_struct.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK (0) // Counter used for "wallclock" time -#define SYSTIMER_LL_COUNTER_OS_TICK (1) // Counter used for OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 (0) // Alarm used for OS tick of CPU core 0 -#define SYSTIMER_LL_ALARM_CLOCK (2) // Alarm used for "wallclock" time - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32h4/include/hal/systimer_ll.h b/components/hal/esp32h4/include/hal/systimer_ll.h index 1bc7d6380f..44058c8b1c 100644 --- a/components/hal/esp32h4/include/hal/systimer_ll.h +++ b/components/hal/esp32h4/include/hal/systimer_ll.h @@ -11,11 +11,6 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32s2/include/hal/systimer_ll.h b/components/hal/esp32s2/include/hal/systimer_ll.h index 2a0194abf2..755d349bb6 100644 --- a/components/hal/esp32s2/include/hal/systimer_ll.h +++ b/components/hal/esp32s2/include/hal/systimer_ll.h @@ -11,9 +11,6 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/hal/esp32s3/include/hal/systimer_ll.h b/components/hal/esp32s3/include/hal/systimer_ll.h index c541ef0a47..676ff1d9f9 100644 --- a/components/hal/esp32s3/include/hal/systimer_ll.h +++ b/components/hal/esp32s3/include/hal/systimer_ll.h @@ -11,12 +11,6 @@ #include "soc/clk_tree_defs.h" #include "hal/assert.h" -#define SYSTIMER_LL_COUNTER_CLOCK 0 // Counter used by esptimer, to generate the system level wall clock -#define SYSTIMER_LL_COUNTER_OS_TICK 1 // Counter used by RTOS porting layer, to generate the OS tick -#define SYSTIMER_LL_ALARM_OS_TICK_CORE0 0 // Alarm used by OS tick, dedicated for core 0 -#define SYSTIMER_LL_ALARM_OS_TICK_CORE1 1 // Alarm used by OS tick, dedicated for core 1 -#define SYSTIMER_LL_ALARM_CLOCK 2 // Alarm used by esptimer - #ifdef __cplusplus extern "C" { #endif diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 845a3083a0..e27e4aad47 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -350,7 +350,6 @@ #define SOC_MEMSPI_SRC_FREQ_40M_SUPPORTED 1 #define SOC_MEMSPI_SRC_FREQ_20M_SUPPORTED 1 -// TODO: IDF-5323 (Copy from esp32c3, need check) /*-------------------------- SYSTIMER CAPS ----------------------------------*/ #define SOC_SYSTIMER_COUNTER_NUM 2 // Number of counter units #define SOC_SYSTIMER_ALARM_NUM 3 // Number of alarm units diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 5383d3f348..c37ee02558 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -599,6 +599,10 @@ config SOC_SYSTIMER_FIXED_DIVIDER bool default y +config SOC_SYSTIMER_SUPPORT_RC_FAST + bool + default y + config SOC_SYSTIMER_INT_LEVEL bool default y @@ -607,6 +611,10 @@ config SOC_SYSTIMER_ALARM_MISS_COMPENSATE bool default y +config SOC_SYSTIMER_SUPPORT_ETM + bool + default y + config SOC_TIMER_GROUPS int default 2 diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index ca420c73f9..0ef5b67f26 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -329,15 +329,16 @@ #define SOC_MEMSPI_SRC_FREQ_48M_SUPPORTED 1 -// TODO: IDF-6230 (Copy from esp32c6, need check) /*-------------------------- SYSTIMER CAPS ----------------------------------*/ #define SOC_SYSTIMER_COUNTER_NUM 2 // Number of counter units #define SOC_SYSTIMER_ALARM_NUM 3 // Number of alarm units #define SOC_SYSTIMER_BIT_WIDTH_LO 32 // Bit width of systimer low part #define SOC_SYSTIMER_BIT_WIDTH_HI 20 // Bit width of systimer high part -#define SOC_SYSTIMER_FIXED_DIVIDER 1 // Clock source divider is fixed: 2.5 +#define SOC_SYSTIMER_FIXED_DIVIDER 1 // Clock source divider is fixed to 2 when clock source is XTAL +#define SOC_SYSTIMER_SUPPORT_RC_FAST 1 // Systimer can use RC_FAST clock source #define SOC_SYSTIMER_INT_LEVEL 1 // Systimer peripheral uses level interrupt #define SOC_SYSTIMER_ALARM_MISS_COMPENSATE 1 // Systimer peripheral can generate interrupt immediately if t(target) > t(current) +#define SOC_SYSTIMER_SUPPORT_ETM 1 // Systimer comparator can generate ETM event // TODO: IDF-6242 (Copy from esp32c6, need check) /*--------------------------- TIMER GROUP CAPS ---------------------------------------*/