timer: save alarm value in driver layer

This commit is contained in:
morris 2021-12-17 09:57:27 +08:00
parent b170aba93a
commit 2c810f8451
8 changed files with 17 additions and 90 deletions

View File

@ -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)

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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
*

View File

@ -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