Skip to content

Commit

Permalink
feat: implement weaked _gettimeofday
Browse files Browse the repository at this point in the history
Fixes stm32duino#2129.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Oct 26, 2023
1 parent b4d7bee commit 81583c5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cores/arduino/wiring_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "clock.h"
#include "dwt.h"
#include <sys/time.h> // for struct timeval

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81583c5

Please sign in to comment.