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:
parent
7dd7d1e3a7
commit
4f2237dd0b
@ -54,32 +54,28 @@ static void _ztimer_periodic_callback(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer,
|
void ztimer_periodic_init(ztimer_clock_t *clock, ztimer_periodic_t *timer,
|
||||||
bool (*callback)(
|
bool (*callback)(void *), void *arg, uint32_t interval)
|
||||||
void *), void *arg, uint32_t interval)
|
|
||||||
{
|
{
|
||||||
ztimer_remove(clock, &timer->timer);
|
/* check if this is a reinit, ensure timer is stopped in case */
|
||||||
*timer =
|
if (timer->timer.callback == _ztimer_periodic_callback) {
|
||||||
(ztimer_periodic_t){ .clock = clock, .interval = interval,
|
ztimer_periodic_stop(timer);
|
||||||
.callback = callback, .arg = arg,
|
}
|
||||||
.timer = {
|
*timer = (ztimer_periodic_t){
|
||||||
.callback = _ztimer_periodic_callback,
|
.clock = clock, .interval = interval,
|
||||||
.arg = timer
|
.callback = callback, .arg = arg,
|
||||||
} };
|
.timer = {
|
||||||
|
.callback = _ztimer_periodic_callback,
|
||||||
|
.arg = timer
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ztimer_periodic_start(ztimer_periodic_t *timer)
|
void ztimer_periodic_start(ztimer_periodic_t *timer)
|
||||||
{
|
{
|
||||||
ztimer_acquire(timer->clock);
|
timer->last = ztimer_set(timer->clock, &timer->timer, timer->interval) + timer->interval;
|
||||||
|
|
||||||
uint32_t now = ztimer_now(timer->clock);
|
|
||||||
|
|
||||||
timer->last = now;
|
|
||||||
_ztimer_periodic_reset(timer, now);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ztimer_periodic_stop(ztimer_periodic_t *timer)
|
void ztimer_periodic_stop(ztimer_periodic_t *timer)
|
||||||
{
|
{
|
||||||
ztimer_remove(timer->clock, &timer->timer);
|
ztimer_remove(timer->clock, &timer->timer);
|
||||||
|
|
||||||
ztimer_release(timer->clock);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user