1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

sys/ztimer: expose ZTIMER_MSEC/USEC_BASE

ztimer_clock are meant to be chained. At the end of the chaine
there is always a timer device object (periph_rtt/rtc/timer).

Since ZTIMER_MSEC and ZTIMER_USEC can be the scaled/shifted with
respect to the base periph_rtt/rtc/timer it makes sense to chain
other ZTIMER_XXX on top of the base rtc/timer/rtt in order to avoid
chained convertions.
This commit is contained in:
Francisco Molina 2020-04-30 16:49:29 +02:00
parent 98a4e1bcf2
commit a1f3a8d668
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
2 changed files with 41 additions and 3 deletions

View File

@ -513,6 +513,41 @@ extern ztimer_clock_t *const ZTIMER_USEC;
*/
extern ztimer_clock_t *const ZTIMER_MSEC;
/**
* @brief Base ztimer for the microsecond clock (ZTIMER_USEC)
*
* This ztimer will reference the counter device object at the end of the
* chain of ztimer_clock_t for ZTIMER_USEC.
*
* If the base counter device object's frequency (CONFIG_ZTIMER_USEC_BASE_FREQ)
* is not 1MHz then ZTIMER_USEC will be converted on top of this one. Otherwise
* they will reference the same ztimer_clock.
*
* To avoid chained conversions its better to base new ztimer_clock on top of
* ZTIMER_USEC_BASE running at CONFIG_ZTIMER_USEC_BASE_FREQ.
*
*/
extern ztimer_clock_t *const ZTIMER_USEC_BASE;
/**
* @brief Base ztimer for the millisecond clock (ZTIMER_MSEC)
*
* This ztimer will reference the counter device object at the end of the
* chain of ztimer_clock_t for ZTIMER_MSEC.
*
* If ztimer_periph_rtt is not used then ZTIMER_MSEC_BASE will reference the
* same base as ZTIMER_USEC_BASE.
*
* If the base counter device object's frequency (CONFIG_ZTIMER_MSEC_BASE_FREQ)
* is not 1KHz then ZTIMER_MSEC will be converted on top of this one. Otherwise
* they will reference the same ztimer_clock.
*
* To avoid chained conversions its better to base new ztimer_clock on top of
* ZTIMER_MSEC_BASE running at CONFIG_ZTIMER_MSEC_BASE_FREQ.
*
*/
extern ztimer_clock_t *const ZTIMER_MSEC_BASE;
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -97,6 +97,7 @@
#if MODULE_ZTIMER_USEC
# if CONFIG_ZTIMER_USEC_TYPE_PERIPH_TIMER
static ztimer_periph_timer_t _ztimer_periph_timer_usec = { .min = CONFIG_ZTIMER_USEC_MIN };
ztimer_clock_t *const ZTIMER_USEC_BASE = &_ztimer_periph_timer_usec.super;
# if CONFIG_ZTIMER_USEC_FREQ == FREQ_1MHZ
ztimer_clock_t *const ZTIMER_USEC = &_ztimer_periph_timer_usec.super;
# elif CONFIG_ZTIMER_USEC_FREQ == 250000LU
@ -113,20 +114,22 @@ ztimer_clock_t *const ZTIMER_USEC = &_ztimer_convert_frac_usec.super.super;
#endif
#if MODULE_ZTIMER_MSEC
# if MODULE_PERIPH_RTT
# if MODULE_ZTIMER_PERIPH_RTT
static ztimer_periph_rtt_t _ztimer_periph_timer_rtt_msec;
# define ZTIMER_RTT_INIT (&_ztimer_periph_timer_rtt_msec)
ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_rtt_msec;
# define ZTIMER_RTT_INIT (ZTIMER_MSEC_BASE)
# if RTT_FREQUENCY!=FREQ_1KHZ
static ztimer_convert_frac_t _ztimer_convert_frac_msec;
ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec.super.super;
# define ZTIMER_MSEC_CONVERT_LOWER_FREQ RTT_FREQUENCY
# define ZTIMER_MSEC_CONVERT_LOWER (&_ztimer_periph_timer_rtt_msec)
# else
ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_periph_timer_rtt_msec.super;
ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_periph_timer_rtt_msec;
# endif
# elif MODULE_ZTIMER_USEC
static ztimer_convert_frac_t _ztimer_convert_frac_msec;
ztimer_clock_t *const ZTIMER_MSEC = &_ztimer_convert_frac_msec.super.super;
ztimer_clock_t *const ZTIMER_MSEC_BASE = &_ztimer_periph_timer_usec.super;
# if CONFIG_ZTIMER_USEC_FREQ < FREQ_1MHZ
# define ZTIMER_MSEC_CONVERT_LOWER ZTIMER_USEC_CONVERT_LOWER
# define ZTIMER_MSEC_CONVERT_LOWER_FREQ CONFIG_ZTIMER_USEC_FREQ