8000 emulation on host: millis()/micros() now start at 0 by d-a-v · Pull Request #7810 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
emulation on host: millis()/micros() now start at 0
  • Loading branch information
d-a-v committed Jan 5, 2021
commit 926791b092b70314fba647acd16120a9cad1e73f
5 changes: 3 additions & 2 deletions tests/host/common/Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@

#include <sys/time.h>
#include "Arduino.h"
#include "ArduinoMain.h"

#include <unistd.h>

extern "C" unsigned long millis()
{
timeval time;
gettimeofday(&time, NULL);
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
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;
return ((time.tv_sec - gtod0.tv_sec) * 1000000) + time.tv_usec - gtod0.tv_usec;
}


Expand Down
4 changes: 4 additions & 0 deletions tests/host/common/ArduinoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <Arduino.h>
#include <user_interface.h> // wifi_get_ip_info()
#include <ArduinoMain.h>

#include <signal.h>
#include <unistd.h>
Expand All @@ -51,6 +52,7 @@ bool restore_tty = false;
bool mockdebug = false;
int mock_port_shifter = MOCK_PORT_SHIFTER;
const char* fspath = nullptr;
struct timeval gtod0;

#define STDIN STDIN_FILENO

Expand Down Expand Up @@ -295,6 +297,8 @@ int main (int argc, char* const argv [])
// install exit handler in case Esp.restart() is called
atexit(cleanup);

gettimeofday(&gtod0, nullptr);

setup();
while (!user_exit)
{
Expand Down
9 changes: 9 additions & 0 deletions tests/host/common/ArduinoMain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#ifndef __ESP8266ARDUINOMAIN_H
#define __ESP8266ARDUINOMAIN_H

#include <sys/time.h>

extern struct timeval gtod0;

#endif // __ESP8266ARDUINOMAIN_H
0