Skip to content

Commit

Permalink
Merge pull request #16340 from haukepetersen/opt_sixlowpanctx_ztimer
Browse files Browse the repository at this point in the history
net/grnc/sixlowpan/ctx: use ztimer_msec if available
  • Loading branch information
miri64 committed Apr 16, 2021
2 parents 922611b + feeffb2 commit 286e4ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ endif

ifneq (,$(filter gnrc_sixlowpan_ctx,$(USEMODULE)))
USEMODULE += ipv6_addr
USEMODULE += xtimer
ifeq (,$(filter ztimer_msec,$(USEMODULE)))
USEMODULE += xtimer
endif
endif

ifneq (,$(filter gnrc_ipv6_default,$(USEMODULE)))
Expand Down
11 changes: 10 additions & 1 deletion sys/net/gnrc/network_layer/sixlowpan/ctx/gnrc_sixlowpan_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

#include "mutex.h"
#include "net/gnrc/sixlowpan/ctx.h"
#if IS_USED(MODULE_ZTIMER_MSEC)
#include "ztimer.h"
#include "timex.h"
#else
#include "xtimer.h"
#endif

#define ENABLE_DEBUG 0
#include "debug.h"
Expand Down Expand Up @@ -131,7 +136,11 @@ gnrc_sixlowpan_ctx_t *gnrc_sixlowpan_ctx_update(uint8_t id, const ipv6_addr_t *p

static uint32_t _current_minute(void)
{
return xtimer_now_usec() / (US_PER_SEC * 60);
#if IS_USED(MODULE_ZTIMER_MSEC)
return ztimer_now(ZTIMER_MSEC) / (MS_PER_SEC * SEC_PER_MIN);
#else
return xtimer_now_usec() / (US_PER_SEC * SEC_PER_MIN);
#endif
}

static void _update_lifetime(uint8_t id)
Expand Down
13 changes: 12 additions & 1 deletion sys/shell/commands/sc_gnrc_6ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
#include "net/gnrc/sixlowpan/ctx.h"
#include "net/sixlowpan/nd.h"
#include "timex.h"
#include "xtimer.h"

#if IS_USED(MODULE_ZTIMER_MSEC)
#include "ztimer.h"
static ztimer_t del_timer[GNRC_SIXLOWPAN_CTX_SIZE];
#else
#include "xtimer.h"
static xtimer_t del_timer[GNRC_SIXLOWPAN_CTX_SIZE];
#endif

void _del_cb(void *ptr)
{
gnrc_sixlowpan_ctx_t *ctx = ptr;
Expand Down Expand Up @@ -120,8 +126,13 @@ int _gnrc_6ctx_del(char *cmd_str, char *ctx_str)
ctx->ltime = 0;
del_timer[cid].callback = _del_cb;
del_timer[cid].arg = ctx;
#if IS_USED(MODULE_ZTIMER_MSEC)
ztimer_set(ZTIMER_MSEC, &del_timer[cid],
SIXLOWPAN_ND_MIN_CTX_CHANGE_SEC_DELAY * MS_PER_SEC);
#else
xtimer_set(&del_timer[cid],
SIXLOWPAN_ND_MIN_CTX_CHANGE_SEC_DELAY * US_PER_SEC);
#endif
}
}
else {
Expand Down

0 comments on commit 286e4ec

Please sign in to comment.