mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
emulation on host: millis()/micros() now start at 0 (#7810)
emulation on host: millis()/micros() now start at 0
This commit is contained in:
parent
100a8df33f
commit
43f44e4b13
@ -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(>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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user