1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/event/timeout_ztimer.c
Francisco Molina 81c5d5dbcc sys/event/timeout: split xtimer, ztimer backends, don't force usec
This PR makes `event_timeout` and `event_timeout_ztimer` two distinct
pseudomodules, where the only api difference is in the init function.

If only `event_timeout_ztimer` is selected then no default ZTIMER
backend is selected and the old init function is not implemented.

If only `event_timeout` is selected then `xtimer` is used unless
`ztimer_usec` is included. In which case the `xtimer` wrapper on top
of `ztimer` is used and `xtimer` is not directly selected. This
allows for the legacy api to be supported with `ztimer_usec` as
a drop-in replacement.

If `event_timeout` and `event_timeut_ztimer` are selected then
`event_timeout` SRC file is excluded from compilation.
2021-11-17 10:15:11 +01:00

50 lines
1.4 KiB
C

/*
* Copyright (C) 2017 Inria
* 2017 Freie Universität Berlin
* 2017 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include "kernel_defines.h"
#include "event/timeout.h"
#include "ztimer.h"
static void _event_timeout_callback(void *arg)
{
event_timeout_t *event_timeout = (event_timeout_t *)arg;
event_post(event_timeout->queue, event_timeout->event);
}
#if IS_USED(MODULE_EVENT_TIMEOUT)
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
{
event_timeout_ztimer_init(event_timeout, ZTIMER_USEC, queue, event);
}
#endif
void event_timeout_ztimer_init(event_timeout_t *event_timeout, ztimer_clock_t *clock,
event_queue_t *queue, event_t *event)
{
event_timeout->clock = clock;
event_timeout->timer.callback = _event_timeout_callback;
event_timeout->timer.arg = event_timeout;
event_timeout->queue = queue;
event_timeout->event = event;
}
void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout)
{
ztimer_set(event_timeout->clock, &event_timeout->timer, timeout);
}
void event_timeout_clear(event_timeout_t *event_timeout)
{
if (event_timeout->clock) {
ztimer_remove(event_timeout->clock, &event_timeout->timer);
}
}