Skip to content

Commit 81583c5

Browse files
committed
feat: implement weaked _gettimeofday
Fixes #2129. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent b4d7bee commit 81583c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cores/arduino/wiring_time.h

Lines changed: 22 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy