From dfacff9568d2321ee84b450c12406f1718698162 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Mon, 20 Jul 2020 13:25:50 +0200 Subject: [PATCH] gnrc_lorawan: add support for RTT --- sys/include/net/gnrc/lorawan.h | 12 ------------ sys/include/net/gnrc/netif/lorawan.h | 6 +++--- sys/net/gnrc/Makefile.dep | 2 +- sys/net/gnrc/link_layer/lorawan/Kconfig | 10 ---------- sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c | 17 ++++++----------- 5 files changed, 10 insertions(+), 37 deletions(-) diff --git a/sys/include/net/gnrc/lorawan.h b/sys/include/net/gnrc/lorawan.h index 97f5994853..1feaf57485 100644 --- a/sys/include/net/gnrc/lorawan.h +++ b/sys/include/net/gnrc/lorawan.h @@ -34,18 +34,6 @@ extern "C" { * @ingroup net_gnrc_conf * @{ */ -/** - * @brief maximum timer drift in per mille - * - * @note this is only a workaround to compensate inaccurate timers. - * - * E.g a value of 1 means there's a positive drift of 0.1% (set timeout to - * 1000 ms => triggers after 1001 ms) - */ -#ifndef CONFIG_GNRC_LORAWAN_TIMER_DRIFT -#define CONFIG_GNRC_LORAWAN_TIMER_DRIFT 10 -#endif - /** * @brief the minimum symbols to detect a LoRa preamble */ diff --git a/sys/include/net/gnrc/netif/lorawan.h b/sys/include/net/gnrc/netif/lorawan.h index 610a805857..ca70854712 100644 --- a/sys/include/net/gnrc/netif/lorawan.h +++ b/sys/include/net/gnrc/netif/lorawan.h @@ -20,7 +20,7 @@ #include "net/gnrc/lorawan.h" -#include "xtimer.h" +#include "ztimer.h" #ifdef __cplusplus extern "C" { @@ -41,8 +41,8 @@ typedef struct { uint8_t deveui[LORAMAC_DEVEUI_LEN]; /**< Device EUI buffer */ uint8_t appeui[LORAMAC_APPEUI_LEN]; /**< App EUI buffer */ gnrc_lorawan_t mac; /**< gnrc lorawan mac descriptor */ - xtimer_t timer; /**< General purpose timer */ - xtimer_t backoff_timer; /**< Backoff timer */ + ztimer_t timer; /**< General purpose timer */ + ztimer_t backoff_timer; /**< Backoff timer */ uint8_t flags; /**< flags for the LoRaWAN interface */ uint8_t demod_margin; /**< value of last demodulation margin */ uint8_t num_gateways; /**< number of gateways of last link check */ diff --git a/sys/net/gnrc/Makefile.dep b/sys/net/gnrc/Makefile.dep index 8d76b02003..f3cc27e77d 100644 --- a/sys/net/gnrc/Makefile.dep +++ b/sys/net/gnrc/Makefile.dep @@ -25,7 +25,7 @@ ifneq (,$(filter gnrc_gomach,$(USEMODULE))) endif ifneq (,$(filter gnrc_lorawan,$(USEMODULE))) - USEMODULE += xtimer + USEMODULE += ztimer_msec USEMODULE += random USEMODULE += hashes USEMODULE += crypto_aes_128 diff --git a/sys/net/gnrc/link_layer/lorawan/Kconfig b/sys/net/gnrc/link_layer/lorawan/Kconfig index 14013b6f61..265b8cff43 100644 --- a/sys/net/gnrc/link_layer/lorawan/Kconfig +++ b/sys/net/gnrc/link_layer/lorawan/Kconfig @@ -16,16 +16,6 @@ menuconfig KCONFIG_USEMODULE_GNRC_LORAWAN if KCONFIG_USEMODULE_GNRC_LORAWAN -config GNRC_LORAWAN_TIMER_DRIFT - int "Maximum timer drift" - default 10 - range -1000 1000 - help - The value is expressed in per mille. This is only a workaround to - compensate inaccurate timers. E.g. a value of 1 means there's a - positive drift of 0.1% (set timeout to 1000 ms => triggers after - 1001 ms) - config GNRC_LORAWAN_MIN_SYMBOLS_TIMEOUT int "Minimum symbols to detect a LoRa preamble" default 30 diff --git a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c index 8a16feb79d..93cc172cb7 100644 --- a/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c +++ b/sys/net/gnrc/netif/lorawan/gnrc_netif_lorawan.c @@ -32,11 +32,6 @@ #define MSG_TYPE_MLME_BACKOFF_EXPIRE (0x3458) /**< Backoff timer expiration message type */ -/* This factor is used for converting "real" seconds into microcontroller - * microseconds. This is done in order to correct timer drift. - */ -#define ADJUST_DRIFT(us) (int) (us * 100 / (100 + (CONFIG_GNRC_LORAWAN_TIMER_DRIFT / 10.0))) - static uint8_t _nwkskey[LORAMAC_NWKSKEY_LEN]; static uint8_t _appskey[LORAMAC_APPSKEY_LEN]; static uint8_t _appkey[LORAMAC_APPKEY_LEN]; @@ -86,13 +81,13 @@ void gnrc_lorawan_mlme_confirm(gnrc_lorawan_t *mac, mlme_confirm_t *confirm) void gnrc_lorawan_set_timer(gnrc_lorawan_t *mac, uint32_t us) { gnrc_netif_lorawan_t *lw_netif = container_of(mac, gnrc_netif_lorawan_t, mac); - xtimer_set_msg(&lw_netif->timer, ADJUST_DRIFT(us), &timeout_msg, thread_getpid()); + ztimer_set_msg(ZTIMER_MSEC, &lw_netif->timer, us/1000, &timeout_msg, thread_getpid()); } void gnrc_lorawan_remove_timer(gnrc_lorawan_t *mac) { gnrc_netif_lorawan_t *lw_netif = container_of(mac, gnrc_netif_lorawan_t, mac); - xtimer_remove(&lw_netif->timer); + ztimer_remove(ZTIMER_MSEC, &lw_netif->timer); } static inline void _set_be_addr(gnrc_lorawan_t *mac, uint8_t *be_addr) @@ -252,8 +247,8 @@ static void _init(gnrc_netif_t *netif) _set_be_addr(&netif->lorawan.mac, _devaddr); gnrc_lorawan_init(&netif->lorawan.mac, netif->lorawan.nwkskey, netif->lorawan.appskey); - xtimer_set_msg(&netif->lorawan.backoff_timer, - GNRC_LORAWAN_BACKOFF_WINDOW_TICK, + ztimer_set_msg(ZTIMER_MSEC, &netif->lorawan.backoff_timer, + GNRC_LORAWAN_BACKOFF_WINDOW_TICK / 1000, &backoff_msg, thread_getpid()); } @@ -305,8 +300,8 @@ static void _msg_handler(gnrc_netif_t *netif, msg_t *msg) break; case MSG_TYPE_MLME_BACKOFF_EXPIRE: gnrc_lorawan_mlme_backoff_expire_cb(&netif->lorawan.mac); - xtimer_set_msg(&netif->lorawan.backoff_timer, - GNRC_LORAWAN_BACKOFF_WINDOW_TICK, + ztimer_set_msg(ZTIMER_MSEC, &netif->lorawan.backoff_timer, + GNRC_LORAWAN_BACKOFF_WINDOW_TICK / 1000, &backoff_msg, thread_getpid()); default: break;