mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ble/skald: switch from xtimer to ZTIMER_MSEC
This commit is contained in:
parent
de9f29cf42
commit
4540b6273b
@ -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)))
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user