add timer since last trigger tooth (#2004)
* add elapsed time to timer * store trigger time * fsio method * don't do a 64b divide Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
82c30dadf8
commit
f1f64bd3e5
|
@ -71,6 +71,7 @@ static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt");
|
|||
static LENameOrdinalPair leCrankingRpm(LE_METHOD_CRANKING_RPM, "cranking_rpm");
|
||||
static LENameOrdinalPair leStartupFuelPumpDuration(LE_METHOD_STARTUP_FUEL_PUMP_DURATION, "startup_fuel_pump_duration");
|
||||
static LENameOrdinalPair leInShutdown(LE_METHOD_IN_SHUTDOWN, "in_shutdown");
|
||||
static LENameOrdinalPair leTimeSinceTrigger(LE_METHOD_TIME_SINCE_TRIGGER_EVENT, "time_since_trigger");
|
||||
|
||||
#include "fsio_names.def"
|
||||
|
||||
|
@ -140,6 +141,7 @@ FsioValue getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
return engine->triggerCentral.getVVTPosition();
|
||||
#endif
|
||||
case LE_METHOD_TIME_SINCE_TRIGGER_EVENT:
|
||||
return engine->triggerCentral.getTimeSinceTriggerEvent();
|
||||
case LE_METHOD_TIME_SINCE_BOOT:
|
||||
#if EFI_MAIN_RELAY_CONTROL
|
||||
// in main relay control mode, we return the number of seconds since the ignition is turned on
|
||||
|
|
|
@ -426,6 +426,8 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
|||
|
||||
engine->onTriggerSignalEvent(timestamp);
|
||||
|
||||
m_lastEventTimer.reset(timestamp);
|
||||
|
||||
int eventIndex = (int) signal;
|
||||
efiAssertVoid(CUSTOM_TRIGGER_EVENT_TYPE, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
||||
hwEventCounters[eventIndex]++;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "listener_array.h"
|
||||
#include "trigger_decoder.h"
|
||||
#include "trigger_central_generated.h"
|
||||
#include "timer.h"
|
||||
|
||||
class Engine;
|
||||
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
@ -43,6 +44,10 @@ public:
|
|||
void resetCounters();
|
||||
void validateCamVvtCounters();
|
||||
|
||||
float getTimeSinceTriggerEvent() const {
|
||||
return m_lastEventTimer.getElapsedSeconds();
|
||||
}
|
||||
|
||||
TriggerNoiseFilter noiseFilter;
|
||||
|
||||
trigger_type_e vvtTriggerType;
|
||||
|
@ -67,6 +72,9 @@ public:
|
|||
TriggerWaveform vvtShape;
|
||||
|
||||
TriggerFormDetails triggerFormDetails;
|
||||
|
||||
// Keep track of the last time we got a valid trigger event
|
||||
Timer m_lastEventTimer;
|
||||
};
|
||||
|
||||
void triggerInfo(void);
|
||||
|
|
|
@ -5,6 +5,10 @@ void Timer::reset() {
|
|||
m_lastReset = getTimeNowNt();
|
||||
}
|
||||
|
||||
void Timer::reset(efitick_t nowNt) {
|
||||
m_lastReset = nowNt;
|
||||
}
|
||||
|
||||
bool Timer::hasElapsedSec(float seconds) const {
|
||||
return hasElapsedMs(seconds * 1e3);
|
||||
}
|
||||
|
@ -25,3 +29,15 @@ bool Timer::hasElapsedUs(float microseconds) const {
|
|||
|
||||
return delta32 > USF2NT(microseconds);
|
||||
}
|
||||
|
||||
float Timer::getElapsedSeconds() const {
|
||||
auto delta = getTimeNowNt() - m_lastReset;
|
||||
|
||||
if (delta > UINT32_MAX - 1) {
|
||||
delta = UINT32_MAX - 1;
|
||||
}
|
||||
|
||||
auto delta32 = (uint32_t)delta;
|
||||
|
||||
return NT2US(delta32);
|
||||
}
|
||||
|
|
|
@ -5,10 +5,19 @@
|
|||
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;
|
||||
|
||||
private:
|
||||
efitick_t m_lastReset = INT64_MIN;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue