trigger refactoring
This commit is contained in:
parent
67bda5f088
commit
241d491625
|
@ -289,6 +289,14 @@ void Engine::OnTriggerStateProperState(efitick_t nowNt) {
|
|||
rpmCalculator.setSpinningUp(nowNt PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
void Engine::OnTriggerSynchronizationLost() {
|
||||
Engine *engine = this;
|
||||
EXPAND_Engine;
|
||||
|
||||
// Needed for early instant-RPM detection
|
||||
engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
void Engine::OnTriggerInvalidIndex(int currentIndex) {
|
||||
Engine *engine = this;
|
||||
EXPAND_Engine;
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
void OnTriggerStateProperState(efitick_t nowNt) override;
|
||||
void OnTriggerSyncronization(bool wasSynchronized) override;
|
||||
void OnTriggerInvalidIndex(int currentIndex) override;
|
||||
void OnTriggerSynchronizationLost() override;
|
||||
|
||||
void setConfig(persistent_config_s *config);
|
||||
injection_mode_e getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -122,7 +122,7 @@ bool RpmCalculator::checkIfSpinning(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUF
|
|||
/**
|
||||
* Also check if there were no trigger events
|
||||
*/
|
||||
bool noTriggerEventsForTooLong = nowNt - engine->triggerCentral.previousShaftEventTimeNt >= NT_PER_SECOND;
|
||||
bool noTriggerEventsForTooLong = nowNt - engine->triggerCentral.triggerState.previousShaftEventTimeNt >= NT_PER_SECOND;
|
||||
if (noRpmEventsForTooLong || noTriggerEventsForTooLong) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,6 @@ trigger_central_s::trigger_central_s() : hwEventCounters() {
|
|||
}
|
||||
|
||||
TriggerCentral::TriggerCentral() : trigger_central_s() {
|
||||
// we need this initial to have not_running at first invocation
|
||||
previousShaftEventTimeNt = (efitimems_t) -10 * NT_PER_SECOND;
|
||||
|
||||
clearCallbacks(&triggerListeneres);
|
||||
triggerState.resetTriggerState();
|
||||
|
@ -340,14 +338,6 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
|||
efiAssertVoid(CUSTOM_ERR_6638, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
||||
hwEventCounters[eventIndex]++;
|
||||
|
||||
if (timestamp - previousShaftEventTimeNt > NT_PER_SECOND) {
|
||||
/**
|
||||
* We are here if there is a time gap between now and previous shaft event - that means the engine is not running.
|
||||
* That means we have lost synchronization since the engine is not running :)
|
||||
*/
|
||||
triggerState.onSynchronizationLost(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
previousShaftEventTimeNt = timestamp;
|
||||
|
||||
/**
|
||||
* This invocation changes the state of triggerState
|
||||
|
|
|
@ -45,7 +45,6 @@ public:
|
|||
efitick_t previousVvtCamTime = 0;
|
||||
efitick_t previousVvtCamDuration = 0;
|
||||
|
||||
volatile efitick_t previousShaftEventTimeNt;
|
||||
private:
|
||||
IntListenerArray<15> triggerListeneres;
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ void TriggerState::resetTriggerState() {
|
|||
totalRevolutionCounter = 0;
|
||||
totalTriggerErrorCounter = 0;
|
||||
orderingErrorCounter = 0;
|
||||
// we need this initial to have not_running at first invocation
|
||||
previousShaftEventTimeNt = (efitimems_t) -10 * NT_PER_SECOND;
|
||||
lastDecodingErrorTime = US2NT(-10000000LL);
|
||||
someSortOfTriggerError = false;
|
||||
|
||||
|
@ -203,7 +205,7 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(int *prevIndexOut,
|
|||
// todo: prevIndex should be pre-calculated
|
||||
int prevIndex = TRIGGER_WAVEFORM(triggerIndexByAngle[(int)previousAngle]);
|
||||
|
||||
if (prevIndexOut != NULL) {
|
||||
if (prevIndexOut) {
|
||||
*prevIndexOut = prevIndex;
|
||||
}
|
||||
|
||||
|
@ -330,12 +332,6 @@ bool TriggerState::isEvenRevolution() const {
|
|||
return totalRevolutionCounter & 1;
|
||||
}
|
||||
|
||||
void TriggerState::onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
setShaftSynchronized(false);
|
||||
// Needed for early instant-RPM detection
|
||||
engine->rpmCalculator.setStopSpinning(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
||||
bool TriggerState::validateEventCounters(TriggerWaveform *triggerShape) const {
|
||||
bool isDecodingError = false;
|
||||
for (int i = 0;i < PWM_PHASE_MAX_WAVE_PER_PWM;i++) {
|
||||
|
@ -359,7 +355,7 @@ void TriggerState::onShaftSynchronization(const TriggerStateCallback triggerCycl
|
|||
efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape) {
|
||||
|
||||
|
||||
if (triggerCycleCallback != NULL) {
|
||||
if (triggerCycleCallback) {
|
||||
triggerCycleCallback(this);
|
||||
}
|
||||
|
||||
|
@ -389,6 +385,19 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg
|
|||
trigger_event_e const signal, efitick_t nowNt DECLARE_CONFIG_PARAMETER_SUFFIX) {
|
||||
ScopePerf perf(PE::DecodeTriggerEvent, static_cast<uint8_t>(signal));
|
||||
|
||||
if (nowNt - previousShaftEventTimeNt > NT_PER_SECOND) {
|
||||
/**
|
||||
* We are here if there is a time gap between now and previous shaft event - that means the engine is not running.
|
||||
* That means we have lost synchronization since the engine is not running :)
|
||||
*/
|
||||
setShaftSynchronized(false);
|
||||
if (triggerStateListener) {
|
||||
triggerStateListener->OnTriggerSynchronizationLost();
|
||||
}
|
||||
}
|
||||
previousShaftEventTimeNt = nowNt;
|
||||
|
||||
|
||||
bool useOnlyRisingEdgeForTrigger = CONFIG(useOnlyRisingEdgeForTrigger);
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class TriggerStateListener {
|
|||
virtual void OnTriggerStateProperState(efitick_t nowNt) = 0;
|
||||
virtual void OnTriggerSyncronization(bool wasSynchronized) = 0;
|
||||
virtual void OnTriggerInvalidIndex(int currentIndex) = 0;
|
||||
virtual void OnTriggerSynchronizationLost() = 0;
|
||||
};
|
||||
|
||||
typedef void (*TriggerStateCallback)(TriggerState *);
|
||||
|
@ -73,10 +74,7 @@ public:
|
|||
bool validateEventCounters(TriggerWaveform *triggerShape) const;
|
||||
void onShaftSynchronization(const TriggerStateCallback triggerCycleCallback,
|
||||
efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape);
|
||||
/**
|
||||
* Resets synchronization flag and alerts rpm_calculator to reset engine spinning flag.
|
||||
*/
|
||||
void onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
|
||||
bool isValidIndex(TriggerWaveform *triggerShape) const;
|
||||
float getTriggerDutyCycle(int index);
|
||||
|
@ -86,6 +84,7 @@ public:
|
|||
*/
|
||||
bool shaft_is_synchronized;
|
||||
efitick_t mostRecentSyncTime;
|
||||
volatile efitick_t previousShaftEventTimeNt;
|
||||
|
||||
void setTriggerErrorState();
|
||||
|
||||
|
|
Loading…
Reference in New Issue