Skip to content

Commit

Permalink
pkg/semtech-loramac: migrate to ztimer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Aug 11, 2020
1 parent fe3d686 commit 161c1da
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions pkg/semtech-loramac/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions pkg/semtech-loramac/contrib/semtech_loramac_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/semtech-loramac/contrib/semtech_loramac_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* @}
*/

#include "xtimer.h"
#include "ztimer.h"
#include "thread.h"
#include "semtech-loramac/timer.h"

extern kernel_pid_t semtech_loramac_pid;

void TimerInit(TimerEvent_t *obj, void (*cb)(void))
{
obj->dev = (xtimer_t) { 0 };
obj->dev = (ztimer_t) { 0 };
obj->running = 0;
obj->cb = cb;
}
Expand All @@ -41,43 +41,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);
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/semtech-loramac/include/semtech-loramac/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
extern "C" {
#endif

#include "xtimer.h"
#include "ztimer.h"
#include "msg.h"

#include "semtech_loramac.h"
Expand All @@ -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;
Expand Down

0 comments on commit 161c1da

Please sign in to comment.