mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/semtech-loramac: migrate to ztimer usage
This commit is contained in:
parent
6199ada6b5
commit
52748dd935
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user