Skip to content

gettimeofday incorrect value for tv_usec #3814

Closed
@BrandonLWhite

Description

@BrandonLWhite

The current implementation _gettimeofday_r is incorrectly setting the tv_usec field.

https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c#L104

According to http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html

tv_usec should be "This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million."

The current code is simply doing tp->tv_usec = micros();. This leads to the wall clock time advancing forward too quickly. I am certainly aware of the caveats of tracking wallclock (ie CLOCK_REALTIME) in ESP8266, but this is just making it far worse.

I have some ideas on how to square this away once and for all (crossing my fingers). I will try to follow-up with additional info or possibly a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions