extracting class & codes clean-up
This commit is contained in:
parent
b637757e57
commit
d9b96fe509
|
@ -1898,15 +1898,15 @@ typedef enum {
|
|||
CUSTOM_ERR_6549 = 6549,
|
||||
|
||||
CUSTOM_ERR_6550 = 6550,
|
||||
CUSTOM_ERR_6551 = 6551,
|
||||
CUSTOM_ERR_6552 = 6552,
|
||||
CUSTOM_TRIGGER_SYNC_ANGLE = 6551,
|
||||
CUSTOM_TRIGGER_SYNC_ANGLE2 = 6552,
|
||||
CUSTOM_ERR_6553 = 6553,
|
||||
CUSTOM_ERR_6554 = 6554,
|
||||
CUSTOM_ERR_6555 = 6555,
|
||||
CUSTOM_ERR_6556 = 6556,
|
||||
CUSTOM_ERR_6557 = 6557,
|
||||
CUSTOM_ERR_6558 = 6558,
|
||||
CUSTOM_ERR_6559 = 6559,
|
||||
CUSTOM_TRIGGER_SYNC_ANGLE_RANGE = 6559,
|
||||
|
||||
CUSTOM_ERR_TRIGGER_ANGLE_RANGE = 6560,
|
||||
CUSTOM_ERR_6561 = 6561,
|
||||
|
@ -1946,8 +1946,8 @@ typedef enum {
|
|||
CUSTOM_ERR_6592 = 6592,
|
||||
CUSTOM_ERR_6593 = 6593,
|
||||
CUSTOM_SHAPE_LEN_ZERO = 6594,
|
||||
CUSTOM_ERR_6595 = 6595,
|
||||
CUSTOM_ERR_6596 = 6596,
|
||||
CUSTOM_TRIGGER_CYCLE = 6595,
|
||||
CUSTOM_TRIGGER_CYCLE_NAN = 6596,
|
||||
CUSTOM_OMODE_UNDEF = 6597,
|
||||
CUSTOM_ERR_6598 = 6598,
|
||||
CUSTOM_ERR_6599 = 6599,
|
||||
|
@ -1993,12 +1993,12 @@ typedef enum {
|
|||
CUSTOM_ERR_6635 = 6635,
|
||||
CUSTOM_ERR_6636 = 6636,
|
||||
CUSTOM_CONF_NULL = 6637,
|
||||
CUSTOM_ERR_6638 = 6638,
|
||||
CUSTOM_TRIGGER_EVENT_TYPE = 6638,
|
||||
CUSTOM_ERR_6639 = 6639,
|
||||
|
||||
CUSTOM_ERR_6640 = 6640,
|
||||
CUSTOM_TRIGGER_UNEXPECTED = 6640,
|
||||
CUSTOM_ERR_6641 = 6641,
|
||||
CUSTOM_ERR_6642 = 6642,
|
||||
CUSTOM_TRIGGER_STACK = 6642,
|
||||
CUSTOM_ERR_6643 = 6643,
|
||||
CUSTOM_IDLE_WAVE_CNT = 6644,
|
||||
CUSTOM_ERR_6645 = 6645,
|
||||
|
|
|
@ -48,10 +48,10 @@ TriggerCentral::TriggerCentral() : trigger_central_s() {
|
|||
|
||||
clearCallbacks(&triggerListeneres);
|
||||
triggerState.resetTriggerState();
|
||||
resetAccumSignalData();
|
||||
noiseFilter.resetAccumSignalData();
|
||||
}
|
||||
|
||||
void TriggerCentral::resetAccumSignalData() {
|
||||
void TriggerNoiseFilter::resetAccumSignalData() {
|
||||
memset(lastSignalTimes, 0xff, sizeof(lastSignalTimes)); // = -1
|
||||
memset(accumSignalPeriods, 0, sizeof(accumSignalPeriods));
|
||||
memset(accumSignalPrevPeriods, 0, sizeof(accumSignalPrevPeriods));
|
||||
|
@ -255,7 +255,9 @@ static ALWAYS_INLINE void reportEventToWaveChart(trigger_event_e ckpSignalType,
|
|||
* And then compare between the current period and previous, with some tolerance (allowing for the wheel speed change).
|
||||
* @return true if the signal is passed through.
|
||||
*/
|
||||
bool TriggerCentral::noiseFilter(efitick_t nowNt, trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
bool TriggerNoiseFilter::noiseFilter(efitick_t nowNt,
|
||||
TriggerState * triggerState,
|
||||
trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
// todo: find a better place for these defs
|
||||
static const trigger_event_e opposite[6] = { SHAFT_PRIMARY_RISING, SHAFT_PRIMARY_FALLING, SHAFT_SECONDARY_RISING, SHAFT_SECONDARY_FALLING,
|
||||
SHAFT_3RD_RISING, SHAFT_3RD_FALLING };
|
||||
|
@ -281,8 +283,8 @@ bool TriggerCentral::noiseFilter(efitick_t nowNt, trigger_event_e signal DECLARE
|
|||
efitick_t allowedPeriod = accumSignalPrevPeriods[os];
|
||||
|
||||
// but first check if we're expecting a gap
|
||||
bool isGapExpected = TRIGGER_WAVEFORM(isSynchronizationNeeded) && triggerState.shaft_is_synchronized &&
|
||||
(triggerState.currentCycle.eventCount[ti] + 1) == TRIGGER_WAVEFORM(expectedEventCount[ti]);
|
||||
bool isGapExpected = TRIGGER_WAVEFORM(isSynchronizationNeeded) && triggerState->shaft_is_synchronized &&
|
||||
(triggerState->currentCycle.eventCount[ti] + 1) == TRIGGER_WAVEFORM(expectedEventCount[ti]);
|
||||
|
||||
if (isGapExpected) {
|
||||
// usually we need to extend the period for gaps, based on the trigger info
|
||||
|
@ -323,7 +325,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
|||
|
||||
// This code gathers some statistics on signals and compares accumulated periods to filter interference
|
||||
if (CONFIG(useNoiselessTriggerDecoder)) {
|
||||
if (!noiseFilter(timestamp, signal PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
if (!noiseFilter.noiseFilter(timestamp, &triggerState, signal PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
return;
|
||||
}
|
||||
// moved here from hwHandleShaftSignal()
|
||||
|
@ -335,7 +337,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
|
|||
engine->onTriggerSignalEvent(timestamp);
|
||||
|
||||
int eventIndex = (int) signal;
|
||||
efiAssertVoid(CUSTOM_ERR_6638, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
||||
efiAssertVoid(CUSTOM_TRIGGER_EVENT_TYPE, eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
|
||||
hwEventCounters[eventIndex]++;
|
||||
|
||||
|
||||
|
@ -665,7 +667,7 @@ void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
#if EFI_ENGINE_CONTROL
|
||||
ENGINE(initializeTriggerWaveform(logger PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
engine->triggerCentral.resetAccumSignalData();
|
||||
engine->triggerCentral.noiseFilter.resetAccumSignalData();
|
||||
#endif
|
||||
}
|
||||
#if EFI_DEFAILED_LOGGING
|
||||
|
|
|
@ -17,6 +17,18 @@ typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, ef
|
|||
|
||||
#define HAVE_CAM_INPUT() engineConfiguration->camInputs[0] != GPIO_UNASSIGNED
|
||||
|
||||
class TriggerNoiseFilter {
|
||||
public:
|
||||
void resetAccumSignalData();
|
||||
bool noiseFilter(efitick_t nowNt,
|
||||
TriggerState * triggerState,
|
||||
trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
efitick_t lastSignalTimes[HW_EVENT_TYPES];
|
||||
efitick_t accumSignalPeriods[HW_EVENT_TYPES];
|
||||
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
||||
};
|
||||
|
||||
/**
|
||||
* Maybe merge TriggerCentral and TriggerState classes into one class?
|
||||
* Probably not: we have an instance of TriggerState which is used for trigger initialization,
|
||||
|
@ -29,11 +41,11 @@ public:
|
|||
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
int getHwEventCounter(int index) const;
|
||||
void resetCounters();
|
||||
void resetAccumSignalData();
|
||||
bool noiseFilter(efitick_t nowNt, trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void validateCamVvtCounters();
|
||||
TriggerStateWithRunningStatistics triggerState;
|
||||
|
||||
TriggerNoiseFilter noiseFilter;
|
||||
|
||||
angle_t vvtPosition = 0;
|
||||
/**
|
||||
* this is similar to TriggerState#startOfCycleNt but with the crank-only sensor magic
|
||||
|
@ -47,11 +59,7 @@ public:
|
|||
|
||||
private:
|
||||
IntListenerArray<15> triggerListeneres;
|
||||
|
||||
// Used by 'useNoiselessTriggerDecoder', see handleShaftSignal()
|
||||
efitick_t lastSignalTimes[HW_EVENT_TYPES];
|
||||
efitick_t accumSignalPeriods[HW_EVENT_TYPES];
|
||||
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
||||
|
||||
};
|
||||
|
||||
void triggerInfo(void);
|
||||
|
|
|
@ -123,7 +123,7 @@ bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
#if EFI_PROD_CODE
|
||||
efiAssertVoid(CUSTOM_ERR_6642, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s");
|
||||
efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s");
|
||||
#endif
|
||||
trigger_config_s const*triggerConfig = &engineConfiguration->trigger;
|
||||
|
||||
|
@ -140,7 +140,7 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECL
|
|||
}
|
||||
|
||||
float firstAngle = shape->getAngle(shape->triggerShapeSynchPointIndex);
|
||||
assertAngleRange(shape->triggerShapeSynchPointIndex, "firstAngle", CUSTOM_ERR_6551);
|
||||
assertAngleRange(shape->triggerShapeSynchPointIndex, "firstAngle", CUSTOM_TRIGGER_SYNC_ANGLE);
|
||||
|
||||
int riseOnlyIndex = 0;
|
||||
|
||||
|
@ -152,13 +152,13 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECL
|
|||
shape->eventAngles[1] = 0;
|
||||
shape->riseOnlyIndexes[0] = 0;
|
||||
} else {
|
||||
assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_ERR_6552);
|
||||
assertAngleRange(shape->triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_TRIGGER_SYNC_ANGLE2);
|
||||
unsigned int triggerDefinitionCoordinate = (shape->triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount;
|
||||
efiAssertVoid(CUSTOM_ERR_6595, engine->engineCycleEventCount != 0, "zero engineCycleEventCount");
|
||||
efiAssertVoid(CUSTOM_TRIGGER_CYCLE, engine->engineCycleEventCount != 0, "zero engineCycleEventCount");
|
||||
int triggerDefinitionIndex = triggerDefinitionCoordinate >= shape->privateTriggerDefinitionSize ? triggerDefinitionCoordinate - shape->privateTriggerDefinitionSize : triggerDefinitionCoordinate;
|
||||
float angle = shape->getAngle(triggerDefinitionCoordinate) - firstAngle;
|
||||
efiAssertVoid(CUSTOM_ERR_6596, !cisnan(angle), "trgSyncNaN");
|
||||
fixAngle(angle, "trgSync", CUSTOM_ERR_6559);
|
||||
efiAssertVoid(CUSTOM_TRIGGER_CYCLE, !cisnan(angle), "trgSyncNaN");
|
||||
fixAngle(angle, "trgSync", CUSTOM_TRIGGER_SYNC_ANGLE_RANGE);
|
||||
if (engineConfiguration->useOnlyRisingEdgeForTrigger) {
|
||||
if (shape->isRiseEvent[triggerDefinitionIndex]) {
|
||||
riseOnlyIndex += 2;
|
||||
|
@ -402,7 +402,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape, const Trigg
|
|||
bool useOnlyRisingEdgeForTrigger = CONFIG(useOnlyRisingEdgeForTrigger);
|
||||
|
||||
|
||||
efiAssertVoid(CUSTOM_ERR_6640, signal <= SHAFT_3RD_RISING, "unexpected signal");
|
||||
efiAssertVoid(CUSTOM_TRIGGER_UNEXPECTED, signal <= SHAFT_3RD_RISING, "unexpected signal");
|
||||
|
||||
trigger_wheel_e triggerWheel = eventIndex[signal];
|
||||
trigger_value_e type = eventType[signal];
|
||||
|
|
|
@ -83,7 +83,7 @@ static void fireNoisyCycle60_2(EngineTestHelper *eth, int numCycles, int duratio
|
|||
|
||||
static void resetTrigger(EngineTestHelper ð) {
|
||||
eth.applyTriggerWaveform();
|
||||
eth.engine.triggerCentral.resetAccumSignalData();
|
||||
eth.engine.triggerCentral.noiseFilter.resetAccumSignalData();
|
||||
// reset error counter
|
||||
eth.engine.triggerCentral.triggerState.totalTriggerErrorCounter = 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue