From a63265bffb31c6af7a6c2aa5d2056c5df5302d6b Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 15 Jun 2023 17:30:55 -0400 Subject: [PATCH] only:more timer API --- firmware/util/timer.cpp | 7 +++++-- firmware/util/timer.h | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/firmware/util/timer.cpp b/firmware/util/timer.cpp index 53f2885a3f..bac7e57e39 100644 --- a/firmware/util/timer.cpp +++ b/firmware/util/timer.cpp @@ -51,7 +51,7 @@ float Timer::getElapsedUs() const { return getElapsedUs(getTimeNowNt()); } -float Timer::getElapsedUs(efitick_t nowNt) const { +uint32_t Timer::getElapsedNt(efitick_t nowNt) const { auto deltaNt = nowNt - m_lastReset; // Yes, things can happen slightly in the future if we get a lucky interrupt between @@ -64,8 +64,11 @@ float Timer::getElapsedUs(efitick_t nowNt) const { if (deltaNt > UINT32_MAX - 1) { deltaNt = UINT32_MAX - 1; } + return deltaNt; +} - auto delta32 = (uint32_t)deltaNt; +float Timer::getElapsedUs(efitick_t nowNt) const { + auto delta32 = getElapsedNt(nowNt); return NT2US(delta32); } diff --git a/firmware/util/timer.h b/firmware/util/timer.h index 7fba060194..8fed6337a7 100644 --- a/firmware/util/timer.h +++ b/firmware/util/timer.h @@ -32,11 +32,17 @@ public: float getElapsedUs() const; // WOW yes returns US while parameter is NT float getElapsedUs(efitick_t nowNt) const; + // too many options for the API probably? + uint32_t getElapsedNt(efitick_t nowNt) const; // Perform an atomic update event based on the passed timestamp, // returning the delta between the last reset and the provided timestamp float getElapsedSecondsAndReset(efitick_t nowNt); + efitick_t get() { + return m_lastReset; + } + private: // Use not-quite-minimum value to avoid overflow efitick_t m_lastReset;