Skip to content

Commit

Permalink
ztimer/periodic: stop timer before reinit, remove aquire/release
Browse files Browse the repository at this point in the history
    - not ztimer_now calls outsid irq -> remove aquire
  • Loading branch information
kfessel committed Jul 14, 2023
1 parent 7dd7d1e commit 4f2237d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions sys/ztimer/periodic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 4f2237d

Please sign in to comment.