Commit 40153b80 authored by Damien George's avatar Damien George

esp32/mphalport: Fix mp_hal_time_ns offset.

gettimeofday returns seconds since 2000/1/1 so needs to be adjusted to
seconds since 1970/1/1 to give the correct return value of mp_hal_time_ns.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent 836bca99
......@@ -45,6 +45,7 @@
#include "py/mpstate.h"
#include "py/mphal.h"
#include "extmod/misc.h"
#include "lib/timeutils/timeutils.h"
#include "lib/utils/pyexec.h"
#include "mphalport.h"
......@@ -199,7 +200,10 @@ void mp_hal_delay_us(uint32_t us) {
uint64_t mp_hal_time_ns(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)tv.tv_sec * 1000000000ULL + (uint64_t)tv.tv_usec * 1000ULL;
// gettimeofday returns seconds since 2000/1/1
uint64_t ns = timeutils_seconds_since_2000_to_nanoseconds_since_1970(tv.tv_sec);
ns += (uint64_t)tv.tv_usec * 1000ULL;
return ns;
}
// Wake up the main task if it is sleeping
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment