diff --git a/sys/event/periodic.c b/sys/event/periodic.c index cba234b491..948b8394a1 100644 --- a/sys/event/periodic.c +++ b/sys/event/periodic.c @@ -22,7 +22,7 @@ #include "ztimer/periodic.h" #include "event/periodic.h" -static int _event_periodic_callback(void *arg) +static bool _event_periodic_callback(void *arg) { event_periodic_t *event_periodic = (event_periodic_t *)arg; diff --git a/sys/include/ztimer/periodic.h b/sys/include/ztimer/periodic.h index 797c323351..78a767017b 100644 --- a/sys/include/ztimer/periodic.h +++ b/sys/include/ztimer/periodic.h @@ -66,6 +66,7 @@ #ifndef ZTIMER_PERIODIC_H #define ZTIMER_PERIODIC_H +#include #include #include "ztimer.h" @@ -77,7 +78,7 @@ extern "C" { /** * @brief Periodic timer stop unless it returns this value */ -#define ZTIMER_PERIODIC_KEEP_GOING 0 +#define ZTIMER_PERIODIC_KEEP_GOING true /** * @brief ztimer periodic structure @@ -87,7 +88,7 @@ typedef struct { ztimer_clock_t *clock; /**< clock for this timer */ uint32_t interval; /**< interval of this timer */ ztimer_now_t last; /**< last trigger time */ - int (*callback)(void *); /**< called on each trigger */ + bool (*callback)(void *); /**< called on each trigger */ void *arg; /**< argument for callback */ } ztimer_periodic_t; @@ -100,11 +101,12 @@ typedef struct { * @param[in] clock the clock to configure this timer on * @param[inout] timer periodic timer object to initialize * @param[in] callback function to call on each trigger + * returns `true` if the timer should keep going * @param[in] arg argument to pass to callback function * @param[in] interval period length of this timer instance */ void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer, - int (*callback)(void *), + bool (*callback)(void *), void *arg, uint32_t interval); /** diff --git a/sys/ztimer/periodic.c b/sys/ztimer/periodic.c index 0e6707504a..496a4f0a6f 100644 --- a/sys/ztimer/periodic.c +++ b/sys/ztimer/periodic.c @@ -54,7 +54,7 @@ static void _ztimer_periodic_callback(void *arg) } void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer, - int (*callback)( + bool (*callback)( void *), void *arg, uint32_t interval) { *timer = diff --git a/tests/ztimer_periodic/main.c b/tests/ztimer_periodic/main.c index 41074f5f50..2b2326f566 100644 --- a/tests/ztimer_periodic/main.c +++ b/tests/ztimer_periodic/main.c @@ -41,7 +41,7 @@ static const char *_names[] = { "ZTIMER_MSEC", "ZTIMER_USEC" }; static uint32_t _intervals[] = { 100, 10000 }; static uint32_t _max_offsets[] = { 2, 100 }; -static int callback(void *arg) +static bool callback(void *arg) { _times[_count] = ztimer_now(arg); @@ -58,7 +58,7 @@ static int callback(void *arg) mutex_unlock(&_mutex); } - return (_count == REPEAT); + return _count < REPEAT; } int main(void)