1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 06:12:43 +01:00

Merge pull request #16958 from fjmolinas/wip/event_timeout_ztimer_no_usec

event/timeout: remove forced ZTIMER_USEC dependency
by separating event_timeout_ztimer interface into its own pseudo module
This commit is contained in:
Karl Fessel 2021-11-17 14:25:59 +01:00 committed by GitHub
commit 5a84a2513f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 110 additions and 46 deletions

View File

@ -8,7 +8,7 @@ BOARD ?= nrf52dk
RIOTBASE ?= $(CURDIR)/../..
# Some RIOT modules needed for this example
USEMODULE += event_timeout
USEMODULE += event_timeout_ztimer
# Include NimBLE
USEPKG += nimble

View File

@ -36,7 +36,7 @@
#define HRS_FLAGS_DEFAULT (0x01) /* 16-bit BPM value */
#define SENSOR_LOCATION (0x02) /* wrist sensor */
#define UPDATE_INTERVAL (250U * US_PER_MS)
#define UPDATE_INTERVAL (250U)
#define BPM_MIN (80U)
#define BPM_MAX (210U)
#define BPM_STEP (2)
@ -287,7 +287,7 @@ int main(void)
/* setup local event queue (for handling heart rate updates) */
event_queue_init(&_eq);
_update_evt.handler = _hr_update;
event_timeout_init(&_update_timeout_evt, &_eq, &_update_evt);
event_timeout_ztimer_init(&_update_timeout_evt, ZTIMER_MSEC, &_eq, &_update_evt);
/* verify and add our custom services */
res = ble_gatts_count_cfg(gatt_svr_svcs);

View File

@ -25,6 +25,7 @@ PSEUDOMODULES += dhcpv6_relay
PSEUDOMODULES += dns_msg
PSEUDOMODULES += ecc_%
PSEUDOMODULES += event_%
PSEUDOMODULES += event_timeout
PSEUDOMODULES += event_timeout_ztimer
PSEUDOMODULES += evtimer_mbox
PSEUDOMODULES += evtimer_on_ztimer

View File

@ -512,22 +512,24 @@ ifneq (,$(filter event_thread_%,$(USEMODULE)))
endif
ifneq (,$(filter event_timeout_ztimer,$(USEMODULE)))
USEMODULE += event_timeout
endif
ifneq (,$(filter event_periodic_timeout,$(USEMODULE)))
USEMODULE += event_timeout
USEMODULE += ztimer_periodic
USEMODULE += ztimer
endif
ifneq (,$(filter event_timeout,$(USEMODULE)))
ifneq (,$(filter event_timeout_ztimer,$(USEMODULE)))
USEMODULE += ztimer_usec
else
USEMODULE += xtimer
ifeq (,$(filter ztimer_usec,$(USEMODULE)))
USEMODULE += xtimer
endif
endif
endif
ifneq (,$(filter event_periodic_timeout,$(USEMODULE)))
USEMODULE += event_timeout
USEMODULE += ztimer_periodic
endif
ifneq (,$(filter event,$(USEMODULE)))
USEMODULE += core_thread_flags
endif

View File

@ -39,8 +39,30 @@ config MODULE_EVENT_THREAD_HIGHEST
endif # MODULE_EVENT_THREAD
config MODULE_EVENT_TIMEOUT_ZTIMER
bool "Support for triggering events after timeout, ztimer backend"
select MODULE_ZTIMER
config MODULE_EVENT_TIMEOUT
bool "Support for triggering events after timeout"
select MODULE_XTIMER
bool "Legacy API, support for triggering events after timeout"
if MODULE_EVENT_TIMEOUT
choice EVENT_TIMEOUT_IMPLEMENTATION
bool "Event Timeout Implementation"
default EVENT_TIMEOUT_ON_XTIMER
config EVENT_TIMEOUT_ON_ZTIMER
bool "Use ztimer as backend"
select MODULE_EVENT_TIMEOUT_ZTIMER
select MODULE_ZTIMER_USEC
config EVENT_TIMEOUT_ON_XTIMER
bool "Use xtimer as backend"
select MODULE_XTIMER if !ZTIMER_USEC
endchoice # EVENT_TIMEOUT_IMPLEMENTATION
endif # MODULE_EVENT_TIMEOUT
endif # MODULE_EVENT

