Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: some simple xtimer->ztimer conversions #17892

Merged
merged 4 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ endif

ifneq (,$(filter csma_sender,$(USEMODULE)))
USEMODULE += random
USEMODULE += xtimer
USEMODULE += ztimer_usec
endif

ifneq (,$(filter dhcpv6_%,$(USEMODULE)))
Expand Down Expand Up @@ -167,7 +167,7 @@ endif

ifneq (,$(filter uhcpc,$(USEMODULE)))
USEMODULE += posix_inet
USEMODULE += xtimer
USEMODULE += ztimer_msec
endif

ifneq (,$(filter netdev_tap,$(USEMODULE)))
Expand Down Expand Up @@ -274,7 +274,6 @@ ifneq (,$(filter posix_sockets,$(USEMODULE)))
USEMODULE += random
USEMODULE += vfs
USEMODULE += posix_headers
USEMODULE += xtimer
endif

ifneq (,$(filter shell,$(USEMODULE)))
Expand Down Expand Up @@ -818,7 +817,7 @@ endif

ifneq (,$(filter suit_transport_coap, $(USEMODULE)))
USEMODULE += nanocoap_sock
USEMODULE += xtimer
USEMODULE += ztimer_msec
USEMODULE += sock_util
endif

Expand Down
4 changes: 2 additions & 2 deletions sys/net/application_layer/uhcp/uhcpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "net/af.h"
#include "net/sock/udp.h"
#include "net/uhcp.h"
#include "xtimer.h"
#include "ztimer.h"

/**
* @brief Request prefix from uhcp server
Expand Down Expand Up @@ -51,7 +51,7 @@ void uhcp_client(uhcp_iface_t iface)
res = sock_udp_recv(&sock, buf, sizeof(buf), 10U*US_PER_SEC, &remote);
if (res > 0) {
uhcp_handle_udp(buf, res, remote.addr.ipv6, remote.port, iface);
xtimer_sleep(60);
ztimer_sleep(ZTIMER_MSEC, 60 * MS_PER_SEC);
}
else {
LOG_ERROR("uhcp_client(): no reply received\n");
Expand Down
7 changes: 4 additions & 3 deletions sys/net/link_layer/csma_sender/csma_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#include <errno.h>
#include <stdbool.h>
#include <inttypes.h>
#include <kernel_defines.h>

#include "xtimer.h"
#include "ztimer.h"
#include "random.h"
#include "net/netdev.h"
#include "net/netopt.h"
Expand Down Expand Up @@ -152,15 +153,15 @@ int csma_sender_csma_ca_send(netdev_t *dev, iolist_t *iolist,

/* if we arrive here, then we must perform the CSMA/CA procedure
ourselves by software */
random_init(xtimer_now_usec());
random_init(ztimer_now(ZTIMER_USEC));
DEBUG("csma: Starting software CSMA/CA....\n");

int nb = 0, be = conf->min_be;

while (nb <= conf->max_be) {
/* delay for an adequate random backoff period */
uint32_t bp = choose_backoff_period(be, conf);
xtimer_usleep(bp);
ztimer_sleep(ZTIMER_USEC, bp);

/* try to send after a CCA */
res = send_if_cca(dev, iolist);
Expand Down
25 changes: 2 additions & 23 deletions sys/suit/transport/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "net/nanocoap_sock.h"
#include "thread.h"
#include "periph/pm.h"
#include "xtimer.h"
#include "ztimer.h"

#include "suit/transport/coap.h"
#include "net/sock/util.h"
Expand Down Expand Up @@ -112,27 +112,6 @@ ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
subtree->resources_numof);
}

static inline uint32_t _now(void)
{
return xtimer_now_usec();
}

static inline uint32_t deadline_from_interval(int32_t interval)
{
assert(interval >= 0);
return _now() + (uint32_t)interval;
}

static inline uint32_t deadline_left(uint32_t deadline)
{
int32_t left = (int32_t)(deadline - _now());

if (left < 0) {
left = 0;
}
return left;
}

static void _suit_handle_url(const char *url, coap_blksize_t blksize, void *work_buf)
{
LOG_INFO("suit_coap: downloading \"%s\"\n", url);
Expand Down Expand Up @@ -161,7 +140,7 @@ static void _suit_handle_url(const char *url, coap_blksize_t blksize, void *work
const riotboot_hdr_t *hdr = riotboot_slot_get_hdr(
riotboot_slot_other());
riotboot_hdr_print(hdr);
xtimer_sleep(1);
ztimer_sleep(ZTIMER_MSEC, 1 * MS_PER_SEC);

if (riotboot_hdr_validate(hdr) == 0) {
LOG_INFO("suit_coap: rebooting...\n");
Expand Down