diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-11-17 17:45:12 -0600 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-11-17 17:45:41 -0600 |
| commit | 9206925bf8d2e3d8220b59200ee50c3e4c8a64d2 (patch) | |
| tree | 63119952834c09e17f269c57bd589a65a20bda37 | |
| parent | 1bc770c3dc308b91184e8cab52f6f4cabdda99fc (diff) | |
esp32s2: port_get_raw_ticks: Use a more efficient, monotonic routine
While trying to debug #3572, I noticed that I would frequently break in
the midst of gettimeofday and that the routine get_adjusted_boot_time
had to take and release locks. Furthermore, we don't want "adjusted"
boot time, which could go forwards or backwards depending on the
adjustment (such as setting the clock used by gettimeofday() to the network
time)
| -rw-r--r-- | ports/esp32s2/supervisor/port.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 47d0c7f46..876ad739d 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -191,14 +191,14 @@ uint32_t port_get_saved_word(void) { } uint64_t port_get_raw_ticks(uint8_t* subticks) { - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - // convert usec back to ticks - uint64_t all_subticks = (uint64_t)(tv_now.tv_usec * 2) / 71; + // Convert microseconds to subticks of 1/32768 seconds + // 32768/1000000 = 64/15625 in lowest terms + // this arithmetic overflows after 570 years + int64_t all_subticks = esp_timer_get_time() * 512 / 15625; if (subticks != NULL) { *subticks = all_subticks % 32; } - return (uint64_t)tv_now.tv_sec * 1024L + all_subticks / 32; + return all_subticks / 32; } // Enable 1/1024 second tick. |
