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
|
# needed modules
|
||||||
select MODULE_PERIPH if TEST_KCONFIG
|
select MODULE_PERIPH if TEST_KCONFIG
|
||||||
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
|
|
||||||
|
|
||||||
config CPU_CORE_NATIVE
|
config CPU_CORE_NATIVE
|
||||||
bool
|
bool
|
||||||
|
@ -40,9 +40,12 @@ ifneq (,$(filter socket_zep,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
ifneq (,$(filter libc_gettimeofday,$(USEMODULE)))
|
||||||
# requires 64bit for syscalls
|
USEMODULE += xtimer
|
||||||
USEMODULE += ztimer64_xtimer_compat
|
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||||
|
# requires 64bit timestamps
|
||||||
|
USEMODULE += ztimer64_xtimer_compat
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
USEMODULE += periph
|
USEMODULE += periph
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
#include "stdio_base.h"
|
#include "stdio_base.h"
|
||||||
|
|
||||||
|
#include "kernel_defines.h"
|
||||||
#include "native_internal.h"
|
#include "native_internal.h"
|
||||||
|
|
||||||
#define ENABLE_DEBUG 0
|
#define ENABLE_DEBUG 0
|
||||||
@ -474,10 +475,10 @@ int getpid(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MODULE_XTIMER
|
#if (IS_USED(MODULE_LIBC_GETTIMEOFDAY))
|
||||||
int _gettimeofday(struct timeval *tp, void *restrict tzp)
|
int _gettimeofday(struct timeval *tp, void *restrict tzp)
|
||||||
{
|
{
|
||||||
(void) tzp;
|
(void)tzp;
|
||||||
uint64_t now = xtimer_now_usec64();
|
uint64_t now = xtimer_now_usec64();
|
||||||
tp->tv_sec = now / US_PER_SEC;
|
tp->tv_sec = now / US_PER_SEC;
|
||||||
tp->tv_usec = now - tp->tv_sec;
|
tp->tv_usec = now - tp->tv_sec;
|
||||||
|
@ -121,6 +121,10 @@ PSEUDOMODULES += log
|
|||||||
PSEUDOMODULES += log_printfnoformat
|
PSEUDOMODULES += log_printfnoformat
|
||||||
PSEUDOMODULES += log_color
|
PSEUDOMODULES += log_color
|
||||||
PSEUDOMODULES += lora
|
PSEUDOMODULES += lora
|
||||||
|
## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday
|
||||||
|
## @brief Includes implementation of gettimeofday()
|
||||||
|
##
|
||||||
|
PSEUDOMODULES += libc_gettimeofday
|
||||||
|
|
||||||
## @defgroup pseudomodule_mpu_stack_guard mpu_stack_guard
|
## @defgroup pseudomodule_mpu_stack_guard mpu_stack_guard
|
||||||
## @brief MPU based 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:38: error: '_IOFBF' undeclared (first use in this function)
|
||||||
# - lua/liolib.c:671:46: error: '_IOLBF' undeclared (first use in this function)
|
# - lua/liolib.c:671:46: error: '_IOLBF' undeclared (first use in this function)
|
||||||
FEATURES_BLACKLIST += picolibc
|
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 += tinydtls_sock_dtls
|
||||||
USEMODULE += ztimer_usec
|
USEMODULE += ztimer_usec
|
||||||
endif
|
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
|
USEMODULE += random
|
||||||
endif
|
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
|
# wolfssl is only supported by 32 bit architectures
|
||||||
FEATURES_REQUIRED += arch_32bit
|
FEATURES_REQUIRED += arch_32bit
|
||||||
|
@ -49,9 +49,15 @@ config MODULE_NEWLIB
|
|||||||
config MODULE_PICOLIBC
|
config MODULE_PICOLIBC
|
||||||
bool "Picolibc"
|
bool "Picolibc"
|
||||||
depends on HAS_PICOLIBC
|
depends on HAS_PICOLIBC
|
||||||
|
|
||||||
endchoice
|
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.newlib"
|
||||||
rsource "Kconfig.picolibc"
|
rsource "Kconfig.picolibc"
|
||||||
|
|
||||||
|
@ -18,10 +18,17 @@ config MODULE_NEWLIB_SYSCALLS_DEFAULT
|
|||||||
default y
|
default y
|
||||||
depends on !HAVE_CUSTOM_NEWLIB_SYSCALLS
|
depends on !HAVE_CUSTOM_NEWLIB_SYSCALLS
|
||||||
select MODULE_DIV
|
select MODULE_DIV
|
||||||
select MODULE_ZTIMER64_XTIMER_COMPAT if MODULE_ZTIMER_XTIMER_COMPAT
|
|
||||||
help
|
help
|
||||||
Default implementation of newlib system calls.
|
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
|
endif # MODULE_NEWLIB
|
||||||
|
|
||||||
config HAVE_CUSTOM_NEWLIB_SYSCALLS
|
config HAVE_CUSTOM_NEWLIB_SYSCALLS
|
||||||
|
@ -242,9 +242,12 @@ ifneq (,$(filter newlib,$(USEMODULE)))
|
|||||||
endif
|
endif
|
||||||
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
|
||||||
USEMODULE += div
|
USEMODULE += div
|
||||||
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
ifneq (,$(filter libc_gettimeofday,$(USEMODULE)))
|
||||||
# requires 64bit timestamps when using xtimer
|
USEMODULE += xtimer
|
||||||
USEMODULE += ztimer64_xtimer_compat
|
ifneq (,$(filter ztimer_xtimer_compat,$(USEMODULE)))
|
||||||
|
# requires 64bit timestamps
|
||||||
|
USEMODULE += ztimer64_xtimer_compat
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
@ -630,24 +630,16 @@ int _kill(pid_t pid, int sig)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MODULE_XTIMER
|
#if (IS_USED(MODULE_LIBC_GETTIMEOFDAY))
|
||||||
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp)
|
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp, void *restrict tzp)
|
||||||
{
|
{
|
||||||
(void) r;
|
(void)tzp;
|
||||||
(void) tzp;
|
(void)r;
|
||||||
uint64_t now = xtimer_now_usec64();
|
uint64_t now = xtimer_now_usec64();
|
||||||
tp->tv_sec = div_u64_by_1000000(now);
|
tp->tv_sec = div_u64_by_1000000(now);
|
||||||
tp->tv_usec = now - (tp->tv_sec * US_PER_SEC);
|
tp->tv_usec = now - (tp->tv_sec * US_PER_SEC);
|
||||||
return 0;
|
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
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,5 +2,6 @@ include ../Makefile.tests_common
|
|||||||
|
|
||||||
USEMODULE += cpp11-compat
|
USEMODULE += cpp11-compat
|
||||||
USEMODULE += xtimer
|
USEMODULE += xtimer
|
||||||
|
USEMODULE += libc_gettimeofday
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
Loading…
Reference in New Issue
Block a user