From 4540b6273b22a8b744dbcdd9b10bdc5c7376c6e3 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 19 Jan 2021 13:00:53 +0100 Subject: [PATCH] ble/skald: switch from xtimer to ZTIMER_MSEC --- sys/Makefile.dep | 6 +++++- sys/include/net/skald.h | 10 +++++----- sys/net/ble/skald/Kconfig | 8 ++++---- sys/net/ble/skald/skald.c | 14 +++++++------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 8a343cd8a4..f5adedd2e9 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -916,9 +916,13 @@ endif ifneq (,$(filter skald,$(USEMODULE))) FEATURES_REQUIRED += radio_nrfble + FEATURES_OPTIONAL += periph_rtt USEMODULE += nrfble - USEMODULE += xtimer USEMODULE += random + USEMODULE += ztimer_msec + ifneq (,$(filter periph_rtt,$(USEMODULE))) + USEMODULE += ztimer_periph_rtt + endif endif ifneq (,$(filter bluetil_addr,$(USEMODULE))) diff --git a/sys/include/net/skald.h b/sys/include/net/skald.h index ab893d5eff..e955444e7b 100644 --- a/sys/include/net/skald.h +++ b/sys/include/net/skald.h @@ -46,7 +46,7 @@ #include -#include "xtimer.h" +#include "ztimer.h" #include "net/ble.h" #include "net/netdev/ble.h" @@ -62,8 +62,8 @@ extern "C" { /** * @brief Advertising interval in microseconds */ -#ifndef CONFIG_SKALD_INTERVAL -#define CONFIG_SKALD_INTERVAL (1 * US_PER_SEC) +#ifndef CONFIG_SKALD_INTERVAL_MS +#define CONFIG_SKALD_INTERVAL_MS (1000U) #endif /** @@ -143,8 +143,8 @@ typedef struct { */ typedef struct { netdev_ble_pkt_t pkt; /**< packet holding the advertisement (GAP) data */ - xtimer_t timer; /**< timer for scheduling advertising events */ - uint32_t last; /**< last timer trigger (for offset compensation) */ + ztimer_t timer; /**< timer for scheduling advertising events */ + ztimer_now_t last; /**< last timer trigger (for offset compensation) */ uint8_t cur_chan; /**< keep track of advertising channels */ } skald_ctx_t; diff --git a/sys/net/ble/skald/Kconfig b/sys/net/ble/skald/Kconfig index 92950a51e1..12f4a378b7 100644 --- a/sys/net/ble/skald/Kconfig +++ b/sys/net/ble/skald/Kconfig @@ -12,12 +12,12 @@ menuconfig KCONFIG_USEMODULE_SKALD if KCONFIG_USEMODULE_SKALD -config SKALD_INTERVAL +config SKALD_INTERVAL_MS int "Advertising interval in microseconds" - default 1000000 + default 1000 help - Configure advertising interval in microseconds. Default value is 1 - second which is 1000000 microseconds. + Configure advertising interval in milliseconds. Default value is 1 + second which is 1000 milliseconds. config ADV_CH_37_DISABLE bool "Disable advertising on channel 37" diff --git a/sys/net/ble/skald/skald.c b/sys/net/ble/skald/skald.c index b85952edda..8433991af6 100644 --- a/sys/net/ble/skald/skald.c +++ b/sys/net/ble/skald/skald.c @@ -40,7 +40,7 @@ #include "debug.h" #define JITTER_MIN (0U) /* 0ms */ -#define JITTER_MAX (10000U) /* 10ms */ +#define JITTER_MAX (10U) /* 10ms */ #define ADV_CHAN_NUMOF sizeof(_adv_chan) #define ADV_AA (0x8e89bed6) /* access address */ @@ -63,18 +63,18 @@ static void _stop_radio(void) static void _sched_next(skald_ctx_t *ctx) { - ctx->last += CONFIG_SKALD_INTERVAL; + ctx->last += CONFIG_SKALD_INTERVAL_MS; /* schedule next advertising event, adding a random jitter between * 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */ ctx->last += random_uint32_range(JITTER_MIN, JITTER_MAX); /* compensate the time passed since the timer triggered last by using the * current value of the timer */ - xtimer_set(&ctx->timer, (ctx->last - xtimer_now_usec())); + ztimer_set(ZTIMER_MSEC, &ctx->timer, (ctx->last - ztimer_now(ZTIMER_MSEC))); } static void _on_adv_evt(void *arg) { - skald_ctx_t *ctx = (skald_ctx_t *)arg; + skald_ctx_t *ctx = arg; /* advertise on the next adv channel - or skip this event if the radio is * busy */ @@ -98,7 +98,7 @@ static void _on_radio_evt(netdev_t *netdev, netdev_event_t event) if (event == NETDEV_EVENT_TX_COMPLETE) { skald_ctx_t *ctx = _radio->context; _stop_radio(); - xtimer_set(&ctx->timer, 150); + _on_adv_evt(ctx); } } @@ -124,7 +124,7 @@ void skald_adv_start(skald_ctx_t *ctx) /* initialize advertising context */ ctx->timer.callback = _on_adv_evt; ctx->timer.arg = ctx; - ctx->last = xtimer_now_usec(); + ctx->last = ztimer_now(ZTIMER_MSEC); ctx->cur_chan = 0; ctx->pkt.flags = (BLE_ADV_NONCON_IND | BLE_LL_FLAG_TXADD); @@ -136,7 +136,7 @@ void skald_adv_stop(skald_ctx_t *ctx) { assert(ctx); - xtimer_remove(&ctx->timer); + ztimer_remove(ZTIMER_MSEC, &ctx->timer); if (_radio->context == (void *)ctx) { _stop_radio(); }