summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-08-31 00:49:19 +1000
committerDamien George <damien@micropython.org>2020-08-31 00:49:58 +1000
commit40153b800a8324f6cf3e47dd71cafcf90c3c4718 (patch)
treed546eecd5c922aa0947fdf4ad0158e53b5e4983d
parent836bca9956d9f02b9c0f6f396dc76cbd1586de10 (diff)
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>
-rw-r--r--ports/esp32/mphalport.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index 5e526df66..3a46edf1f 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -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