diff --git a/components/driver/timer.c b/components/driver/timer.c index 43f9b0888d..55705d346d 100644 --- a/components/driver/timer.c +++ b/components/driver/timer.c @@ -47,6 +47,7 @@ typedef struct { gptimer_clock_source_t clk_src; gptimer_count_direction_t direction; uint32_t divider; + uint64_t alarm_value; bool alarm_en; bool auto_reload_en; bool counter_en; @@ -171,6 +172,7 @@ esp_err_t timer_set_alarm_value(timer_group_t group_num, timer_idx_t timer_num, ESP_RETURN_ON_FALSE(p_timer_obj[group_num][timer_num] != NULL, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NEVER_INIT_ERROR); TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]); timer_ll_set_alarm_value(p_timer_obj[group_num][timer_num]->hal.dev, timer_num, alarm_value); + p_timer_obj[group_num][timer_num]->alarm_value = alarm_value; TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]); return ESP_OK; } @@ -182,7 +184,7 @@ esp_err_t timer_get_alarm_value(timer_group_t group_num, timer_idx_t timer_num, ESP_RETURN_ON_FALSE(alarm_value != NULL, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_PARAM_ADDR_ERROR); ESP_RETURN_ON_FALSE(p_timer_obj[group_num][timer_num] != NULL, ESP_ERR_INVALID_ARG, TIMER_TAG, TIMER_NEVER_INIT_ERROR); TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]); - *alarm_value = timer_ll_get_alarm_value(p_timer_obj[group_num][timer_num]->hal.dev, timer_num); + *alarm_value = p_timer_obj[group_num][timer_num]->alarm_value; TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]); return ESP_OK; } @@ -430,6 +432,7 @@ uint64_t IRAM_ATTR timer_group_get_counter_value_in_isr(timer_group_t group_num, void IRAM_ATTR timer_group_set_alarm_value_in_isr(timer_group_t group_num, timer_idx_t timer_num, uint64_t alarm_val) { timer_ll_set_alarm_value(p_timer_obj[group_num][timer_num]->hal.dev, timer_num, alarm_val); + p_timer_obj[group_num][timer_num]->alarm_value = alarm_val; } void IRAM_ATTR timer_group_set_counter_enable_in_isr(timer_group_t group_num, timer_idx_t timer_num, timer_start_t counter_en) diff --git a/components/hal/esp32/include/hal/timer_ll.h b/components/hal/esp32/include/hal/timer_ll.h index fbd44ddb1f..b2855cef7b 100644 --- a/components/hal/esp32/include/hal/timer_ll.h +++ b/components/hal/esp32/include/hal/timer_ll.h @@ -144,18 +144,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t) alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t) hw->hw_timer[timer_num].alarmhi.tx_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tx_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/esp32c3/include/hal/timer_ll.h b/components/hal/esp32c3/include/hal/timer_ll.h index 8f2d633f1c..5149954ef6 100644 --- a/components/hal/esp32c3/include/hal/timer_ll.h +++ b/components/hal/esp32c3/include/hal/timer_ll.h @@ -147,18 +147,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t) alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t) hw->hw_timer[timer_num].alarmhi.tx_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tx_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/esp32h2/include/hal/timer_ll.h b/components/hal/esp32h2/include/hal/timer_ll.h index 8f2d633f1c..5149954ef6 100644 --- a/components/hal/esp32h2/include/hal/timer_ll.h +++ b/components/hal/esp32h2/include/hal/timer_ll.h @@ -147,18 +147,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t) alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t) hw->hw_timer[timer_num].alarmhi.tx_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tx_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/esp32s2/include/hal/timer_ll.h b/components/hal/esp32s2/include/hal/timer_ll.h index 798ff147f4..8d403b8a6c 100644 --- a/components/hal/esp32s2/include/hal/timer_ll.h +++ b/components/hal/esp32s2/include/hal/timer_ll.h @@ -148,18 +148,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t) alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t) hw->hw_timer[timer_num].alarmhi.tx_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tx_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/esp32s3/include/hal/timer_ll.h b/components/hal/esp32s3/include/hal/timer_ll.h index 2f5481c0fa..9a3994a5e3 100644 --- a/components/hal/esp32s3/include/hal/timer_ll.h +++ b/components/hal/esp32s3/include/hal/timer_ll.h @@ -147,18 +147,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tn_alarm_lo = (uint32_t)alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t)hw->hw_timer[timer_num].alarmhi.tn_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tn_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/esp8684/include/hal/timer_ll.h b/components/hal/esp8684/include/hal/timer_ll.h index d28c0d7925..f35de704a8 100644 --- a/components/hal/esp8684/include/hal/timer_ll.h +++ b/components/hal/esp8684/include/hal/timer_ll.h @@ -12,7 +12,6 @@ #include "hal/assert.h" #include "hal/misc.h" #include "hal/timer_types.h" -#include "soc/timer_periph.h" #include "soc/timer_group_struct.h" #ifdef __cplusplus @@ -148,18 +147,6 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t) alarm_value; } -/** - * @brief Get alarm value - * - * @param hw Timer Group register base address - * @param timer_num Timer number in the group - * @return Counter value to trigger the alarm event - */ -static inline uint64_t timer_ll_get_alarm_value(timg_dev_t *hw, uint32_t timer_num) -{ - return ((uint64_t) hw->hw_timer[timer_num].alarmhi.tx_alarm_hi << 32) | (hw->hw_timer[timer_num].alarmlo.tx_alarm_lo); -} - /** * @brief Set reload value * diff --git a/components/hal/include/hal/timer_types.h b/components/hal/include/hal/timer_types.h index 19e72418bd..4b339c9f29 100644 --- a/components/hal/include/hal/timer_types.h +++ b/components/hal/include/hal/timer_types.h @@ -6,6 +6,8 @@ #pragma once +#include "soc/soc_caps.h" + #ifdef __cplusplus extern "C" { #endif @@ -14,17 +16,21 @@ extern "C" { * @brief GPTimer clock source * @note The clock source listed here is not supported on all targets * @note User should select the clock source based on real requirements: - * ╔══════════════════════╦══════════════════════════════════╦══════════════════════════╗ - * ║ GPTimer clock source ║ Features ║ Power Management ║ - * ╠══════════════════════╬══════════════════════════════════╬══════════════════════════╣ - * ║ GPTIMER_CLK_SRC_APB ║ High resolution ║ ESP_PM_APB_FREQ_MAX lock ║ - * ╠══════════════════════╬══════════════════════════════════╬══════════════════════════╣ - * ║ GPTIMER_CLK_SRC_XTAL ║ Medium resolution, high accuracy ║ No PM lock ║ - * ╚══════════════════════╩══════════════════════════════════╩══════════════════════════╝ + * @verbatim embed:rst:leading-asterisk + * +----------------------+----------------------------------+--------------------------+ + * | GPTimer clock source | Features | Power Management | + * +======================+==================================+==========================+ + * | GPTIMER_CLK_SRC_APB | High resolution | ESP_PM_APB_FREQ_MAX lock | + * +----------------------+----------------------------------+--------------------------+ + * | GPTIMER_CLK_SRC_XTAL | Medium resolution, high accuracy | No PM lock | + * +----------------------+----------------------------------+--------------------------+ + * @endverbatim */ typedef enum { GPTIMER_CLK_SRC_APB, /*!< Select APB as the source clock */ +#if SOC_TIMER_GROUP_SUPPORT_XTAL GPTIMER_CLK_SRC_XTAL, /*!< Select XTAL as the source clock */ +#endif } gptimer_clock_source_t; /** @@ -35,15 +41,6 @@ typedef enum { GPTIMER_COUNT_UP, /*!< Increase count value */ } gptimer_count_direction_t; -/** - * @brief GPTimer actions on alarm event - */ -typedef enum { - GPTIMER_ALARM_ACTION_CONTINUE, /*!< Counter will pass through the alarm point and continue counting */ - GPTIMER_ALARM_ACTION_STOP, /*!< Counter will stop on alarm event */ - GPTIMER_ALARM_ACTION_RELOAD, /*!< Counter will do reload on alarm event */ -} gptimer_alarm_action_t; - #ifdef __cplusplus } #endif