refactoring trigger

This commit is contained in:
rusefi 2020-01-24 13:42:09 -05:00
parent 3056154fe6
commit aabc50e7a9
4 changed files with 19 additions and 18 deletions

View File

@ -381,7 +381,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
return; return;
} }
if (triggerState.isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE)) { if (triggerState.isValidIndex(&ENGINE(triggerCentral.triggerShape))) {
ScopePerf perf(PE::ShaftPositionListeners); ScopePerf perf(PE::ShaftPositionListeners);
#if TRIGGER_EXTREME_LOGGING #if TRIGGER_EXTREME_LOGGING

View File

@ -263,8 +263,8 @@ void TriggerStateWithRunningStatistics::runtimeStatistics(efitick_t nowNt DECLAR
} }
} }
bool TriggerState::isValidIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { bool TriggerState::isValidIndex(TriggerWaveform *triggerShape) const {
return currentCycle.current_index < getTriggerSize(); return currentCycle.current_index < triggerShape->getSize();
} }
static trigger_wheel_e eventIndex[6] = { T_PRIMARY, T_PRIMARY, T_SECONDARY, T_SECONDARY, T_CHANNEL_3, T_CHANNEL_3 }; static trigger_wheel_e eventIndex[6] = { T_PRIMARY, T_PRIMARY, T_SECONDARY, T_SECONDARY, T_CHANNEL_3, T_CHANNEL_3 };
@ -379,11 +379,8 @@ void TriggerState::handleTriggerError(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
void TriggerState::onShaftSynchronization(const TriggerStateCallback triggerCycleCallback, void TriggerState::onShaftSynchronization(const TriggerStateCallback triggerCycleCallback,
efitick_t nowNt, trigger_wheel_e triggerWheel DECLARE_ENGINE_PARAMETER_SUFFIX) { efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape) {
setShaftSynchronized(true);
// this call would update duty cycle values
nextTriggerEvent()
;
if (triggerCycleCallback != NULL) { if (triggerCycleCallback != NULL) {
triggerCycleCallback(this); triggerCycleCallback(this);
@ -392,7 +389,7 @@ void TriggerState::onShaftSynchronization(const TriggerStateCallback triggerCycl
startOfCycleNt = nowNt; startOfCycleNt = nowNt;
resetCurrentCycleState(); resetCurrentCycleState();
incrementTotalEventCounter(); incrementTotalEventCounter();
totalEventCountBase += getTriggerSize(); totalEventCountBase += triggerShape->getSize();
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
if (printTriggerDebug) { if (printTriggerDebug) {
@ -607,10 +604,10 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
printf("sync=%d index=%d size=%d\r\n", printf("sync=%d index=%d size=%d\r\n",
shaft_is_synchronized, shaft_is_synchronized,
currentCycle.current_index, currentCycle.current_index,
getTriggerSize()); triggerShape->getSize());
} }
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
unsigned int endOfCycleIndex = getTriggerSize() - (CONFIG(useOnlyRisingEdgeForTrigger) ? 2 : 1); unsigned int endOfCycleIndex = triggerShape->getSize() - (CONFIG(useOnlyRisingEdgeForTrigger) ? 2 : 1);
isSynchronizationPoint = !shaft_is_synchronized || (currentCycle.current_index >= endOfCycleIndex); isSynchronizationPoint = !shaft_is_synchronized || (currentCycle.current_index >= endOfCycleIndex);
@ -620,7 +617,7 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
printf("isSynchronizationPoint=%d index=%d size=%d\r\n", printf("isSynchronizationPoint=%d index=%d size=%d\r\n",
isSynchronizationPoint, isSynchronizationPoint,
currentCycle.current_index, currentCycle.current_index,
getTriggerSize()); triggerShape->getSize());
} }
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
@ -641,8 +638,12 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
triggerStateListener->OnTriggerSyncronization(wasSynchronized); triggerStateListener->OnTriggerSyncronization(wasSynchronized);
} }
setShaftSynchronized(true);
// this call would update duty cycle values
nextTriggerEvent()
;
onShaftSynchronization(triggerCycleCallback, nowNt, triggerWheel PASS_ENGINE_PARAMETER_SUFFIX); onShaftSynchronization(triggerCycleCallback, nowNt, triggerWheel, triggerShape);
} else { /* if (!isSynchronizationPoint) */ } else { /* if (!isSynchronizationPoint) */
nextTriggerEvent() nextTriggerEvent()
@ -655,10 +656,10 @@ void TriggerState::decodeTriggerEvent(const TriggerStateCallback triggerCycleCal
toothed_previous_time = nowNt; toothed_previous_time = nowNt;
} }
if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && triggerStateListener) { if (!isValidIndex(triggerShape) && triggerStateListener) {
// let's not show a warning if we are just starting to spin // let's not show a warning if we are just starting to spin
if (GET_RPM_VALUE != 0) { if (GET_RPM_VALUE != 0) {
warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentCycle.current_index, getTriggerSize()); warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentCycle.current_index, triggerShape->getSize());
lastDecodingErrorTime = getTimeNowNt(); lastDecodingErrorTime = getTimeNowNt();
someSortOfTriggerError = true; someSortOfTriggerError = true;
} }

View File

@ -73,13 +73,13 @@ public:
bool validateEventCounters(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; bool validateEventCounters(DECLARE_ENGINE_PARAMETER_SIGNATURE) const;
void handleTriggerError(DECLARE_ENGINE_PARAMETER_SIGNATURE); void handleTriggerError(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void onShaftSynchronization(const TriggerStateCallback triggerCycleCallback, void onShaftSynchronization(const TriggerStateCallback triggerCycleCallback,
efitick_t nowNt, trigger_wheel_e triggerWheel DECLARE_ENGINE_PARAMETER_SUFFIX); efitick_t nowNt, trigger_wheel_e triggerWheel, TriggerWaveform *triggerShape);
/** /**
* Resets synchronization flag and alerts rpm_calculator to reset engine spinning flag. * Resets synchronization flag and alerts rpm_calculator to reset engine spinning flag.
*/ */
void onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE); void onSynchronizationLost(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isValidIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; bool isValidIndex(TriggerWaveform *triggerShape) const;
float getTriggerDutyCycle(int index); float getTriggerDutyCycle(int index);
/** /**

View File

@ -129,7 +129,7 @@ void startTriggerInputPins(void) {
// 20 rpm (60_2) = 1000*60/((2*60)*20) = 25 ms for 1 tooth event // 20 rpm (60_2) = 1000*60/((2*60)*20) = 25 ms for 1 tooth event
float satRpm = CONFIG(triggerCompSensorSatRpm) * RPM_1_BYTE_PACKING_MULT; float satRpm = CONFIG(triggerCompSensorSatRpm) * RPM_1_BYTE_PACKING_MULT;
hystUpdatePeriodNumEvents = getTriggerSize(); // = 116 for "60-2" trigger wheel hystUpdatePeriodNumEvents = ENGINE(triggerCentral.triggerShape).getSize(); // = 116 for "60-2" trigger wheel
float saturatedToothDurationUs = 60.0f * US_PER_SECOND_F / satRpm / hystUpdatePeriodNumEvents; float saturatedToothDurationUs = 60.0f * US_PER_SECOND_F / satRpm / hystUpdatePeriodNumEvents;
saturatedVrFreqNt = 1.0f / US2NT(saturatedToothDurationUs); saturatedVrFreqNt = 1.0f / US2NT(saturatedToothDurationUs);