diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index 8a0162b477..c02457f1a5 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -18,18 +18,24 @@ #include +static struct timeval gtod0 = { 0, 0 }; + extern "C" unsigned long millis() { timeval time; gettimeofday(&time, NULL); - return (time.tv_sec * 1000) + (time.tv_usec / 1000); + if (gtod0.tv_sec == 0) + memcpy(>od0, &time, sizeof gtod0); + return ((time.tv_sec - gtod0.tv_sec) * 1000) + ((time.tv_usec - gtod0.tv_usec) / 1000); } extern "C" unsigned long micros() { timeval time; gettimeofday(&time, NULL); - return (time.tv_sec * 1000000) + time.tv_usec; + if (gtod0.tv_sec == 0) + memcpy(>od0, &time, sizeof gtod0); + return ((time.tv_sec - gtod0.tv_sec) * 1000000) + time.tv_usec - gtod0.tv_usec; } diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index a9d8d696f6..051ca0dbc1 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -295,6 +295,9 @@ int main (int argc, char* const argv []) // install exit handler in case Esp.restart() is called atexit(cleanup); + // first call to millis(): now is millis() and micros() beginning + millis(); + setup(); while (!user_exit) {