diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index dfe93ce10b..df3e23539f 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -669,7 +669,7 @@ uint32_t findTriggerZeroEventIndex(TriggerState *state, TriggerShape * shape, // todo: should this variable be declared 'static' to reduce stack usage? TriggerStimulatorHelper helper; - uint32_t syncIndex = helper.doFindTrigger(shape, triggerConfig, state PASS_ENGINE_PARAMETER_SUFFIX); + uint32_t syncIndex = helper.findTriggerSyncPoint(shape, state PASS_ENGINE_PARAMETER_SUFFIX); if (syncIndex == EFI_ERROR_CODE) { isInitializingTrigger = false; return syncIndex; diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index 11f9c61065..ff01b99b21 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -45,7 +45,7 @@ void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIn bool thirdWheelState = state->multiWave.waves[2].pinStates[prevIndex]; int new3rdWheelState = state->multiWave.waves[2].pinStates[stateIndex]; - // todo: code duplication with TriggerStimulatorHelper::nextStep? + // todo: code duplication with TriggerStimulatorHelper::feedSimulatedEvent? if (primaryWheelState != newPrimaryWheelState) { primaryWheelState = newPrimaryWheelState; diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index 5ae8d12e59..afa886654c 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -29,8 +29,8 @@ bool isUsefulSignal(trigger_event_e signal, engine_configuration_s *engineConfig extern bool printTriggerDebug; #endif /* ! EFI_UNIT_TEST */ -void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape, int i, - trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX) { +void TriggerStimulatorHelper::feedSimulatedEvent(TriggerState *state, TriggerShape * shape, int i + DECLARE_ENGINE_PARAMETER_SUFFIX) { int stateIndex = i % shape->getSize(); int prevIndex = (stateIndex + shape->getSize() - 1 ) % shape->getSize(); @@ -50,7 +50,7 @@ void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape #if EFI_UNIT_TEST || defined(__DOXYGEN__) if (printTriggerDebug) { - printf("nextStep: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, + printf("feedSimulatedEvent: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, secondaryWheelState, newSecondaryWheelState ); } #endif /* EFI_UNIT_TEST */ @@ -82,10 +82,12 @@ void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(const uint32_t syncIndex, TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX) { - int startIndex = syncIndex + 1; - for (uint32_t i = startIndex; i <= syncIndex + 2 * shape->getSize(); i++) { - nextStep(state, shape, i, triggerConfig PASS_ENGINE_PARAMETER_SUFFIX); + /** + * let's feed two more cycles to validate shape definition + */ + for (uint32_t i = syncIndex + 1; i <= syncIndex + 2 * shape->getSize(); i++) { + feedSimulatedEvent(state, shape, i PASS_ENGINE_PARAMETER_SUFFIX); } int revolutionCounter = state->getTotalRevolutionCounter(); if (revolutionCounter != 3) { @@ -103,10 +105,10 @@ void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(const uint32_t s /** * @return trigger synchronization point index, or error code if not found */ -uint32_t TriggerStimulatorHelper::doFindTrigger(TriggerShape * shape, - trigger_config_s const*triggerConfig, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) { +uint32_t TriggerStimulatorHelper::findTriggerSyncPoint(TriggerShape * shape, + TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) { for (int i = 0; i < 4 * PWM_PHASE_MAX_COUNT; i++) { - nextStep(state, shape, i, triggerConfig PASS_ENGINE_PARAMETER_SUFFIX); + feedSimulatedEvent(state, shape, i PASS_ENGINE_PARAMETER_SUFFIX); if (state->shaft_is_synchronized) return i; diff --git a/firmware/controllers/trigger/trigger_simulator.h b/firmware/controllers/trigger/trigger_simulator.h index 64d4430e69..3515f213ed 100644 --- a/firmware/controllers/trigger/trigger_simulator.h +++ b/firmware/controllers/trigger/trigger_simulator.h @@ -15,13 +15,15 @@ class TriggerStimulatorHelper { public: TriggerStimulatorHelper(); - uint32_t doFindTrigger(TriggerShape * shape, - trigger_config_s const*triggerConfig, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX); - - void nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX); + uint32_t findTriggerSyncPoint(TriggerShape * shape, + TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX); void assertSyncPositionAndSetDutyCycle(const uint32_t index, TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_SUFFIX); + +private: + // send next event so that we can see how state reacts + void feedSimulatedEvent(TriggerState *state, TriggerShape * shape, int i DECLARE_ENGINE_PARAMETER_SUFFIX); }; bool isUsefulSignal(trigger_event_e signal, engine_configuration_s *engineConfiguration);