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: Damien George <damien@micropython.org>
v1.13-wasp-os
Damien George 2020-08-31 00:49:19 +10:00
parent 836bca9956
commit 40153b800a
1 changed files with 5 additions and 1 deletions

View File

@ -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