Merge pull request #15805 from haukepetersen/opt_skald_ztimer
ble/skald: switch from xtimer to ZTIMER_MSEC
This commit is contained in:
commit
69f7baa478
@ -916,9 +916,13 @@ endif
|
|||||||
|
|
||||||
ifneq (,$(filter skald,$(USEMODULE)))
|
ifneq (,$(filter skald,$(USEMODULE)))
|
||||||
FEATURES_REQUIRED += radio_nrfble
|
FEATURES_REQUIRED += radio_nrfble
|
||||||
|
FEATURES_OPTIONAL += periph_rtt
|
||||||
USEMODULE += nrfble
|
USEMODULE += nrfble
|
||||||
USEMODULE += xtimer
|
|
||||||
USEMODULE += random
|
USEMODULE += random
|
||||||
|
USEMODULE += ztimer_msec
|
||||||
|
ifneq (,$(filter periph_rtt,$(USEMODULE)))
|
||||||
|
USEMODULE += ztimer_periph_rtt
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter bluetil_addr,$(USEMODULE)))
|
ifneq (,$(filter bluetil_addr,$(USEMODULE)))
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "xtimer.h"
|
#include "ztimer.h"
|
||||||
#include "net/ble.h"
|
#include "net/ble.h"
|
||||||
#include "net/netdev/ble.h"
|
#include "net/netdev/ble.h"
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @brief Advertising interval in microseconds
|
* @brief Advertising interval in microseconds
|
||||||
*/
|
*/
|
||||||
#ifndef CONFIG_SKALD_INTERVAL
|
#ifndef CONFIG_SKALD_INTERVAL_MS
|
||||||
#define CONFIG_SKALD_INTERVAL (1 * US_PER_SEC)
|
#define CONFIG_SKALD_INTERVAL_MS (1000U)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,8 +143,8 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
netdev_ble_pkt_t pkt; /**< packet holding the advertisement (GAP) data */
|
netdev_ble_pkt_t pkt; /**< packet holding the advertisement (GAP) data */
|
||||||
xtimer_t timer; /**< timer for scheduling advertising events */
|
ztimer_t timer; /**< timer for scheduling advertising events */
|
||||||
uint32_t last; /**< last timer trigger (for offset compensation) */
|
ztimer_now_t last; /**< last timer trigger (for offset compensation) */
|
||||||
uint8_t cur_chan; /**< keep track of advertising channels */
|
uint8_t cur_chan; /**< keep track of advertising channels */
|
||||||
} skald_ctx_t;
|
} skald_ctx_t;
|
||||||
|
|
||||||
|
|||||||
@ -12,12 +12,12 @@ menuconfig KCONFIG_USEMODULE_SKALD
|
|||||||
|
|
||||||
if KCONFIG_USEMODULE_SKALD
|
if KCONFIG_USEMODULE_SKALD
|
||||||
|
|
||||||
config SKALD_INTERVAL
|
config SKALD_INTERVAL_MS
|
||||||
int "Advertising interval in microseconds"
|
int "Advertising interval in microseconds"
|
||||||
default 1000000
|
default 1000
|
||||||
help
|
help
|
||||||
Configure advertising interval in microseconds. Default value is 1
|
Configure advertising interval in milliseconds. Default value is 1
|
||||||
second which is 1000000 microseconds.
|
second which is 1000 milliseconds.
|
||||||
|
|
||||||
config ADV_CH_37_DISABLE
|
config ADV_CH_37_DISABLE
|
||||||
bool "Disable advertising on channel 37"
|
bool "Disable advertising on channel 37"
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define JITTER_MIN (0U) /* 0ms */
|
#define JITTER_MIN (0U) /* 0ms */
|
||||||
#define JITTER_MAX (10000U) /* 10ms */
|
#define JITTER_MAX (10U) /* 10ms */
|
||||||
|
|
||||||
#define ADV_CHAN_NUMOF sizeof(_adv_chan)
|
#define ADV_CHAN_NUMOF sizeof(_adv_chan)
|
||||||
#define ADV_AA (0x8e89bed6) /* access address */
|
#define ADV_AA (0x8e89bed6) /* access address */
|
||||||
@ -63,18 +63,18 @@ static void _stop_radio(void)
|
|||||||
|
|
||||||
static void _sched_next(skald_ctx_t *ctx)
|
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
|
/* schedule next advertising event, adding a random jitter between
|
||||||
* 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */
|
* 0ms and 10ms (see spec v5.0-vol6-b-4.4.2.2.1) */
|
||||||
ctx->last += random_uint32_range(JITTER_MIN, JITTER_MAX);
|
ctx->last += random_uint32_range(JITTER_MIN, JITTER_MAX);
|
||||||
/* compensate the time passed since the timer triggered last by using the
|
/* compensate the time passed since the timer triggered last by using the
|
||||||
* current value of the timer */
|
* 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)
|
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
|
/* advertise on the next adv channel - or skip this event if the radio is
|
||||||
* busy */
|
* busy */
|
||||||
@ -98,7 +98,7 @@ static void _on_radio_evt(netdev_t *netdev, netdev_event_t event)
|
|||||||
if (event == NETDEV_EVENT_TX_COMPLETE) {
|
if (event == NETDEV_EVENT_TX_COMPLETE) {
|
||||||
skald_ctx_t *ctx = _radio->context;
|
skald_ctx_t *ctx = _radio->context;
|
||||||
_stop_radio();
|
_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 */
|
/* initialize advertising context */
|
||||||
ctx->timer.callback = _on_adv_evt;
|
ctx->timer.callback = _on_adv_evt;
|
||||||
ctx->timer.arg = ctx;
|
ctx->timer.arg = ctx;
|
||||||
ctx->last = xtimer_now_usec();
|
ctx->last = ztimer_now(ZTIMER_MSEC);
|
||||||
ctx->cur_chan = 0;
|
ctx->cur_chan = 0;
|
||||||
ctx->pkt.flags = (BLE_ADV_NONCON_IND | BLE_LL_FLAG_TXADD);
|
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);
|
assert(ctx);
|
||||||
|
|
||||||
xtimer_remove(&ctx->timer);
|
ztimer_remove(ZTIMER_MSEC, &ctx->timer);
|
||||||
if (_radio->context == (void *)ctx) {
|
if (_radio->context == (void *)ctx) {
|
||||||
_stop_radio();
|
_stop_radio();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user