mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-03 12:07:52 +00:00
Merge branch 'feature/gptimer_c5_mp' into 'master'
feat(gptimer): support timer group driver on c5 mp Closes IDF-8705 See merge request espressif/esp-idf!30126
This commit is contained in:
@@ -10,14 +10,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h" // TODO: remove
|
||||
#include "hal/assert.h"
|
||||
#include "hal/misc.h"
|
||||
#include "hal/timer_types.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
// TODO: [ESP32C5] IDF-8693
|
||||
// #include "soc/soc_etm_source.h"
|
||||
#include "soc/soc_etm_source.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -27,6 +25,31 @@ extern "C" {
|
||||
#define TIMER_LL_GET_HW(group_id) ((group_id == 0) ? (&TIMERG0) : (&TIMERG1))
|
||||
#define TIMER_LL_EVENT_ALARM(timer_id) (1 << (timer_id))
|
||||
|
||||
#define TIMER_LL_ETM_TASK_TABLE(group, timer, task) \
|
||||
(uint32_t [2][1][GPTIMER_ETM_TASK_MAX]){{{ \
|
||||
[GPTIMER_ETM_TASK_START_COUNT] = TIMER0_TASK_CNT_START_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_STOP_COUNT] = TIMER0_TASK_CNT_STOP_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_EN_ALARM] = TIMER0_TASK_ALARM_START_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_RELOAD] = TIMER0_TASK_CNT_RELOAD_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_CAPTURE] = TIMER0_TASK_CNT_CAP_TIMER0, \
|
||||
}}, \
|
||||
{{ \
|
||||
[GPTIMER_ETM_TASK_START_COUNT] = TIMER1_TASK_CNT_START_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_STOP_COUNT] = TIMER1_TASK_CNT_STOP_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_EN_ALARM] = TIMER1_TASK_ALARM_START_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_RELOAD] = TIMER1_TASK_CNT_RELOAD_TIMER0, \
|
||||
[GPTIMER_ETM_TASK_CAPTURE] = TIMER1_TASK_CNT_CAP_TIMER0, \
|
||||
}}, \
|
||||
}[group][timer][task]
|
||||
|
||||
#define TIMER_LL_ETM_EVENT_TABLE(group, timer, event) \
|
||||
(uint32_t [2][1][GPTIMER_ETM_EVENT_MAX]){{{ \
|
||||
[GPTIMER_ETM_EVENT_ALARM_MATCH] = TIMER0_EVT_CNT_CMP_TIMER0, \
|
||||
}}, \
|
||||
{{ \
|
||||
[GPTIMER_ETM_EVENT_ALARM_MATCH] = TIMER1_EVT_CNT_CMP_TIMER0, \
|
||||
}}, \
|
||||
}[group][timer][event]
|
||||
|
||||
/**
|
||||
* @brief Enable the bus clock for timer group module
|
||||
@@ -134,11 +157,7 @@ __attribute__((always_inline))
|
||||
static inline void timer_ll_enable_alarm(timg_dev_t *hw, uint32_t timer_num, bool en)
|
||||
{
|
||||
(void)timer_num;
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].config.tx_alarm_en = en;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,12 +173,8 @@ static inline void timer_ll_set_clock_prescale(timg_dev_t *hw, uint32_t timer_nu
|
||||
if (divider >= 65536) {
|
||||
divider = 0;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
HAL_FORCE_MODIFY_U32_REG_FIELD(hw->hw_timer[timer_num].config, tx_divider, divider);
|
||||
hw->hw_timer[timer_num].config.tx_divcnt_rst = 1;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,11 +188,7 @@ static inline void timer_ll_set_clock_prescale(timg_dev_t *hw, uint32_t timer_nu
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_enable_auto_reload(timg_dev_t *hw, uint32_t timer_num, bool en)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].config.tx_autoreload = en;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,11 +200,7 @@ static inline void timer_ll_enable_auto_reload(timg_dev_t *hw, uint32_t timer_nu
|
||||
*/
|
||||
static inline void timer_ll_set_count_direction(timg_dev_t *hw, uint32_t timer_num, gptimer_count_direction_t direction)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].config.tx_increase = (direction == GPTIMER_COUNT_UP);
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +214,7 @@ static inline void timer_ll_set_count_direction(timg_dev_t *hw, uint32_t timer_n
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_enable_counter(timg_dev_t *hw, uint32_t timer_num, bool en)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].config.tx_en = en;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,15 +226,11 @@ static inline void timer_ll_enable_counter(timg_dev_t *hw, uint32_t timer_num, b
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_trigger_soft_capture(timg_dev_t *hw, uint32_t timer_num)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].update.tx_update = 1;
|
||||
// Timer register is in a different clock domain from Timer hardware logic
|
||||
// We need to wait for the update to take effect before fetching the count value
|
||||
while (hw->hw_timer[timer_num].update.tx_update) {
|
||||
}
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,12 +244,7 @@ static inline void timer_ll_trigger_soft_capture(timg_dev_t *hw, uint32_t timer_
|
||||
__attribute__((always_inline))
|
||||
static inline uint64_t timer_ll_get_counter_value(timg_dev_t *hw, uint32_t timer_num)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
return ((uint64_t)hw->hw_timer[timer_num].hi.tx_hi << 32) | (hw->hw_timer[timer_num].lo.tx_lo);
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,12 +257,8 @@ static inline uint64_t timer_ll_get_counter_value(timg_dev_t *hw, uint32_t timer
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num, uint64_t alarm_value)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].alarmhi.tx_alarm_hi = (uint32_t)(alarm_value >> 32);
|
||||
hw->hw_timer[timer_num].alarmlo.tx_alarm_lo = (uint32_t)alarm_value;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,12 +271,8 @@ static inline void timer_ll_set_alarm_value(timg_dev_t *hw, uint32_t timer_num,
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, uint64_t reload_val)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].loadhi.tx_load_hi = (uint32_t)(reload_val >> 32);
|
||||
hw->hw_timer[timer_num].loadlo.tx_load_lo = (uint32_t)reload_val;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,12 +285,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num,
|
||||
__attribute__((always_inline))
|
||||
static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo);
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,11 +297,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_
|
||||
__attribute__((always_inline))
|
||||
static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C5_BETA3_VERSION
|
||||
hw->hw_timer[timer_num].load.tx_load = 1;
|
||||
#elif CONFIG_IDF_TARGET_ESP32C5_MP_VERSION
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user