Skip to content

Commit

Permalink
sys/syscalls: empty gettimeofday() unless 64bit present
Browse files Browse the repository at this point in the history
Instead of requesting the 64bit for gettimeofday, make it an empty
function unless 64 bit is already present
  • Loading branch information
fjmolinas committed Mar 2, 2022
1 parent 0bb7ecc commit 1a64bc1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
1 change: 0 additions & 1 deletion cpu/native/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ config CPU_ARCH_NATIVE

# needed modules
select MODULE_PERIPH if TEST_KCONFIG
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT

config CPU_CORE_NATIVE
bool
Expand Down
5 changes: 0 additions & 5 deletions cpu/native/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ ifneq (,$(filter socket_zep,$(USEMODULE)))
endif
endif

ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
# requires 64bit for syscalls
USEMODULE += ztimer64_xtimer_compat
endif

USEMODULE += periph

# UART is needed by startup.c
Expand Down
12 changes: 9 additions & 3 deletions cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "xtimer.h"
#include "stdio_base.h"

#include "kernel_defines.h"
#include "native_internal.h"

#define ENABLE_DEBUG 0
Expand Down Expand Up @@ -474,16 +475,21 @@ int getpid(void)
return -1;
}

#ifdef MODULE_XTIMER
int _gettimeofday(struct timeval *tp, void *restrict tzp)
{
(void) tzp;
(void)tzp;
(void)tp;
#if (IS_USED(MODULE_XTIMER) && !IS_USED(MODULE_ZTIMER_XTIMER_COMPAT)) || \
(IS_USED(MODULE_XTIMER) && IS_USED(MODULE_ZTIMER64_XTIMER_COMPAT))
uint64_t now = xtimer_now_usec64();
tp->tv_sec = now / US_PER_SEC;
tp->tv_usec = now - tp->tv_sec;
return 0;
}
#else
return -1;
#endif
}


/**
* set up native internal syscall symbols
Expand Down
1 change: 0 additions & 1 deletion sys/Kconfig.newlib
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ config MODULE_NEWLIB_SYSCALLS_DEFAULT
default y
depends on !HAVE_CUSTOM_NEWLIB_SYSCALLS
select MODULE_DIV
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
help
Default implementation of newlib system calls.

Expand Down
4 changes: 0 additions & 4 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ ifneq (,$(filter newlib,$(USEMODULE)))
endif
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
USEMODULE += div
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
# requires 64bit timestamps when using xtimer
USEMODULE += ztimer64_xtimer_compat
endif
endif
endif

Expand Down
15 changes: 6 additions & 9 deletions sys/newlib_syscalls_default/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,25 +630,22 @@ int _kill(pid_t pid, int sig)
return -1;
}

#ifdef MODULE_XTIMER
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp)
{
(void) r;
(void) tzp;
(void)r;
(void)tzp;
(void)tp;
#if (IS_USED(MODULE_XTIMER) && !IS_USED(MODULE_ZTIMER_XTIMER_COMPAT)) || \
(IS_USED(MODULE_XTIMER) && IS_USED(MODULE_ZTIMER64_XTIMER_COMPAT))
uint64_t now = xtimer_now_usec64();
tp->tv_sec = div_u64_by_1000000(now);
tp->tv_usec = now - (tp->tv_sec * US_PER_SEC);
return 0;
}
#else
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp)
{
(void) tp;
(void) tzp;
r->_errno = ENOSYS;
return -1;
}
#endif
}

/**
* Current process times (not implemented).
Expand Down

0 comments on commit 1a64bc1

Please sign in to comment.