mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
sys/trickle: migrate to ZTIMER_MSEC
This commit is contained in:
parent
13eb3f05c5
commit
c5d1a34b83
@ -142,7 +142,9 @@ endif
|
|||||||
|
|
||||||
ifneq (,$(filter trickle,$(USEMODULE)))
|
ifneq (,$(filter trickle,$(USEMODULE)))
|
||||||
USEMODULE += random
|
USEMODULE += random
|
||||||
|
ifeq (,$(filter ztimer_msec,$(USEMODULE)))
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter eui_provider,$(USEMODULE)))
|
ifneq (,$(filter eui_provider,$(USEMODULE)))
|
||||||
|
|||||||
@ -32,8 +32,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "xtimer.h"
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#if IS_USED(MODULE_ZTIMER_MSEC)
|
||||||
|
#include "ztimer.h"
|
||||||
|
#else
|
||||||
|
#include "xtimer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Trickle callback function with arguments
|
* @brief Trickle callback function with arguments
|
||||||
@ -59,8 +64,13 @@ typedef struct {
|
|||||||
trickle_callback_t callback; /**< callback function and parameter that
|
trickle_callback_t callback; /**< callback function and parameter that
|
||||||
trickle calls after each interval */
|
trickle calls after each interval */
|
||||||
msg_t msg; /**< the msg_t to use for intervals */
|
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
|
xtimer_t msg_timer; /**< xtimer to send a msg_t to the target
|
||||||
thread for a new interval */
|
thread for a new interval */
|
||||||
|
#endif
|
||||||
} trickle_t;
|
} trickle_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -53,9 +53,14 @@ void trickle_interval(trickle_t *trickle)
|
|||||||
/* old_interval == trickle->I / 2 */
|
/* old_interval == trickle->I / 2 */
|
||||||
trickle->t = random_uint32_range(old_interval, trickle->I);
|
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;
|
uint64_t msg_time = (trickle->t + diff) * US_PER_MS;
|
||||||
xtimer_set_msg64(&trickle->msg_timer, msg_time, &trickle->msg,
|
xtimer_set_msg64(&trickle->msg_timer, msg_time, &trickle->msg,
|
||||||
trickle->pid);
|
trickle->pid);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_reset_timer(trickle_t *trickle)
|
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)
|
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);
|
xtimer_remove(&trickle->msg_timer);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void trickle_increment_counter(trickle_t *trickle)
|
void trickle_increment_counter(trickle_t *trickle)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user