From 63f852adc852a7269532116274dacd5c8899de6d Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Thu, 17 Nov 2022 21:29:16 +0800 Subject: [PATCH] hal: Adds hal/ll func for SYSTIMER to select clock source: XTAL or RC_FAST_CLK --- components/hal/esp32c2/include/hal/systimer_ll.h | 11 +++++++++++ components/hal/esp32c3/include/hal/systimer_ll.h | 11 +++++++++++ components/hal/esp32c6/include/hal/systimer_ll.h | 13 +++++++++++++ components/hal/esp32h4/include/hal/systimer_ll.h | 11 +++++++++++ components/hal/esp32s2/include/hal/systimer_ll.h | 11 +++++++++++ components/hal/esp32s3/include/hal/systimer_ll.h | 11 +++++++++++ components/hal/include/hal/systimer_hal.h | 16 ++++++++++++++++ components/hal/systimer_hal.c | 12 ++++++++++++ components/soc/esp32/include/soc/clk_tree_defs.h | 9 +++++++++ .../soc/esp32c2/include/soc/clk_tree_defs.h | 9 +++++++++ .../soc/esp32c3/include/soc/clk_tree_defs.h | 10 ++++++++++ .../soc/esp32c6/include/soc/Kconfig.soc_caps.in | 4 ++++ .../soc/esp32c6/include/soc/clk_tree_defs.h | 11 +++++++++++ components/soc/esp32c6/include/soc/soc_caps.h | 1 + .../soc/esp32h4/include/soc/clk_tree_defs.h | 9 +++++++++ .../soc/esp32s2/include/soc/clk_tree_defs.h | 9 +++++++++ .../soc/esp32s3/include/soc/clk_tree_defs.h | 9 +++++++++ 17 files changed, 167 insertions(+) diff --git a/components/hal/esp32c2/include/hal/systimer_ll.h b/components/hal/esp32c2/include/hal/systimer_ll.h index ef57c4bd8d..fb881e8588 100644 --- a/components/hal/esp32c2/include/hal/systimer_ll.h +++ b/components/hal/esp32c2/include/hal/systimer_ll.h @@ -8,6 +8,7 @@ #include #include #include "soc/systimer_struct.h" +#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 @@ -29,6 +30,16 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + (void)clk_src; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/esp32c3/include/hal/systimer_ll.h b/components/hal/esp32c3/include/hal/systimer_ll.h index ef57c4bd8d..fb881e8588 100644 --- a/components/hal/esp32c3/include/hal/systimer_ll.h +++ b/components/hal/esp32c3/include/hal/systimer_ll.h @@ -8,6 +8,7 @@ #include #include #include "soc/systimer_struct.h" +#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 @@ -29,6 +30,16 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + (void)clk_src; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/esp32c6/include/hal/systimer_ll.h b/components/hal/esp32c6/include/hal/systimer_ll.h index 8818a44961..632a8c1191 100644 --- a/components/hal/esp32c6/include/hal/systimer_ll.h +++ b/components/hal/esp32c6/include/hal/systimer_ll.h @@ -8,6 +8,8 @@ #include #include #include "soc/systimer_struct.h" +#include "soc/clk_tree_defs.h" +#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 @@ -29,6 +31,17 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +// Set clock source: XTAL(default) or RC_FAST +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + PCR.systimer_func_clk_conf.systimer_func_clk_sel = (clk_src == SYSTIMER_CLK_SRC_RC_FAST) ? 1 : 0; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return (PCR.systimer_func_clk_conf.systimer_func_clk_sel == 1) ? SYSTIMER_CLK_SRC_RC_FAST : SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/esp32h4/include/hal/systimer_ll.h b/components/hal/esp32h4/include/hal/systimer_ll.h index 6646146be2..1bc7d6380f 100644 --- a/components/hal/esp32h4/include/hal/systimer_ll.h +++ b/components/hal/esp32h4/include/hal/systimer_ll.h @@ -8,6 +8,7 @@ #include #include #include "soc/systimer_struct.h" +#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 @@ -29,6 +30,16 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + (void)clk_src; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/esp32s2/include/hal/systimer_ll.h b/components/hal/esp32s2/include/hal/systimer_ll.h index 472b9feaed..2a0194abf2 100644 --- a/components/hal/esp32s2/include/hal/systimer_ll.h +++ b/components/hal/esp32s2/include/hal/systimer_ll.h @@ -8,6 +8,7 @@ #include #include #include "soc/systimer_struct.h" +#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 @@ -27,6 +28,16 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + (void)clk_src; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/esp32s3/include/hal/systimer_ll.h b/components/hal/esp32s3/include/hal/systimer_ll.h index 6486544de6..c541ef0a47 100644 --- a/components/hal/esp32s3/include/hal/systimer_ll.h +++ b/components/hal/esp32s3/include/hal/systimer_ll.h @@ -8,6 +8,7 @@ #include #include #include "soc/systimer_struct.h" +#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 @@ -30,6 +31,16 @@ __attribute__((always_inline)) static inline void systimer_ll_enable_clock(systi dev->conf.clk_en = en; } +static inline void systimer_ll_set_clock_source(soc_periph_systimer_clk_src_t clk_src) +{ + (void)clk_src; +} + +static inline soc_periph_systimer_clk_src_t systimer_ll_get_clock_source(void) +{ + return SYSTIMER_CLK_SRC_XTAL; +} + /******************* Counter *************************/ __attribute__((always_inline)) static inline void systimer_ll_enable_counter(systimer_dev_t *dev, uint32_t counter_id, bool en) diff --git a/components/hal/include/hal/systimer_hal.h b/components/hal/include/hal/systimer_hal.h index 6bb338c930..10f6fd84a5 100644 --- a/components/hal/include/hal/systimer_hal.h +++ b/components/hal/include/hal/systimer_hal.h @@ -10,6 +10,7 @@ #include #include "hal/systimer_types.h" #include "soc/soc_caps.h" +#include "soc/clk_tree_defs.h" #ifdef __cplusplus extern "C" { @@ -38,6 +39,11 @@ typedef struct { us_to_ticks_func_t us_to_ticks; /*!< function to convert microseconds to ticks */ } systimer_hal_tick_rate_ops_t; +/** + * @brief Systimer clock source + */ +typedef soc_periph_systimer_clk_src_t systimer_clock_source_t; + /** * @brief initialize systimer in HAL layer */ @@ -120,6 +126,16 @@ void systimer_hal_counter_can_stall_by_cpu(systimer_hal_context_t *hal, uint32_t void systimer_hal_set_steps_per_tick(systimer_hal_context_t *hal, int clock_source, uint32_t steps); #endif +/** + * @brief Set Systimer clock source + */ +void systimer_hal_set_clock_source(systimer_hal_context_t *hal, systimer_clock_source_t clk_src); + +/** + * @brief Get Systimer clock source + */ +systimer_clock_source_t systimer_hal_get_clock_source(systimer_hal_context_t *hal); + #ifdef __cplusplus } #endif diff --git a/components/hal/systimer_hal.c b/components/hal/systimer_hal.c index 16efca0e9e..b3b071d413 100644 --- a/components/hal/systimer_hal.c +++ b/components/hal/systimer_hal.c @@ -24,6 +24,18 @@ void systimer_hal_deinit(systimer_hal_context_t *hal) hal->dev = NULL; } +void systimer_hal_set_clock_source(systimer_hal_context_t *hal, systimer_clock_source_t clk_src) +{ + (void)hal; + systimer_ll_set_clock_source(clk_src); +} + +systimer_clock_source_t systimer_hal_get_clock_source(systimer_hal_context_t *hal) +{ + (void)hal; + return systimer_ll_get_clock_source(); +} + void systimer_hal_set_tick_rate_ops(systimer_hal_context_t *hal, systimer_hal_tick_rate_ops_t *ops) { hal->ticks_to_us = ops->ticks_to_us; diff --git a/components/soc/esp32/include/soc/clk_tree_defs.h b/components/soc/esp32/include/soc/clk_tree_defs.h index 2d9130464c..1a599c62ff 100644 --- a/components/soc/esp32/include/soc/clk_tree_defs.h +++ b/components/soc/esp32/include/soc/clk_tree_defs.h @@ -117,6 +117,15 @@ typedef enum { SOC_MOD_CLK_APLL, /*!< APLL is sourced from PLL, and its frequency is configurable through APLL configuration registers */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// diff --git a/components/soc/esp32c2/include/soc/clk_tree_defs.h b/components/soc/esp32c2/include/soc/clk_tree_defs.h index dcae8277a6..6068c5b822 100644 --- a/components/soc/esp32c2/include/soc/clk_tree_defs.h +++ b/components/soc/esp32c2/include/soc/clk_tree_defs.h @@ -111,6 +111,15 @@ typedef enum { SOC_MOD_CLK_XTAL, /*!< XTAL_CLK comes from the external 26/40MHz crystal */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// diff --git a/components/soc/esp32c3/include/soc/clk_tree_defs.h b/components/soc/esp32c3/include/soc/clk_tree_defs.h index fbcf451396..7d0387f695 100644 --- a/components/soc/esp32c3/include/soc/clk_tree_defs.h +++ b/components/soc/esp32c3/include/soc/clk_tree_defs.h @@ -113,6 +113,16 @@ typedef enum { SOC_MOD_CLK_XTAL, /*!< XTAL_CLK comes from the external 40MHz crystal */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; + //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// /** diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 8cb88aa4f7..59469e73f8 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -659,6 +659,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 diff --git a/components/soc/esp32c6/include/soc/clk_tree_defs.h b/components/soc/esp32c6/include/soc/clk_tree_defs.h index 8168786529..32c77d1b9d 100644 --- a/components/soc/esp32c6/include/soc/clk_tree_defs.h +++ b/components/soc/esp32c6/include/soc/clk_tree_defs.h @@ -116,6 +116,17 @@ typedef enum { SOC_MOD_CLK_XTAL, /*!< XTAL_CLK comes from the external 40MHz crystal */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_RC_FAST = SOC_MOD_CLK_RC_FAST, /*!< SYSTIMER source clock is RC_FAST */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; + //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// /** diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index bcf983f6b1..d39cb4a5d7 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -336,6 +336,7 @@ #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_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) diff --git a/components/soc/esp32h4/include/soc/clk_tree_defs.h b/components/soc/esp32h4/include/soc/clk_tree_defs.h index 5650952068..25e67725a0 100644 --- a/components/soc/esp32h4/include/soc/clk_tree_defs.h +++ b/components/soc/esp32h4/include/soc/clk_tree_defs.h @@ -118,6 +118,15 @@ typedef enum { SOC_MOD_CLK_PLL, /*< PLL_CLK is the output of 32MHz crystal oscillator frequency multiplier, 96MHz */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// diff --git a/components/soc/esp32s2/include/soc/clk_tree_defs.h b/components/soc/esp32s2/include/soc/clk_tree_defs.h index edfe3f173d..415438e2db 100644 --- a/components/soc/esp32s2/include/soc/clk_tree_defs.h +++ b/components/soc/esp32s2/include/soc/clk_tree_defs.h @@ -115,6 +115,15 @@ typedef enum { SOC_MOD_CLK_TEMP_SENSOR, /*!< TEMP_SENSOR_CLK comes directly from the internal 8MHz rc oscillator */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; //////////////////////////////////////////////////GPTimer/////////////////////////////////////////////////////////////// diff --git a/components/soc/esp32s3/include/soc/clk_tree_defs.h b/components/soc/esp32s3/include/soc/clk_tree_defs.h index cc026ae661..e5f4e25ad8 100644 --- a/components/soc/esp32s3/include/soc/clk_tree_defs.h +++ b/components/soc/esp32s3/include/soc/clk_tree_defs.h @@ -114,6 +114,15 @@ typedef enum { SOC_MOD_CLK_TEMP_SENSOR, /*!< TEMP_SENSOR_CLK comes directly from the internal 20MHz rc oscillator */ } soc_module_clk_t; +//////////////////////////////////////////////////SYSTIMER/////////////////////////////////////////////////////////////// + +/** + * @brief Type of SYSTIMER clock source + */ +typedef enum { + SYSTIMER_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock is XTAL */ + SYSTIMER_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< SYSTIMER source clock default choice is XTAL */ +} soc_periph_systimer_clk_src_t; //////////////////////////////////////////////////GPTimer///////////////////////////////////////////////////////////////