1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/lorawan: use ztimer_msec if not rtc

This commit is contained in:
Francisco Molina 2021-11-11 10:36:33 +01:00
parent 12ade5a8b5
commit b247dbca97
3 changed files with 24 additions and 5 deletions

View File

@ -27,7 +27,7 @@ USEPKG += semtech-loramac
USEMODULE += $(DRIVER)
USEMODULE += fmt
FEATURES_REQUIRED += periph_rtc
FEATURES_OPTIONAL += periph_rtc
# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the

View File

@ -1,4 +1,10 @@
BOARD_INSUFFICIENT_MEMORY := \
arduino-duemilanove \
arduino-leonardo \
arduino-nano \
arduino-uno \
atmega328p-xplained-mini \
atmega328p \
nucleo-f031k6 \
nucleo-f042k6 \
nucleo-l011k4 \

View File

@ -27,7 +27,12 @@
#include "thread.h"
#include "fmt.h"
#if IS_USED(MODULE_PERIPH_RTC)
#include "periph/rtc.h"
#else
#include "timex.h"
#include "ztimer.h"
#endif
#include "net/loramac.h"
#include "semtech_loramac.h"
@ -45,7 +50,7 @@
#endif
/* Messages are sent every 20s to respect the duty cycle on each channel */
#define PERIOD (20U)
#define PERIOD_S (20U)
#define SENDER_PRIO (THREAD_PRIORITY_MAIN - 1)
static kernel_pid_t sender_pid;
@ -58,6 +63,9 @@ static sx127x_t sx127x;
#if IS_USED(MODULE_SX126X)
static sx126x_t sx126x;
#endif
#if !IS_USED(MODULE_PERIPH_RTC)
static ztimer_t timer;
#endif
static const char *message = "This is RIOT!";
@ -65,7 +73,7 @@ static uint8_t deveui[LORAMAC_DEVEUI_LEN];
static uint8_t appeui[LORAMAC_APPEUI_LEN];
static uint8_t appkey[LORAMAC_APPKEY_LEN];
static void rtc_cb(void *arg)
static void _alarm_cb(void *arg)
{
(void) arg;
msg_t msg;
@ -74,12 +82,17 @@ static void rtc_cb(void *arg)
static void _prepare_next_alarm(void)
{
#if IS_USED(MODULE_PERIPH_RTC)
struct tm time;
rtc_get_time(&time);
/* set initial alarm */
time.tm_sec += PERIOD;
time.tm_sec += PERIOD_S;
mktime(&time);
rtc_set_alarm(&time, rtc_cb, NULL);
rtc_set_alarm(&time, _alarm_cb, NULL);
#else
timer.callback = _alarm_cb;
ztimer_set(ZTIMER_MSEC, &timer, PERIOD_S * MS_PER_SEC);
#endif
}
static void _send_message(void)