Skip to content

Commit

Permalink
ESP32: use esp_timer_get_time() for millis/micros which returns an ui…
Browse files Browse the repository at this point in the history
…nt64_t and thus hardly wraps
  • Loading branch information
folkertvanheusden committed Oct 8, 2024
1 parent 5a43b9a commit f25daa0
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ uint32_t get_uint32_t(const uint8_t *const p)
uint64_t get_micros()
{
#if defined(ARDUINO)
#if defined(ESP32)
return esp_timer_get_time();
#else
return micros();
#endif
#else
struct timespec tv { };
if (clock_gettime(CLOCK_REALTIME, &tv) == -1) {
Expand All @@ -194,17 +198,7 @@ uint64_t get_micros()

uint64_t get_millis()
{
#if defined(ARDUINO)
return millis();
#else
struct timespec tv { };
if (clock_gettime(CLOCK_REALTIME, &tv) == -1) {
DOLOG(logging::ll_error, "get_millis", "-", "clock_gettime failed: %s", strerror(errno));
return 0;
}

return uint64_t(tv.tv_sec) * uint64_t(1000) + uint64_t(tv.tv_nsec / 1000000);
#endif
return get_micros() / 1000;
}

#if defined(TEENSY4_1)
Expand Down

0 comments on commit f25daa0

Please sign in to comment.