1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/event/timeout.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

43 lines
1.1 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"
#if IS_USED(MODULE_ZTIMER_USEC)
#include "ztimer/xtimer_compat.h"
#else
#include "xtimer.h"
#endif
static void _event_timeout_callback(void *arg)
{
event_timeout_t *event_timeout = (event_timeout_t *)arg;
event_post(event_timeout->queue, event_timeout->event);
}
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
{
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)
{
xtimer_set(&event_timeout->timer, timeout);
}
void event_timeout_clear(event_timeout_t *event_timeout)
{
xtimer_remove(&event_timeout->timer);
}