only:more timer API

This commit is contained in:
Andrey 2023-06-15 17:30:55 -04:00
parent 8ca5db6413
commit a63265bffb
2 changed files with 11 additions and 2 deletions

View File

@ -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);
}

View File

@ -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;