Browse Source

Adapt to RIOT ztimer and ztimer64 (#988)

RIOT-OS currently changes xtimer to ztimer
Karl Fessel 4 years ago
parent
commit
770ca8c90c

+ 3 - 1
core/shared/platform/riot/riot_thread.c

@@ -8,6 +8,8 @@
 #include "platform_api_extension.h"
 
 #include <panic.h>
+#include <sema.h>
+#include <ztimer.h>
 
 /* clang-format off */
 #define bh_assert(v) do {                                   \
@@ -373,7 +375,7 @@ os_cond_wait_internal(korp_cond *cond, korp_mutex *mutex, bool timed,
     if (timed)
         sema_wait(&node->sem);
     else
-        sema_wait_timed(&node->sem, useconds);
+        sema_wait_timed_ztimer(&node->sem, ZTIMER_USEC, useconds);
     mutex_lock(mutex);
 
     /* Remove wait node from wait list */

+ 22 - 2
core/shared/platform/riot/riot_time.c

@@ -5,10 +5,30 @@
  */
 
 #include "platform_api_vmcore.h"
-#include <xtimer.h>
+#include <ztimer64.h>
+#include <kernel_defines.h>
 
+#if IS_USED(MODULE_ZTIMER64_USEC)
 uint64
 os_time_get_boot_microsecond()
 {
-    return xtimer_now_usec64();
+    return ztimer64_now(ZTIMER64_USEC);
 }
+#elif IS_USED(MODULE_ZTIMER64_MSEC)
+uint64
+os_time_get_boot_microsecond()
+{
+    return ztimer64_now(ZTIMER64_MSEC) * 1000;
+}
+#else
+#ifdef __GNUC__
+__attribute__((weak)) uint64
+os_time_get_boot_microsecond();
+#endif
+uint64
+os_time_get_boot_microsecond()
+{
+    static uint64_t times;
+    return ++times;
+}
+#endif

+ 2 - 1
product-mini/platforms/riot/Makefile

@@ -5,7 +5,8 @@ BOARD ?= native
 # This has to be the absolute path to the RIOT base directory:
 RIOTBASE ?= $(CURDIR)/../../../../RIOT
 
-USEMODULE += xtimer
+USEMODULE += ztimer64_msec
+USEMODULE += ztimer_usec
 USEMODULE += sema
 
 WPEDANTIC := 0