diff --git a/sys/include/ztimer/periodic.h b/sys/include/ztimer/periodic.h index f2d5c1f13c..8cafe525b4 100644 --- a/sys/include/ztimer/periodic.h +++ b/sys/include/ztimer/periodic.h @@ -130,6 +130,19 @@ void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer, */ void ztimer_periodic_start(ztimer_periodic_t *timer); +/** + * @brief Start or restart a periodic timer without initial timer delay + * + * When called on a newly initialized timer, the timer will start. + * + * When called on an already running timer, the current interval is reset to its + * start (thus the next callback will be called after the configured interval + * has passed). + * + * @param[in] timer periodic timer object to work on + */ +void ztimer_periodic_start_now(ztimer_periodic_t *timer); + /** * @brief Stop a periodic timer * diff --git a/sys/ztimer/periodic.c b/sys/ztimer/periodic.c index 70cba0ece2..8542ae21f0 100644 --- a/sys/ztimer/periodic.c +++ b/sys/ztimer/periodic.c @@ -75,6 +75,11 @@ void ztimer_periodic_start(ztimer_periodic_t *timer) timer->last = ztimer_set(timer->clock, &timer->timer, timer->interval) + timer->interval; } +void ztimer_periodic_start_now(ztimer_periodic_t *timer) +{ + timer->last = ztimer_set(timer->clock, &timer->timer, 0); +} + void ztimer_periodic_stop(ztimer_periodic_t *timer) { ztimer_remove(timer->clock, &timer->timer);