diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 66dcab6b47..9bc1c07a42 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -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 diff --git a/sys/ztimer/auto_init.c b/sys/ztimer/auto_init.c index 7c4b264c17..886f9d5db4 100644 --- a/sys/ztimer/auto_init.c +++ b/sys/ztimer/auto_init.c @@ -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