minor trigger refactoring

This commit is contained in:
Andrey 2022-11-05 21:43:12 -04:00
parent f5f1fbfe2f
commit b57bf2903a
4 changed files with 51 additions and 48 deletions

View File

@ -7,7 +7,7 @@
#pragma once
#include "trigger_structure.h"
#include "rusefi_enums.h"
void setAlgorithm(engine_load_mode_e algo);

View File

@ -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");

View File

@ -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();

View File

@ -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;