From 2b682585a75109146f3cc54629364feb7819fab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Mon, 14 Oct 2024 21:15:50 +0200 Subject: [PATCH] sys/ztimer: add ztimer_periodic_start_now() --- sys/include/ztimer/periodic.h | 13 +++++++++++++ sys/ztimer/periodic.c | 5 +++++ 2 files changed, 18 insertions(+) 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);