mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/syscalls: add libc_gettimeofday
Conditionally implement gettimeofday() if module is included, this avoids including ztimer64 even when not needed
This commit is contained in:
parent
feda38ceb5
commit
0819660303
@ -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
|
||||
|
@ -40,10 +40,13 @@ ifneq (,$(filter socket_zep,$(USEMODULE)))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter libc_gettimeofday,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||
# requires 64bit for syscalls
|
||||
# requires 64bit timestamps
|
||||
USEMODULE += ztimer64_xtimer_compat
|
||||
endif
|
||||
endif
|
||||
|
||||
USEMODULE += periph
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "xtimer.h"
|
||||
#include "stdio_base.h"
|
||||
|
||||
#include "kernel_defines.h"
|
||||
#include "native_internal.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
@ -474,7 +475,7 @@ int getpid(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef MODULE_XTIMER
|
||||
#if (IS_USED(MODULE_LIBC_GETTIMEOFDAY))
|
||||
int _gettimeofday(struct timeval *tp, void *restrict tzp)
|
||||
{
|
||||
(void)tzp;
|
||||
|
@ -121,6 +121,10 @@ PSEUDOMODULES += log
|
||||
PSEUDOMODULES += log_printfnoformat
|
||||
PSEUDOMODULES += log_color
|
||||
PSEUDOMODULES += lora
|
||||
## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday
|
||||
## @brief Includes implementation of gettimeofday()
|
||||
##
|
||||
PSEUDOMODULES += libc_gettimeofday
|
||||
|
||||
## @defgroup pseudomodule_mpu_stack_guard mpu_stack_guard
|
||||
## @brief MPU based stack guard
|
||||
|
@ -17,3 +17,11 @@ FEATURES_BLACKLIST += arch_riscv
|
||||
# - lua/liolib.c:671:38: error: '_IOFBF' undeclared (first use in this function)
|
||||
# - lua/liolib.c:671:46: error: '_IOLBF' undeclared (first use in this function)
|
||||
FEATURES_BLACKLIST += picolibc
|
||||
|
||||
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
||||
ifneq (,$(filter native,$(CPU)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
@ -14,3 +14,11 @@ ifneq (,$(filter sock_dtls,$(USEMODULE)))
|
||||
USEMODULE += tinydtls_sock_dtls
|
||||
USEMODULE += ztimer_usec
|
||||
endif
|
||||
|
||||
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
||||
ifneq (,$(filter native,$(CPU)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
@ -82,5 +82,13 @@ ifneq (,$(filter wolfcrypt_random,$(USEMODULE)))
|
||||
USEMODULE += random
|
||||
endif
|
||||
|
||||
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
||||
ifneq (,$(filter native,$(CPU)))
|
||||
USEMODULE += libc_gettimeofday
|
||||
endif
|
||||
|
||||
# wolfssl is only supported by 32 bit architectures
|
||||
FEATURES_REQUIRED += arch_32bit
|
||||
|
@ -49,9 +49,15 @@ config MODULE_NEWLIB
|
||||
config MODULE_PICOLIBC
|
||||
bool "Picolibc"
|
||||
depends on HAS_PICOLIBC
|
||||
|
||||
endchoice
|
||||
|
||||
config MODULE_LIBC_GETTIMEOFDAY
|
||||
bool
|
||||
select MODULE_XTIMER
|
||||
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
|
||||
help
|
||||
Support for gettimeofday()
|
||||
|
||||
rsource "Kconfig.newlib"
|
||||
rsource "Kconfig.picolibc"
|
||||
|
||||
|
@ -18,10 +18,17 @@ 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.
|
||||
|
||||
config MODULE_LIBC_GETTIMEOFDAY
|
||||
bool
|
||||
select MODULE_NEWLIB_SYSCALLS_DEFAULT if MODULE_NEWLIB
|
||||
select MODULE_XTIMER
|
||||
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
|
||||
help
|
||||
Support for gettimeofday()
|
||||
|
||||
endif # MODULE_NEWLIB
|
||||
|
||||
config HAVE_CUSTOM_NEWLIB_SYSCALLS
|
||||
|
@ -242,12 +242,15 @@ ifneq (,$(filter newlib,$(USEMODULE)))
|
||||
endif
|
||||
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
||||
USEMODULE += div
|
||||
ifneq (,$(filter libc_gettimeofday,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||
# requires 64bit timestamps when using xtimer
|
||||
# requires 64bit timestamps
|
||||
USEMODULE += ztimer64_xtimer_compat
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(filter posix_select,$(USEMODULE)))
|
||||
ifneq (,$(filter posix_sockets,$(USEMODULE)))
|
||||
|
@ -630,24 +630,16 @@ int _kill(pid_t pid, int sig)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef MODULE_XTIMER
|
||||
#if (IS_USED(MODULE_LIBC_GETTIMEOFDAY))
|
||||
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp)
|
||||
{
|
||||
(void) r;
|
||||
(void)tzp;
|
||||
(void)r;
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -2,5 +2,6 @@ include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += cpp11-compat
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += libc_gettimeofday
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
Loading…
Reference in New Issue
Block a user