diff --git a/sys/include/ztimer.h b/sys/include/ztimer.h index 747603b227..f6ee9c8c7e 100644 --- a/sys/include/ztimer.h +++ b/sys/include/ztimer.h @@ -659,12 +659,18 @@ ztimer_now_t _ztimer_now_extend(ztimer_clock_t *clock); * unrelated components are altered that change the systems's power * management behavior. * + * @warning Make sure to call @ref ztimer_acquire(@p clock) before fetching + * the clock's current time. + * * @param[in] clock ztimer clock to operate on * * @return Current count on @p clock */ static inline ztimer_now_t ztimer_now(ztimer_clock_t *clock) { +#if MODULE_ZTIMER_ONDEMAND_STRICT + assert(clock->users > 0); +#endif #if MODULE_ZTIMER_NOW64 if (1) { #elif MODULE_ZTIMER_EXTEND @@ -693,6 +699,10 @@ static inline ztimer_now_t ztimer_now(ztimer_clock_t *clock) * If the time (@p last_wakeup + @p period) has already passed, the function * sets @p last_wakeup to @p last_wakeup + @p period and returns immediately. * + * @warning Make sure to call @ref ztimer_acquire(@p clock) before making use + * of @ref ztimer_periodic_wakeup. After usage + * @ref ztimer_release(@p clock) should be called. + * * @param[in] clock ztimer clock to operate on * @param[in] last_wakeup base time stamp for the wakeup * @param[in] period time in ticks that will be added to @p last_wakeup diff --git a/sys/ztimer/Kconfig b/sys/ztimer/Kconfig index 3bc73680d7..b9b56d422d 100644 --- a/sys/ztimer/Kconfig +++ b/sys/ztimer/Kconfig @@ -236,6 +236,11 @@ menuconfig MODULE_ZTIMER_ONDEMAND if MODULE_ZTIMER_ONDEMAND +config MODULE_ZTIMER_ONDEMAND_STRICT + bool "Strict ztimer on demand" + help + Enforce ztimer clocks to be running before calling ztimer_now(). + config MODULE_ZTIMER_ONDEMAND_TIMER bool "Run Timer only on demand" depends on MODULE_ZTIMER_PERIPH_TIMER