mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
esp_timer: initial support on esp32-s3
This commit is contained in:
@@ -21,6 +21,7 @@ PROVIDE ( LEDC = 0x60019000 );
|
|||||||
PROVIDE ( MCP = 0x600c3000 );
|
PROVIDE ( MCP = 0x600c3000 );
|
||||||
PROVIDE ( TIMERG0 = 0x6001F000 );
|
PROVIDE ( TIMERG0 = 0x6001F000 );
|
||||||
PROVIDE ( TIMERG1 = 0x60020000 );
|
PROVIDE ( TIMERG1 = 0x60020000 );
|
||||||
|
PROVIDE ( SYS_TIMER = 0x60023000 );
|
||||||
PROVIDE ( GPSPI2 = 0x60024000 );
|
PROVIDE ( GPSPI2 = 0x60024000 );
|
||||||
PROVIDE ( GPSPI3 = 0x60025000 );
|
PROVIDE ( GPSPI3 = 0x60025000 );
|
||||||
PROVIDE ( SYSCON = 0x60026000 );
|
PROVIDE ( SYSCON = 0x60026000 );
|
||||||
|
@@ -34,6 +34,8 @@
|
|||||||
#include "esp32/rom/ets_sys.h" // for ETSTimer type
|
#include "esp32/rom/ets_sys.h" // for ETSTimer type
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
#include "esp32s2/rom/ets_sys.h"
|
#include "esp32s2/rom/ets_sys.h"
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
#include "esp32s3/rom/ets_sys.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* We abuse 'timer_arg' field of ETSTimer structure to hold a pointer to esp_timer */
|
/* We abuse 'timer_arg' field of ETSTimer structure to hold a pointer to esp_timer */
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
#include "esp32/rom/ets_sys.h" // for ETSTimer type
|
#include "esp32/rom/ets_sys.h" // for ETSTimer type
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
#include "esp32s2/rom/ets_sys.h"
|
#include "esp32s2/rom/ets_sys.h"
|
||||||
|
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||||
|
#include "esp32s3/rom/ets_sys.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_CASE("ets_timer produces correct delay", "[ets_timer]")
|
TEST_CASE("ets_timer produces correct delay", "[ets_timer]")
|
||||||
|
@@ -37,15 +37,13 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(uin
|
|||||||
REG_SET_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (30 - counter_id));
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (30 - counter_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_apply_counter_value(uint32_t counter_id)
|
__attribute__((always_inline)) static inline void systimer_ll_counter_can_stall_by_cpu(uint32_t counter_id, uint32_t cpu_id, bool can)
|
||||||
{
|
{
|
||||||
REG_SET_BIT(SYS_TIMER_SYSTIMER_UNIT0_OP_REG + 4 * counter_id, 1 << 31);
|
if (can) {
|
||||||
}
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << ((28 - counter_id * 2) - cpu_id));
|
||||||
|
} else {
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_load_counter_value(uint32_t counter_id, uint64_t value)
|
REG_CLR_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << ((28 - counter_id * 2) - cpu_id));
|
||||||
{
|
}
|
||||||
REG_WRITE(SYS_TIMER_SYSTIMER_UNIT0_LOAD_LO_REG + 8 * counter_id, value & 0xFFFFFFFF);
|
|
||||||
REG_WRITE(SYS_TIMER_SYSTIMER_UNIT0_LOAD_HI_REG, value >> 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_counter_snapshot(uint32_t counter_id)
|
__attribute__((always_inline)) static inline void systimer_ll_counter_snapshot(uint32_t counter_id)
|
||||||
@@ -58,6 +56,12 @@ __attribute__((always_inline)) static inline bool systimer_ll_is_counter_value_v
|
|||||||
return REG_GET_BIT(SYS_TIMER_SYSTIMER_UNIT0_OP_REG + 4 * counter_id, 1 << 29);
|
return REG_GET_BIT(SYS_TIMER_SYSTIMER_UNIT0_OP_REG + 4 * counter_id, 1 << 29);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_set_counter_value(uint32_t counter_id, uint64_t value)
|
||||||
|
{
|
||||||
|
REG_WRITE(SYS_TIMER_SYSTIMER_UNIT0_LOAD_LO_REG + 8 * counter_id, value & 0xFFFFFFFF);
|
||||||
|
REG_WRITE(SYS_TIMER_SYSTIMER_UNIT0_LOAD_HI_REG, (value >> 32) & 0xFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline uint32_t systimer_ll_get_counter_value_low(uint32_t counter_id)
|
__attribute__((always_inline)) static inline uint32_t systimer_ll_get_counter_value_low(uint32_t counter_id)
|
||||||
{
|
{
|
||||||
return REG_READ(SYS_TIMER_SYSTIMER_UNIT0_VALUE_LO_REG + 8 * counter_id);
|
return REG_READ(SYS_TIMER_SYSTIMER_UNIT0_VALUE_LO_REG + 8 * counter_id);
|
||||||
@@ -68,13 +72,17 @@ __attribute__((always_inline)) static inline uint32_t systimer_ll_get_counter_va
|
|||||||
return REG_READ(SYS_TIMER_SYSTIMER_UNIT0_VALUE_HI_REG + 8 * counter_id);
|
return REG_READ(SYS_TIMER_SYSTIMER_UNIT0_VALUE_HI_REG + 8 * counter_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_apply_counter_value(uint32_t counter_id)
|
||||||
|
{
|
||||||
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_UNIT0_LOAD_REG + 4 * counter_id, SYS_TIMER_TIMER_UNIT0_LOAD);
|
||||||
|
}
|
||||||
|
|
||||||
/*******************alarm*************************/
|
/*******************alarm*************************/
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_set_alarm_value(uint32_t alarm_id, uint64_t value)
|
__attribute__((always_inline)) static inline void systimer_ll_set_alarm_value(uint32_t alarm_id, uint64_t value)
|
||||||
{
|
{
|
||||||
REG_WRITE(SYS_TIMER_SYSTIMER_TARGET0_LO_REG + alarm_id * 8, value & 0xFFFFFFFF);
|
REG_WRITE(SYS_TIMER_SYSTIMER_TARGET0_LO_REG + alarm_id * 8, value & 0xFFFFFFFF);
|
||||||
REG_WRITE(SYS_TIMER_SYSTIMER_TARGET0_HI_REG + alarm_id * 8, value >> 32);
|
REG_WRITE(SYS_TIMER_SYSTIMER_TARGET0_HI_REG + alarm_id * 8, (value >> 32) & 0xFFFFF);
|
||||||
REG_WRITE(SYS_TIMER_SYSTIMER_COMP0_LOAD_REG + alarm_id * 4, SYS_TIMER_TIMER_COMP0_LOAD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline uint64_t systimer_ll_get_alarm_value(uint32_t alarm_id)
|
__attribute__((always_inline)) static inline uint64_t systimer_ll_get_alarm_value(uint32_t alarm_id)
|
||||||
@@ -83,6 +91,31 @@ __attribute__((always_inline)) static inline uint64_t systimer_ll_get_alarm_valu
|
|||||||
| REG_READ(SYS_TIMER_SYSTIMER_TARGET0_LO_REG + alarm_id * 8);
|
| REG_READ(SYS_TIMER_SYSTIMER_TARGET0_LO_REG + alarm_id * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_connect_alarm_counter(uint32_t alarm_id, uint32_t counter_id)
|
||||||
|
{
|
||||||
|
REG_SET_FIELD(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + 4 * alarm_id, SYS_TIMER_TARGET0_TIMER_UNIT_SEL, counter_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_oneshot(uint32_t alarm_id)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_period(uint32_t alarm_id)
|
||||||
|
{
|
||||||
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_set_alarm_period(uint32_t alarm_id, uint32_t period)
|
||||||
|
{
|
||||||
|
REG_SET_FIELD(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD, period);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline)) static inline void systimer_ll_apply_alarm_value(uint32_t alarm_id)
|
||||||
|
{
|
||||||
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_COMP0_LOAD_REG + alarm_id * 4, SYS_TIMER_TIMER_COMP0_LOAD);
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_disable_alarm(uint32_t alarm_id)
|
__attribute__((always_inline)) static inline void systimer_ll_disable_alarm(uint32_t alarm_id)
|
||||||
{
|
{
|
||||||
REG_CLR_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (24 - alarm_id));
|
REG_CLR_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (24 - alarm_id));
|
||||||
@@ -93,26 +126,6 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_alarm(uint3
|
|||||||
REG_SET_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (24 - alarm_id));
|
REG_SET_BIT(SYS_TIMER_SYSTIMER_CONF_REG, 1 << (24 - alarm_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_oneshot(uint32_t alarm_id)
|
|
||||||
{
|
|
||||||
REG_CLR_BIT(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD_MODE_M);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_period(uint32_t alarm_id)
|
|
||||||
{
|
|
||||||
REG_SET_BIT(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD_MODE_M);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_set_alarm_period(uint32_t alarm_id, uint32_t period)
|
|
||||||
{
|
|
||||||
REG_SET_FIELD(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + alarm_id * 4, SYS_TIMER_TARGET0_PERIOD, period);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_connect_alarm_counter(uint32_t alarm_id, uint32_t counter_id)
|
|
||||||
{
|
|
||||||
REG_SET_FIELD(SYS_TIMER_SYSTIMER_TARGET0_CONF_REG + 4 * alarm_id, SYS_TIMER_TARGET0_TIMER_UNIT_SEL, counter_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************interrupt*************************/
|
/*******************interrupt*************************/
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_int(uint32_t alarm_id)
|
__attribute__((always_inline)) static inline void systimer_ll_enable_alarm_int(uint32_t alarm_id)
|
||||||
|
@@ -17,8 +17,9 @@
|
|||||||
#include "hal/systimer_ll.h"
|
#include "hal/systimer_ll.h"
|
||||||
#include "hal/systimer_types.h"
|
#include "hal/systimer_types.h"
|
||||||
#include "soc/systimer_caps.h"
|
#include "soc/systimer_caps.h"
|
||||||
|
#include "hal/clk_gate_ll.h"
|
||||||
|
|
||||||
#define SYSTIMER_TICKS_PER_US (16) // Number of timer ticks per microsecond
|
#define SYSTIMER_TICKS_PER_US (16) // Systimer clock source is fixed to 16MHz
|
||||||
|
|
||||||
uint64_t systimer_hal_get_counter_value(systimer_counter_id_t counter_id)
|
uint64_t systimer_hal_get_counter_value(systimer_counter_id_t counter_id)
|
||||||
{
|
{
|
||||||
@@ -56,6 +57,7 @@ void systimer_hal_set_alarm_value(systimer_alarm_id_t alarm_id, uint64_t timesta
|
|||||||
systimer_counter_value_t alarm = { .val = timestamp * SYSTIMER_TICKS_PER_US};
|
systimer_counter_value_t alarm = { .val = timestamp * SYSTIMER_TICKS_PER_US};
|
||||||
systimer_ll_disable_alarm(alarm_id);
|
systimer_ll_disable_alarm(alarm_id);
|
||||||
systimer_ll_set_alarm_value(alarm_id, alarm.val);
|
systimer_ll_set_alarm_value(alarm_id, alarm.val);
|
||||||
|
systimer_ll_apply_alarm_value(alarm_id);
|
||||||
systimer_ll_enable_alarm(alarm_id);
|
systimer_ll_enable_alarm(alarm_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,7 @@ void systimer_hal_on_apb_freq_update(uint32_t apb_ticks_per_us)
|
|||||||
void systimer_hal_counter_value_advance(systimer_counter_id_t counter_id, int64_t time_us)
|
void systimer_hal_counter_value_advance(systimer_counter_id_t counter_id, int64_t time_us)
|
||||||
{
|
{
|
||||||
systimer_counter_value_t new_count = { .val = systimer_hal_get_counter_value(counter_id) + time_us * SYSTIMER_TICKS_PER_US };
|
systimer_counter_value_t new_count = { .val = systimer_hal_get_counter_value(counter_id) + time_us * SYSTIMER_TICKS_PER_US };
|
||||||
systimer_ll_load_counter_value(counter_id, new_count.val);
|
systimer_ll_set_counter_value(counter_id, new_count.val);
|
||||||
systimer_ll_apply_counter_value(counter_id);
|
systimer_ll_apply_counter_value(counter_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ void systimer_hal_enable_counter(systimer_counter_id_t counter_id)
|
|||||||
|
|
||||||
void systimer_hal_init(void)
|
void systimer_hal_init(void)
|
||||||
{
|
{
|
||||||
|
periph_ll_enable_clk_clear_rst(PERIPH_SYSTIMER_MODULE);
|
||||||
systimer_ll_enable_clock();
|
systimer_ll_enable_clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user