1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

ztimer/periodic: stop timer before reinit, remove aquire/release

- not ztimer_now calls outsid irq -> remove aquire
This commit is contained in:
Karl Fessel 2023-07-13 16:04:49 +02:00
parent 7dd7d1e3a7
commit 4f2237dd0b

View File

@ -54,32 +54,28 @@ static void _ztimer_periodic_callback(void *arg)
}
void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer,
bool (*callback)(
void *), void *arg, uint32_t interval)
bool (*callback)(void *), void *arg, uint32_t interval)
{
ztimer_remove(clock, &timer->timer);
*timer =
(ztimer_periodic_t){ .clock = clock, .interval = interval,
.callback = callback, .arg = arg,
.timer = {
.callback = _ztimer_periodic_callback,
.arg = timer
} };
/* check if this is a reinit, ensure timer is stopped in case */
if (timer->timer.callback == _ztimer_periodic_callback) {
ztimer_periodic_stop(timer);
}
*timer = (ztimer_periodic_t){
.clock = clock, .interval = interval,
.callback = callback, .arg = arg,
.timer = {
.callback = _ztimer_periodic_callback,
.arg = timer
}
};
}
void ztimer_periodic_start(ztimer_periodic_t *timer)
{
ztimer_acquire(timer->clock);
uint32_t now = ztimer_now(timer->clock);
timer->last = now;
_ztimer_periodic_reset(timer, now);
timer->last = ztimer_set(timer->clock, &timer->timer, timer->interval) + timer->interval;
}
void ztimer_periodic_stop(ztimer_periodic_t *timer)
{
ztimer_remove(timer->clock, &timer->timer);
ztimer_release(timer->clock);
}