diff --git a/pkg/semtech-loramac/Makefile.dep b/pkg/semtech-loramac/Makefile.dep index 84d9dbab21..1bd02cfb96 100644 --- a/pkg/semtech-loramac/Makefile.dep +++ b/pkg/semtech-loramac/Makefile.dep @@ -6,6 +6,9 @@ USEMODULE += semtech_loramac_mac_region USEMODULE += semtech_loramac_crypto USEMODULE += semtech_loramac_arch +USEMODULE += ztimer_msec +USEMODULE += ztimer_periph_rtt + # The build fails on MSP430 because the toolchain doesn't provide # EXIT_SUCCESS/EXIT_FAILURE macros FEATURES_BLACKLIST += arch_msp430 diff --git a/pkg/semtech-loramac/contrib/semtech_loramac_radio.c b/pkg/semtech-loramac/contrib/semtech_loramac_radio.c index a0cf9be655..e37bb6f9ee 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac_radio.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac_radio.c @@ -122,7 +122,7 @@ void SX127XSetTxConfig(RadioModems_t modem, int8_t power, uint32_t fdev, sx127x_set_tx_power(&sx127x, power); sx127x_set_preamble_length(&sx127x, preambleLen); sx127x_set_rx_single(&sx127x, false); - sx127x_set_tx_timeout(&sx127x, timeout * US_PER_MS); /* base unit us, LoRaMAC ms */ + sx127x_set_tx_timeout(&sx127x, timeout); /* base unit ms, LoRaMAC ms */ } uint32_t SX127XTimeOnAir(RadioModems_t modem, uint8_t pktLen) @@ -153,7 +153,7 @@ void SX127XStandby(void) void SX127XRx(uint32_t timeout) { - sx127x_set_rx_timeout(&sx127x, timeout * US_PER_MS); + sx127x_set_rx_timeout(&sx127x, timeout); sx127x_set_rx(&sx127x); } diff --git a/pkg/semtech-loramac/contrib/semtech_loramac_timer.c b/pkg/semtech-loramac/contrib/semtech_loramac_timer.c index d1ed507407..3a04e5a737 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac_timer.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac_timer.c @@ -19,7 +19,7 @@ * @} */ -#include "xtimer.h" +#include "ztimer.h" #include "thread.h" #include "semtech-loramac/timer.h" @@ -27,7 +27,14 @@ extern kernel_pid_t semtech_loramac_pid; void TimerInit(TimerEvent_t *obj, void (*cb)(void)) { - obj->dev = (xtimer_t) { 0 }; + obj->dev = (ztimer_t) { + .base = { + .next = NULL, + .offset = 0, + }, + .callback = NULL, + .arg = NULL, + }; obj->running = 0; obj->cb = cb; } @@ -41,43 +48,43 @@ void TimerReset(TimerEvent_t *obj) void TimerStart(TimerEvent_t *obj) { obj->running = 1; - xtimer_t *timer = &(obj->dev); + ztimer_t *timer = &(obj->dev); msg_t *msg = &(obj->msg); msg->type = MSG_TYPE_MAC_TIMEOUT; msg->content.value = (uintptr_t)obj->cb; - xtimer_set_msg(timer, obj->timeout, msg, semtech_loramac_pid); + ztimer_set_msg(ZTIMER_MSEC, timer, obj->timeout, msg, semtech_loramac_pid); } void TimerStop(TimerEvent_t *obj) { obj->running = 0; - xtimer_remove(&(obj->dev)); + ztimer_remove(ZTIMER_MSEC, &(obj->dev)); } void TimerSetValue(TimerEvent_t *obj, uint32_t value) { if (obj->running) { - xtimer_remove(&(obj->dev)); + ztimer_remove(ZTIMER_MSEC, &(obj->dev)); } - obj->timeout = value * US_PER_MS; + obj->timeout = value; } TimerTime_t TimerGetCurrentTime(void) { - uint64_t CurrentTime = xtimer_now_usec64() / US_PER_MS; + uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC); return (TimerTime_t)CurrentTime; } TimerTime_t TimerGetElapsedTime(TimerTime_t savedTime) { - uint64_t CurrentTime = xtimer_now_usec64() / US_PER_MS; + uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC); return (TimerTime_t)(CurrentTime - savedTime); } TimerTime_t TimerGetFutureTime(TimerTime_t eventInFuture) { - uint64_t CurrentTime = xtimer_now_usec64() / US_PER_MS; + uint64_t CurrentTime = ztimer_now(ZTIMER_MSEC); return (TimerTime_t)(CurrentTime + eventInFuture); } diff --git a/pkg/semtech-loramac/include/semtech-loramac/timer.h b/pkg/semtech-loramac/include/semtech-loramac/timer.h index cce20f2083..54e01a4380 100644 --- a/pkg/semtech-loramac/include/semtech-loramac/timer.h +++ b/pkg/semtech-loramac/include/semtech-loramac/timer.h @@ -26,7 +26,7 @@ extern "C" { #endif -#include "xtimer.h" +#include "ztimer.h" #include "msg.h" #include "semtech_loramac.h" @@ -37,7 +37,7 @@ extern "C" { typedef struct TimerEvent_s { uint32_t timeout; /**< Timer timeout in us */ uint8_t running; /**< Check if timer is running */ - xtimer_t dev; /**< xtimer instance attached to this LoRaMAC timer */ + ztimer_t dev; /**< ztimer instance attached to this LoRaMAC timer */ msg_t msg; /**< message attacher to this LoRaMAC timer */ void (*cb)(void); /**< callback to call when timer timeout */ } TimerEvent_t;