From d8bb2d7c6d32781addf07afdc2b6514386b6f30e Mon Sep 17 00:00:00 2001 From: DavePutz Date: Mon, 8 Jun 2020 10:52:27 -0500 Subject: [PATCH] Correct ticks being returned from port_get_raw_ticks() Issue #2958 . Correct calculation of usec back to ticks in port_get_raw_ticks(). --- ports/esp32s2/supervisor/port.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 4c42f11af9..f5a4ae48e3 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -118,11 +118,12 @@ uint32_t port_get_saved_word(void) { uint64_t port_get_raw_ticks(uint8_t* subticks) { struct timeval tv_now; gettimeofday(&tv_now, NULL); - uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 32768; + // convert usec back to ticks + uint64_t all_subticks = (uint64_t)tv_now.tv_usec / 1024; if (subticks != NULL) { *subticks = all_subticks % 32; } - return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32; + return (uint64_t)tv_now.tv_sec * 1024L + all_subticks; } // Enable 1/1024 second tick.