From e8b31b0668b4e330cdf0ee52152a7399a28ab3bc Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 4 Mar 2017 09:07:10 -0500 Subject: [PATCH] better variable name & docs --- .../controllers/trigger/trigger_simulator.cpp | 21 ++++++++++++++++--- .../controllers/trigger/trigger_simulator.h | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index 5f5f084b73..9d63880ed7 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -24,6 +24,10 @@ bool isUsefulSignal(trigger_event_e signal, engine_configuration_s *engineConfig return !engineConfiguration->useOnlyRisingEdgeForTrigger || isRisingEdge[(int) signal]; } +#if EFI_UNIT_TEST || defined(__DOXYGEN__) +extern bool printTriggerDebug; +#endif /* ! EFI_UNIT_TEST */ + void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S) { int stateIndex = i % shape->getSize(); @@ -43,6 +47,14 @@ void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape bool thirdWheelState = shape->wave.getChannelState(2, prevIndex); bool new3rdWheelState = shape->wave.getChannelState(2, stateIndex); +#if EFI_UNIT_TEST || defined(__DOXYGEN__) + if (printTriggerDebug) { + printf("nextStep: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, + secondaryWheelState, newSecondaryWheelState ); + } +#endif /* EFI_UNIT_TEST */ + + // todo: code duplication with TriggerEmulatorHelper::handleEmulatorCallback? if (primaryWheelState != newPrimaryWheelState) { @@ -64,11 +76,11 @@ void TriggerStimulatorHelper::nextStep(TriggerState *state, TriggerShape * shape } } -void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(uint32_t index, TriggerState *state, TriggerShape * shape, +void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(const uint32_t syncIndex, TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S) { - int startIndex = engineConfiguration->useOnlyRisingEdgeForTrigger ? index + 2 : index + 1; + int startIndex = engineConfiguration->useOnlyRisingEdgeForTrigger ? syncIndex + 2 : syncIndex + 1; - for (uint32_t i = startIndex; i <= index + 2 * shape->getSize(); i++) { + for (uint32_t i = startIndex; i <= syncIndex + 2 * shape->getSize(); i++) { nextStep(state, shape, i, triggerConfig PASS_ENGINE_PARAMETER); } int revolutionCounter = state->getTotalRevolutionCounter(); @@ -84,6 +96,9 @@ void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(uint32_t index, } } +/** + * @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_S) { for (int i = 0; i < 4 * PWM_PHASE_MAX_COUNT; i++) { diff --git a/firmware/controllers/trigger/trigger_simulator.h b/firmware/controllers/trigger/trigger_simulator.h index 6883c7e91c..617e0b1007 100644 --- a/firmware/controllers/trigger/trigger_simulator.h +++ b/firmware/controllers/trigger/trigger_simulator.h @@ -20,7 +20,7 @@ public: void nextStep(TriggerState *state, TriggerShape * shape, int i, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S); - void assertSyncPositionAndSetDutyCycle(uint32_t index, TriggerState *state, TriggerShape * shape, + void assertSyncPositionAndSetDutyCycle(const uint32_t index, TriggerState *state, TriggerShape * shape, trigger_config_s const*triggerConfig DECLARE_ENGINE_PARAMETER_S); };