From 81583c57056b8aba47c56e4bb3eb588dae669f88 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 23 Oct 2023 10:08:24 +0200 Subject: [PATCH] feat: implement weaked _gettimeofday Fixes #2129. Signed-off-by: Frederic Pillon --- cores/arduino/wiring_time.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cores/arduino/wiring_time.h b/cores/arduino/wiring_time.h index 74b1978c92..4b32537629 100644 --- a/cores/arduino/wiring_time.h +++ b/cores/arduino/wiring_time.h @@ -22,6 +22,7 @@ #include "clock.h" #include "dwt.h" +#include // for struct timeval #ifdef __cplusplus extern "C" { @@ -86,6 +87,27 @@ static inline void delayMicroseconds(uint32_t us) #endif } +/** + * \brief gives the number of seconds and microseconds since the Epoch + * + * based on millisecond since last power on. + * + * \note The function is declared as weak to be overwritten in case of other + * implementations in user file (using RTC values for example). + * + * \param tv argument is a struct timeval + * \param tz argument is a struct timezone (unused) + * + * \return 0 + */ +int __attribute__((weak)) _gettimeofday(struct timeval *tv, void *tz) +{ + (void)tz; + tv->tv_sec = getCurrentMillis() / 1000; + tv->tv_usec = getCurrentMicros() - (tv->tv_sec * 1000000); // get remaining microseconds + return 0; +} + #ifdef __cplusplus } #endif