rusefi-1/firmware/util/timer.h

30 lines
854 B
C++

#pragma once
#include "efitime.h"
class Timer {
public:
void reset();
// Reset the timer to a known timestamp (don't take a timestamp internally)
void reset(efitick_t nowNt);
bool hasElapsedSec(float seconds) const;
bool hasElapsedMs(float ms) const;
bool hasElapsedUs(float us) const;
// Return the elapsed time since the last reset.
// If the elapsed time is longer than 2^32 timer tick counts,
// then a time period representing 2^32 counts will be returned.
float getElapsedSeconds() const;
float getElapsedSeconds(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);
private:
// Use not-quite-minimum value to avoid overflow
efitick_t m_lastReset = INT64_MIN / 8;
};