rusefi-1/firmware/util/timer.h

40 lines
1.2 KiB
C
Raw Normal View History

2020-11-30 16:35:06 -08:00
#pragma once
#include "efitime.h"
2021-03-11 21:43:48 -08:00
/**
* Helper class with "has X amount of time elapsed since most recent reset" methods
* Brand new instances have most recent reset time far in the past, i.e. "hasElapse" is true for any reasonable range
*/
2020-11-30 16:35:06 -08:00
class Timer {
public:
Timer();
2020-11-30 16:35:06 -08:00
void reset();
// Reset the timer to a known timestamp (don't take a timestamp internally)
void reset(efitick_t nowNt);
// returns timer to the most original-as-constructed state
void init();
2020-11-30 16:35:06 -08:00
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;
2021-11-14 11:53:44 -08:00
float getElapsedUs() const;
// WOW yes returns US while parameter is NT
float getElapsedUs(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);
2020-11-30 16:35:06 -08:00
private:
// Use not-quite-minimum value to avoid overflow
efitick_t m_lastReset;
2020-11-30 16:35:06 -08:00
};