Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulation on host: millis()/micros() now start at 0 #7810

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions tests/host/common/Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

#include <unistd.h>

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(&gtod0, &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(&gtod0, &time, sizeof gtod0);
return ((time.tv_sec - gtod0.tv_sec) * 1000000) + time.tv_usec - gtod0.tv_usec;
}


Expand Down
3 changes: 3 additions & 0 deletions tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down