diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 3fb9aa0384..b779281791 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -7,7 +7,7 @@ #pragma once -#include "trigger_structure.h" +#include "rusefi_enums.h" void setAlgorithm(engine_load_mode_e algo); diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index ebd742d14d..d8fc0f72b0 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -952,6 +952,47 @@ static void initVvtShape(TriggerWaveform& shape, const TriggerConfiguration& con shape.initializeSyncPoint(initState, config); } +void TriggerCentral::validateCamVvtCounters() { + // micro-optimized 'crankSynchronizationCounter % 256' + int camVvtValidationIndex = triggerState.getCrankSynchronizationCounter() & 0xFF; + if (camVvtValidationIndex == 0) { + vvtCamCounter = 0; + } else if (camVvtValidationIndex == 0xFE && vvtCamCounter < 60) { + // magic logic: we expect at least 60 CAM/VVT events for each 256 trigger cycles, otherwise throw a code + warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "No Camshaft Position Sensor signals"); + } +} +/** + * Calculate 'shape.triggerShapeSynchPointIndex' value using 'TriggerDecoderBase *state' + */ +static void calculateTriggerSynchPoint( + TriggerCentral *triggerCentral, + TriggerWaveform& shape, + TriggerDecoderBase& state) { + state.resetTriggerState(); + +#if EFI_PROD_CODE + efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s"); +#endif + triggerCentral->triggerErrorDetection.clear(); + shape.initializeSyncPoint(state, triggerCentral->primaryTriggerConfiguration); + + int length = shape.getLength(); + triggerCentral->engineCycleEventCount = length; + + efiAssertVoid(CUSTOM_SHAPE_LEN_ZERO, length > 0, "shapeLength=0"); + if (shape.getSize() >= PWM_PHASE_MAX_COUNT) { + // todo: by the time we are here we had already modified a lot of RAM out of bounds! + firmwareError(CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG, "Trigger length above maximum: %d", length); + shape.setShapeDefinitionError(true); + return; + } + + if (shape.getSize() == 0) { + firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); + } +} + void TriggerCentral::updateWaveform() { static TriggerDecoderBase initState("init"); diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index e8dc432137..954eb3ebd7 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -211,9 +211,4 @@ void onConfigurationChangeTriggerCallback(); #define SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER 6 #define SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER 24 -void calculateTriggerSynchPoint( - TriggerCentral *triggerCentral, - TriggerWaveform& shape, - TriggerDecoderBase& state); - TriggerCentral * getTriggerCentral(); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 7bb5cf4c2d..229bdf2caf 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -36,9 +36,18 @@ #include "trigger_central.h" #include "trigger_decoder.h" +/** + * decoder depends on current RPM for error condition logic + */ #include "sensor.h" +/** + * sensorChartMode + */ #include "engine_state.h" #include "engine_math.h" +/** + * decoder uses TriggerStimulatorHelper in findTriggerZeroEventIndex + */ #include "trigger_simulator.h" #if EFI_SENSOR_CHART @@ -120,37 +129,6 @@ void TriggerWaveform::initializeSyncPoint(TriggerDecoderBase& state, triggerShapeSynchPointIndex = state.findTriggerZeroEventIndex(*this, triggerConfiguration); } -/** - * Calculate 'shape.triggerShapeSynchPointIndex' value using 'TriggerDecoderBase *state' - */ -void calculateTriggerSynchPoint( - TriggerCentral *triggerCentral, - TriggerWaveform& shape, - TriggerDecoderBase& state) { - state.resetTriggerState(); - -#if EFI_PROD_CODE - efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s"); -#endif - triggerCentral->triggerErrorDetection.clear(); - shape.initializeSyncPoint(state, triggerCentral->primaryTriggerConfiguration); - - int length = shape.getLength(); - triggerCentral->engineCycleEventCount = length; - - efiAssertVoid(CUSTOM_SHAPE_LEN_ZERO, length > 0, "shapeLength=0"); - if (shape.getSize() >= PWM_PHASE_MAX_COUNT) { - // todo: by the time we are here we had already modified a lot of RAM out of bounds! - firmwareError(CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG, "Trigger length above maximum: %d", length); - shape.setShapeDefinitionError(true); - return; - } - - if (shape.getSize() == 0) { - firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); - } -} - void TriggerFormDetails::prepareEventAngles(TriggerWaveform *shape) { int triggerShapeSynchPointIndex = shape->triggerShapeSynchPointIndex; if (triggerShapeSynchPointIndex == EFI_ERROR_CODE) { @@ -378,17 +356,6 @@ int TriggerDecoderBase::getCurrentIndex() const { return currentCycle.current_index; } -void TriggerCentral::validateCamVvtCounters() { - // micro-optimized 'crankSynchronizationCounter % 256' - int camVvtValidationIndex = triggerState.getCrankSynchronizationCounter() & 0xFF; - if (camVvtValidationIndex == 0) { - vvtCamCounter = 0; - } else if (camVvtValidationIndex == 0xFE && vvtCamCounter < 60) { - // magic logic: we expect at least 60 CAM/VVT events for each 256 trigger cycles, otherwise throw a code - warning(OBD_Camshaft_Position_Sensor_Circuit_Range_Performance, "No Camshaft Position Sensor signals"); - } -} - angle_t PrimaryTriggerDecoder::syncEnginePhase(int divider, int remainder, angle_t engineCycle) { efiAssert(OBD_PCM_Processor_Fault, remainder < divider, "syncEnginePhase", false); angle_t totalShift = 0;