From f23f3c0d2f968093214b863c951758cd2af375c4 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 17 Nov 2015 12:50:48 +0100 Subject: [PATCH] sys: newlib: use xtimer_now64() for gettimeofday() --- sys/newlib/syscalls.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sys/newlib/syscalls.c b/sys/newlib/syscalls.c index 28ab23c03..2630dab02 100644 --- a/sys/newlib/syscalls.c +++ b/sys/newlib/syscalls.c @@ -38,6 +38,12 @@ #include "uart_stdio.h" +#ifdef MODULE_XTIMER +#include +#include "div.h" +#include "xtimer.h" +#endif + /** * @brief manage the heap */ @@ -322,3 +328,14 @@ int _kill(pid_t pid, int sig) errno = ESRCH; /* not implemented yet */ return -1; } + +#ifdef MODULE_XTIMER +int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp) +{ + (void)tzp; + uint64_t now = xtimer_now64(); + tp->tv_sec = div_u64_by_1000000(now); + tp->tv_usec = now - (tp->tv_sec * SEC_IN_USEC); + return 0; +} +#endif