From c5d1a34b83118d9bff7710922913b014918bf105 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 13 Apr 2021 14:19:42 +0200 Subject: [PATCH] sys/trickle: migrate to ZTIMER_MSEC --- sys/Makefile.dep | 4 +++- sys/include/trickle.h | 12 +++++++++++- sys/trickle/trickle.c | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index e08fbb6499..c2e42a8220 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -142,7 +142,9 @@ endif ifneq (,$(filter trickle,$(USEMODULE))) USEMODULE += random - USEMODULE += xtimer + ifeq (,$(filter ztimer_msec,$(USEMODULE))) + USEMODULE += xtimer + endif endif ifneq (,$(filter eui_provider,$(USEMODULE))) diff --git a/sys/include/trickle.h b/sys/include/trickle.h index 76210789eb..994af9d73c 100644 --- a/sys/include/trickle.h +++ b/sys/include/trickle.h @@ -32,8 +32,13 @@ extern "C" { #endif -#include "xtimer.h" #include "thread.h" +#if IS_USED(MODULE_ZTIMER_MSEC) +#include "ztimer.h" +#else +#include "xtimer.h" +#endif + /** * @brief Trickle callback function with arguments @@ -59,8 +64,13 @@ typedef struct { trickle_callback_t callback; /**< callback function and parameter that trickle calls after each interval */ msg_t msg; /**< the msg_t to use for intervals */ +#if IS_USED(MODULE_ZTIMER_MSEC) + ztimer_t msg_timer; /**< timer to send a msg_t to the target + thread for a new interval */ +#else xtimer_t msg_timer; /**< xtimer to send a msg_t to the target thread for a new interval */ +#endif } trickle_t; /** diff --git a/sys/trickle/trickle.c b/sys/trickle/trickle.c index 1b03b19b7f..ab37140d10 100644 --- a/sys/trickle/trickle.c +++ b/sys/trickle/trickle.c @@ -53,9 +53,14 @@ void trickle_interval(trickle_t *trickle) /* old_interval == trickle->I / 2 */ trickle->t = random_uint32_range(old_interval, trickle->I); +#if IS_USED(MODULE_ZTIMER_MSEC) + ztimer_set_msg(ZTIMER_MSEC, &trickle->msg_timer, (trickle->t + diff), + &trickle->msg, trickle->pid); +#else uint64_t msg_time = (trickle->t + diff) * US_PER_MS; xtimer_set_msg64(&trickle->msg_timer, msg_time, &trickle->msg, trickle->pid); +#endif } void trickle_reset_timer(trickle_t *trickle) @@ -88,7 +93,11 @@ void trickle_start(kernel_pid_t pid, trickle_t *trickle, uint16_t msg_type, void trickle_stop(trickle_t *trickle) { +#if IS_USED(MODULE_ZTIMER_MSEC) + ztimer_remove(ZTIMER_MSEC, &trickle->msg_timer); +#else xtimer_remove(&trickle->msg_timer); +#endif } void trickle_increment_counter(trickle_t *trickle)