Skip to content

Commit 81583c5

Browse files
committed
feat: implement weaked _gettimeofday
Fixes stm32duino#2129. Signed-off-by: Frederic Pillon <[email protected]>
1 parent b4d7bee commit 81583c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: cores/arduino/wiring_time.h

+22
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "clock.h"
2424
#include "dwt.h"
25+
#include <sys/time.h> // for struct timeval
2526

2627
#ifdef __cplusplus
2728
extern "C" {
@@ -86,6 +87,27 @@ static inline void delayMicroseconds(uint32_t us)
8687
#endif
8788
}
8889

90+
/**
91+
* \brief gives the number of seconds and microseconds since the Epoch
92+
*
93+
* based on millisecond since last power on.
94+
*
95+
* \note The function is declared as weak to be overwritten in case of other
96+
* implementations in user file (using RTC values for example).
97+
*
98+
* \param tv argument is a struct timeval
99+
* \param tz argument is a struct timezone (unused)
100+
*
101+
* \return 0
102+
*/
103+
int __attribute__((weak)) _gettimeofday(struct timeval *tv, void *tz)
104+
{
105+
(void)tz;
106+
tv->tv_sec = getCurrentMillis() / 1000;
107+
tv->tv_usec = getCurrentMicros() - (tv->tv_sec * 1000000); // get remaining microseconds
108+
return 0;
109+
}
110+
89111
#ifdef __cplusplus
90112
}
91113
#endif

0 commit comments

Comments
 (0)