Merge branch 'feature/esp_timer_add_ll_for_rc_fast_clk' into 'master'

hal: Adds hal/ll func for SYSTIMER to select clock source: XTAL or RC_FAST_CLK

Closes IDF-5323

See merge request espressif/esp-idf!21136
This commit is contained in:
Konstantin Kondrashov
2022-11-23 15:05:48 +08:00
17 changed files with 167 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -8,6 +8,8 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -8,6 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#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)

View File

@@ -10,6 +10,7 @@
#include <stdbool.h>
#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

View File

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