From f5de257d58940bb14e1d0aa558be761044eff5c3 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 15 Jan 2021 14:40:02 +0100 Subject: [PATCH] ztimer: expose ztimer_is_set() to public API --- sys/include/ztimer.h | 11 +++++++++++ sys/ztimer/core.c | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index d3976de505..f1f93e3e90 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -349,6 +349,17 @@ void ztimer_handler(ztimer_clock_t *clock); */ void ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val); +/** + * @brief Check if a timer is currently active + * + * @param[in] clock ztimer clock to operate on + * @param[in] timer timer to check + * + * @return > 0 if timer is active + * @return 0 if timer is not active + */ +unsigned ztimer_is_set(const ztimer_clock_t *clock, const ztimer_t *timer); + /** * @brief Remove a timer from a clock * diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index 7c7fbc3e46..9a8af567d7 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -58,6 +58,15 @@ static unsigned _is_set(const ztimer_clock_t *clock, const ztimer_t *t) } } +unsigned ztimer_is_set(const ztimer_clock_t *clock, const ztimer_t *timer) +{ + unsigned state = irq_disable(); + unsigned res = _is_set(clock, timer); + + irq_restore(state); + return res; +} + void ztimer_remove(ztimer_clock_t *clock, ztimer_t *timer) { unsigned state = irq_disable();