From 90b2f3158c31ecdf1301f937405b99d23e2343b8 Mon Sep 17 00:00:00 2001 From: Juergen Fitschen Date: Fri, 4 Feb 2022 18:51:21 +0100 Subject: [PATCH] ztimer/convert: pass-thru start/stop ops to lower timer --- sys/include/ztimer/convert.h | 18 ++++++++++++++++++ sys/ztimer/convert.c | 14 ++++++++++++++ sys/ztimer/convert_frac.c | 4 ++++ sys/ztimer/convert_muldiv64.c | 4 ++++ sys/ztimer/convert_shift.c | 4 ++++ 5 files changed, 44 insertions(+) diff --git a/sys/include/ztimer/convert.h b/sys/include/ztimer/convert.h index 098f092c43..4dacfa8ed8 100644 --- a/sys/include/ztimer/convert.h +++ b/sys/include/ztimer/convert.h @@ -71,6 +71,24 @@ void ztimer_convert_init(ztimer_convert_t *ztimer_convert, */ void ztimer_convert_cancel(ztimer_clock_t *clock); +/** + * @brief ztimer_convert common start() op + * + * Used by some conversion modules as ztimer_clock_t::ops.start(). + * + * @param[in] clock ztimer clock to operate on + */ +void ztimer_convert_start(ztimer_clock_t *clock); + +/** + * @brief ztimer_convert common stop() op + * + * Used by some conversion modules as ztimer_clock_t::ops.stop(). + * + * @param[in] clock ztimer clock to operate on + */ +void ztimer_convert_stop(ztimer_clock_t *clock); + #ifdef __cplusplus } #endif diff --git a/sys/ztimer/convert.c b/sys/ztimer/convert.c index 27ef678716..16bb43ea91 100644 --- a/sys/ztimer/convert.c +++ b/sys/ztimer/convert.c @@ -35,6 +35,20 @@ void ztimer_convert_cancel(ztimer_clock_t *clock) ztimer_remove(ztimer_convert->lower, &ztimer_convert->lower_entry); } +void ztimer_convert_start(ztimer_clock_t *clock) +{ + ztimer_convert_t *ztimer_convert = (ztimer_convert_t *)clock; + + ztimer_acquire(ztimer_convert->lower); +} + +void ztimer_convert_stop(ztimer_clock_t *clock) +{ + ztimer_convert_t *ztimer_convert = (ztimer_convert_t *)clock; + + ztimer_release(ztimer_convert->lower); +} + void ztimer_convert_init(ztimer_convert_t *ztimer_convert, ztimer_clock_t *lower, uint32_t max_value) diff --git a/sys/ztimer/convert_frac.c b/sys/ztimer/convert_frac.c index 4aa82b9b77..5a0b6dfa23 100644 --- a/sys/ztimer/convert_frac.c +++ b/sys/ztimer/convert_frac.c @@ -74,6 +74,10 @@ static const ztimer_ops_t ztimer_convert_frac_ops = { .set = ztimer_convert_frac_op_set, .now = ztimer_convert_frac_op_now, .cancel = ztimer_convert_cancel, +#if MODULE_ZTIMER_ONDEMAND + .start = ztimer_convert_start, + .stop = ztimer_convert_stop, +#endif }; static void ztimer_convert_frac_compute_scale(ztimer_convert_frac_t *self, diff --git a/sys/ztimer/convert_muldiv64.c b/sys/ztimer/convert_muldiv64.c index 8b8e602875..924d1045d0 100644 --- a/sys/ztimer/convert_muldiv64.c +++ b/sys/ztimer/convert_muldiv64.c @@ -98,6 +98,10 @@ static const ztimer_ops_t _ztimer_convert_muldiv64_ops = { .set = _ztimer_convert_muldiv64_set, .now = _ztimer_convert_muldiv64_now, .cancel = ztimer_convert_cancel, +#if MODULE_ZTIMER_ONDEMAND + .start = ztimer_convert_start, + .stop = ztimer_convert_stop, +#endif }; void ztimer_convert_muldiv64_init( diff --git a/sys/ztimer/convert_shift.c b/sys/ztimer/convert_shift.c index a099a103a9..34cda54da2 100644 --- a/sys/ztimer/convert_shift.c +++ b/sys/ztimer/convert_shift.c @@ -78,6 +78,10 @@ static const ztimer_ops_t _ztimer_convert_shift_ops_up = { .set = _ztimer_convert_shift_up_set, .now = _ztimer_convert_shift_up_now, .cancel = ztimer_convert_cancel, +#if MODULE_ZTIMER_ONDEMAND + .start = ztimer_convert_start, + .stop = ztimer_convert_stop, +#endif }; void ztimer_convert_shift_up_init(ztimer_convert_shift_t *clock,