Skip to content

feat: implement weaked _gettimeofday #2151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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