diff --git a/sys/include/net/gnrc/rpl.h b/sys/include/net/gnrc/rpl.h index 9b4d6b6036..90a477da79 100644 --- a/sys/include/net/gnrc/rpl.h +++ b/sys/include/net/gnrc/rpl.h @@ -152,7 +152,6 @@ #include "net/gnrc/rpl/dodag.h" #include "net/gnrc/rpl/of_manager.h" #include "net/fib.h" -#include "xtimer.h" #include "trickle.h" #ifdef MODULE_NETSTATS_RPL diff --git a/sys/net/gnrc/Makefile.dep b/sys/net/gnrc/Makefile.dep index 8d76b02003..5652403ae6 100644 --- a/sys/net/gnrc/Makefile.dep +++ b/sys/net/gnrc/Makefile.dep @@ -99,7 +99,9 @@ ifneq (,$(filter gnrc_rpl,$(USEMODULE))) USEMODULE += gnrc_icmpv6 USEMODULE += gnrc_ipv6_nib USEMODULE += trickle - USEMODULE += xtimer + ifeq (,$(filter ztimer_msec,$(USEMODULE))) + USEMODULE += xtimer + endif USEMODULE += evtimer endif diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/sys/net/gnrc/routing/rpl/gnrc_rpl.c index 154b031632..cc42f6453b 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl.c @@ -26,6 +26,12 @@ #include "mutex.h" #include "evtimer.h" #include "random.h" +#if IS_USED(MODULE_ZTIMER_MSEC) +#include "ztimer.h" +#include "timex.h" +#else +#include "xtimer.h" +#endif #include "gnrc_rpl_internal/globals.h" #include "net/gnrc/rpl.h" @@ -41,8 +47,13 @@ static char _stack[GNRC_RPL_STACK_SIZE]; kernel_pid_t gnrc_rpl_pid = KERNEL_PID_UNDEF; const ipv6_addr_t ipv6_addr_all_rpl_nodes = GNRC_RPL_ALL_NODES_ADDR; #ifdef MODULE_GNRC_RPL_P2P +#if IS_USED(MODULE_ZTIMER_MSEC) +static uint32_t _lt_time = GNRC_RPL_LIFETIME_UPDATE_STEP * MS_PER_SEC; +static ztimer_t _lt_timer; +#else static uint32_t _lt_time = GNRC_RPL_LIFETIME_UPDATE_STEP * US_PER_SEC; static xtimer_t _lt_timer; +#endif static msg_t _lt_msg = { .type = GNRC_RPL_MSG_TYPE_LIFETIME_UPDATE }; #endif static msg_t _msg_q[GNRC_RPL_MSG_QUEUE_SIZE]; @@ -96,8 +107,13 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid) gnrc_rpl_of_manager_init(); evtimer_init_msg(&gnrc_rpl_evtimer); #ifdef MODULE_GNRC_RPL_P2P +#if IS_USED(MODULE_ZTIMER_MSEC) + ztimer_set_msg(ZTIMER_MSEC, &_lt_timer, _lt_time, + &_lt_msg, gnrc_rpl_pid); +#else xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid); #endif +#endif #ifdef MODULE_NETSTATS_RPL memset(&gnrc_rpl_netstats, 0, sizeof(gnrc_rpl_netstats)); @@ -332,7 +348,11 @@ void _update_lifetime(void) { gnrc_rpl_p2p_update(); +#if IS_USED(MODULE_ZTIMER_MSEC) + ztimer_set_msg(ZTIMER_MSEC, &_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid); +#else xtimer_set_msg(&_lt_timer, _lt_time, &_lt_msg, gnrc_rpl_pid); +#endif } #endif diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c b/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c index 2e18583be2..2c30383678 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c @@ -19,6 +19,11 @@ #include #include #include "kernel_defines.h" +#if IS_USED(MODULE_ZTIMER_MSEC) +#include "ztimer.h" +#else +#include "xtimer.h" +#endif #include "net/af.h" #include "net/icmpv6.h" @@ -322,7 +327,11 @@ gnrc_pktsnip_t *_dio_prefix_info_build(gnrc_pktsnip_t *pkt, gnrc_rpl_dodag_t *do prefix_info->prefix_len = 64; if (_get_pl_entry(dodag->iface, &dodag->dodag_id, prefix_info->prefix_len, &ple)) { +#if IS_USED(MODULE_ZTIMER_MSEC) + uint32_t now = (uint32_t)ztimer_now(ZTIMER_MSEC); +#else uint32_t now = (xtimer_now_usec64() / US_PER_MS) & UINT32_MAX; +#endif uint32_t valid_ltime = (ple.valid_until < UINT32_MAX) ? (ple.valid_until - now) / MS_PER_SEC : UINT32_MAX; uint32_t pref_ltime = (ple.pref_until < UINT32_MAX) ?