View File

@ -2,4 +2,10 @@ SRC := event.c
SUBMODULES := 1
ifneq (,$(filter event_timeout_ztimer,$(USEMODULE)))
ifneq (,$(filter ztimer_usec,$(USEMODULE)))
SUBMODULES_NO_SRC += timeout.c
endif
endif
include $(RIOTBASE)/Makefile.base

View File

@ -9,20 +9,21 @@
*/
#include "kernel_defines.h"
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
#include "ztimer.h"
#include "event/timeout.h"
#if IS_USED(MODULE_ZTIMER_USEC)
#include "ztimer/xtimer_compat.h"
#else
#include "xtimer.h"
#endif
#include "event/timeout.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);
}
static void _event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *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;
@ -30,40 +31,12 @@ static void _event_timeout_init(event_timeout_t *event_timeout, event_queue_t *q
event_timeout->event = event;
}
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue, event_t *event)
{
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
event_timeout_ztimer_init(event_timeout, ZTIMER_USEC, queue, event);
#else
_event_timeout_init(event_timeout, queue, event);
#endif
}
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
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_init(event_timeout, queue, event);
}
#endif
void event_timeout_set(event_timeout_t *event_timeout, uint32_t timeout)
{
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
ztimer_set(event_timeout->clock, &event_timeout->timer, timeout);
#else
xtimer_set(&event_timeout->timer, timeout);
#endif
}
void event_timeout_clear(event_timeout_t *event_timeout)
{
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
if (event_timeout->clock) {
ztimer_remove(event_timeout->clock, &event_timeout->timer);
}
#else
xtimer_remove(&event_timeout->timer);
#endif
}

View File

@ -0,0 +1,49 @@
/*
* 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);
}
}

View File

@ -38,7 +38,7 @@
#define EVENT_TIMEOUT_H
#include "event.h"
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER) || IS_USED(MODULE_ZTIMER_USEC)
#include "ztimer.h"
#else
#include "xtimer.h"
@ -53,8 +53,10 @@ extern "C" {
*/
typedef struct {
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER)
ztimer_t timer; /**< ztimer object used for timeout */
ztimer_clock_t *clock; /**< ztimer clock to use */
#endif
#if IS_USED(MODULE_EVENT_TIMEOUT_ZTIMER) || IS_USED(MODULE_ZTIMER_USEC)
ztimer_t timer; /**< ztimer object used for timeout */
#else
xtimer_t timer; /**< ztimer object used for timeout */
#endif
@ -75,6 +77,7 @@ void event_timeout_ztimer_init(event_timeout_t *event_timeout, ztimer_clock_t *c
event_queue_t *queue, event_t *event);
#endif
#if IS_USED(MODULE_EVENT_TIMEOUT) || DOXYGEN
/**
* @brief Initialize timeout event object
*
@ -86,6 +89,7 @@ void event_timeout_ztimer_init(event_timeout_t *event_timeout, ztimer_clock_t *c
*/
void event_timeout_init(event_timeout_t *event_timeout, event_queue_t *queue,
event_t *event);
#endif
/**
* @brief Set a timeout

View File

@ -5,5 +5,6 @@ USEMODULE += event_thread
USEMODULE += event_callback
USEMODULE += event_timeout_ztimer
USEMODULE += event_periodic
USEMODULE += ztimer_usec
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,6 @@
# this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration.
# enable event thread in lowest priority
CONFIG_MODULE_EVENT=y
CONFIG_MODULE_EVENT_CALLBACK=y
CONFIG_MODULE_EVENT_TIMEOUT=y