From 64ff3d1d4f41b9f3aed5f012d93aa7ac0b52edd2 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Thu, 4 Nov 2021 13:20:23 +0100 Subject: [PATCH] pkg/lwip: use ztimer_msec instead of xtimer --- pkg/lwip/Makefile.dep | 2 +- pkg/lwip/contrib/sys_arch.c | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/lwip/Makefile.dep b/pkg/lwip/Makefile.dep index 9903a67418..012ffc1119 100644 --- a/pkg/lwip/Makefile.dep +++ b/pkg/lwip/Makefile.dep @@ -87,7 +87,7 @@ endif ifneq (,$(filter lwip_contrib,$(USEMODULE))) USEMODULE += sema - USEMODULE += xtimer + USEMODULE += ztimer_msec endif ifneq (,$(filter lwip_netif,$(USEMODULE))) diff --git a/pkg/lwip/contrib/sys_arch.c b/pkg/lwip/contrib/sys_arch.c index da78504d8b..a6b7b50c4e 100644 --- a/pkg/lwip/contrib/sys_arch.c +++ b/pkg/lwip/contrib/sys_arch.c @@ -28,7 +28,7 @@ #include "msg.h" #include "sema.h" #include "thread.h" -#include "xtimer.h" +#include "ztimer.h" #define _MSG_SUCCESS (0x5cac) #define _MSG_TIMEOUT (0x5cad) @@ -40,7 +40,7 @@ void sys_init(void) u32_t sys_now(void) { - return (uint32_t)(xtimer_now_usec64() / US_PER_MS); + return ztimer_now(ZTIMER_MSEC); } err_t sys_mutex_new(sys_mutex_t *mutex) @@ -85,14 +85,14 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t count) { LWIP_ASSERT("invalid semaphore", sys_sem_valid(sem)); if (count != 0) { - uint64_t stop, start; - start = xtimer_now_usec64(); - int res = sema_wait_timed((sema_t *)sem, count * US_PER_MS); - stop = xtimer_now_usec64() - start; + uint32_t stop, start; + start = ztimer_now(ZTIMER_MSEC); + int res = sema_wait_timed_ztimer((sema_t *)sem, ZTIMER_MSEC, count); + stop = ztimer_now(ZTIMER_MSEC); if (res == -ETIMEDOUT) { return SYS_ARCH_TIMEOUT; } - return (u32_t)(stop / US_PER_MS); + return stop - start; } else { sema_wait((sema_t *)sem); @@ -142,21 +142,20 @@ static void _mbox_timeout(void *arg) u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) { msg_t m; - xtimer_t timer = { .callback = _mbox_timeout, .arg = &mbox->mbox }; - uint64_t start, stop; + ztimer_t timer = { .callback = _mbox_timeout, .arg = &mbox->mbox }; + uint32_t start, stop; - start = xtimer_now_usec64(); + start = ztimer_now(ZTIMER_MSEC); if (timeout > 0) { - uint64_t u_timeout = (timeout * US_PER_MS); - xtimer_set64(&timer, u_timeout); + ztimer_set(ZTIMER_MSEC, &timer, timeout); } mbox_get(&mbox->mbox, &m); - stop = xtimer_now_usec64(); - xtimer_remove(&timer); /* in case timer did not time out */ + stop = ztimer_now(ZTIMER_MSEC); + ztimer_remove(ZTIMER_MSEC, &timer); /* in case timer did not time out */ switch (m.type) { case _MSG_SUCCESS: *msg = m.content.ptr; - return (u32_t)((stop - start) / US_PER_MS); + return stop - start; case _MSG_TIMEOUT: break; default: /* should not happen */