Get the current wall clock time. See remarks below.
Syntax
#include <sys/time.h>
int gettimeofday (struct timeval *restrict tp, void *restrict tzp);
Parameters
-
tp
The structure that will receive the current time.
-
tzp
Optional argument specifying the timezone. This argument is currently ignored.
Return Value
The return value is null if successful. Otherwise, the return value is negative and errno is set:
-
EINVAL
The
tp
argument is not valid.
Remarks
Since most microcontrollers do not contain a real-time (wall time) clock, this system call returns the current system timer counting since the system was booted. In order to get the correct wall time, compensate with a real-time clock.
The time resulution is decided by the system tick timer, which operates at 1 KHz (1 millisecond resolution).
The internal counter is an unsigned 32-bit value, be wary of overflow.