File tree 2 files changed +11
-2
lines changed
2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 18
18
19
19
#include < unistd.h>
20
20
21
+ static struct timeval gtod0 = { 0 , 0 };
22
+
21
23
extern " C" unsigned long millis ()
22
24
{
23
25
timeval time ;
24
26
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 );
26
30
}
27
31
28
32
extern " C" unsigned long micros ()
29
33
{
30
34
timeval time ;
31
35
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 ;
33
39
}
34
40
35
41
Original file line number Diff line number Diff line change @@ -295,6 +295,9 @@ int main (int argc, char* const argv [])
295
295
// install exit handler in case Esp.restart() is called
296
296
atexit (cleanup);
297
297
298
+ // first call to millis(): now is millis() and micros() beginning
299
+ millis ();
300
+
298
301
setup ();
299
302
while (!user_exit)
300
303
{
You can’t perform that action at this time.
0 commit comments