Skip to content
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