File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 1818
1919#include < unistd.h>
2020
21+ static struct timeval gtod0 = { 0 , 0 };
22+
2123extern " C" unsigned long millis ()
2224{
2325 timeval time;
2426 gettimeofday (&time, NULL );
25- return (time.tv_sec * 1000 ) + (time.tv_usec / 1000 );
27+ if (gtod0.tv_sec == 0 )
28+ memcpy (>od0, &time, sizeof gtod0);
29+ return ((time.tv_sec - gtod0.tv_sec ) * 1000 ) + ((time.tv_usec - gtod0.tv_usec ) / 1000 );
2630}
2731
2832extern " C" unsigned long micros ()
2933{
3034 timeval time;
3135 gettimeofday (&time, NULL );
32- return (time.tv_sec * 1000000 ) + time.tv_usec ;
36+ if (gtod0.tv_sec == 0 )
37+ memcpy (>od0, &time, sizeof gtod0);
38+ return ((time.tv_sec - gtod0.tv_sec ) * 1000000 ) + time.tv_usec - gtod0.tv_usec ;
3339}
3440
3541
Original file line number Diff line number Diff line change @@ -295,6 +295,9 @@ int main (int argc, char* const argv [])
295295 // install exit handler in case Esp.restart() is called
296296 atexit (cleanup);
297297
298+ // first call to millis(): now is millis() and micros() beginning
299+ millis ();
300+
298301 setup ();
299302 while (!user_exit)
300303 {
You can’t perform that action at this time.
0 commit comments