35 #ifndef NOISE_RATIO_THRESHOLD
36 #define NOISE_RATIO_THRESHOLD 3000
92 #if EFI_SHAFT_POSITION_INPUT
111 if (triggerShapeSynchPointIndex == EFI_ERROR_CODE) {
117 int riseOnlyIndex = 0;
124 size_t triggerShapeLength = shape->
getSize();
141 auto triggerDefinitionIndex = wrappedIndex % triggerShapeLength;
144 float angle = shape->
getAngle(wrappedIndex) - firstAngle;
151 criticalAssertVoid(triggerDefinitionIndex < triggerShapeLength,
"trigger shape fail");
152 assertIsInBounds(triggerDefinitionIndex, shape->
isRiseEvent,
"isRise");
190 #define PRINT_INC_INDEX if (printTriggerTrace) {\
191 printf("nextTriggerEvent index=%d\r\n", currentCycle.current_index); \
194 #define PRINT_INC_INDEX {}
197 #define nextTriggerEvent() \
199 if (useOnlyRisingEdgeForTrigger) {currentCycle.current_index++;} \
200 currentCycle.current_index++; \
219 totalShift += engineCycle / divider;
225 if (totalShift > 0) {
241 #pragma GCC diagnostic push
242 #pragma GCC diagnostic ignored "-Waddress"
248 #pragma GCC diagnostic pop
270 return "SHAFT_PRIMARY_FALLING";
272 return "SHAFT_PRIMARY_RISING";
274 return "SHAFT_SECONDARY_FALLING";
276 return "SHAFT_SECONDARY_RISING";
283 return "TriggerValue::FALL";
285 return "TriggerValue::RISE";
300 bool isDecodingError =
false;
301 for (
int i = 0;i < PWM_PHASE_MAX_WAVE_PER_PWM;i++) {
305 #if EFI_DEFAILED_LOGGING
306 printf(
"validateEventCounters: isDecodingError=%d\n", isDecodingError);
307 if (isDecodingError) {
308 for (
int i = 0;i < PWM_PHASE_MAX_WAVE_PER_PWM;i++) {
314 return isDecodingError;
318 bool wasSynchronized,
319 const efitick_t nowNt,
324 if (wasSynchronized) {
335 printf(
"onShaftSynchronization index=%d %d\r\n",
375 const efitick_t nowNt) {
384 if (triggerStateListener) {
397 if (!useOnlyRisingEdgeForTrigger &&
prevSignal == signal) {
416 currentDurationLong > 10 * NT_PER_SECOND ? 10 * NT_PER_SECOND : currentDurationLong;
421 printf(
"%s isLessImportant %s now=%d index=%d\r\n",
434 printf(
"%s event %s %lld\r\n",
444 bool isSynchronizationPoint;
455 if (isSynchronizationPoint) {
466 #if EFI_PROD_CODE || EFI_SIMULATOR
470 const char * prefix = verbose ?
"[vrb]" :
"[err]";
474 if (cisnan(ratioFrom)) {
481 efiPrintf(
"%s index=%d NaN gap, you have noise issues?",
488 bool gapOk =
isInRange(ratioFrom, gap, ratioTo);
490 efiPrintf(
"%s %srpm=%d time=%d eventIndex=%d gapIndex=%d: %s gap=%.3f expected from %.3f to %.3f error=%s",
509 printf(
"%sindex=%d: gap=%.2f expected from %.2f to %.2f error=%s\r\n",
527 unsigned int endOfCycleIndex = triggerShape.
getSize() - (useOnlyRisingEdgeForTrigger ? 2 : 1);
533 printf(
"decodeTriggerEvent sync=%d isSynchronizationPoint=%d index=%d size=%d\r\n",
535 isSynchronizationPoint,
543 printf(
"decodeTriggerEvent %s isSynchronizationPoint=%d index=%d %s\r\n",
550 if (isSynchronizationPoint) {
553 if (triggerStateListener) {
563 if (wasSynchronized && isDecodingError) {
592 if (wasSynchronized) {
617 if (triggerStateListener) {
648 if (!currentGapOk || !secondGapOk) {
670 bool isGapCondition =
674 if (!isGapCondition) {
703 triggerConfiguration,
706 return EFI_ERROR_CODE;
714 printf(
"findTriggerZeroEventIndex: syncIndex located %d!\r\n", syncIndex);
719 syncIndex.Value, *
this, shape);
721 return syncIndex.Value % shape.
getSize();
const char * getTrigger_type_e(trigger_type_e value)
TriggerCentral triggerCentral
RpmCalculator rpmCalculator
OutputPin debugTriggerSync
PrimaryTriggerDecoder(const char *name)
void onTooManyTeeth(int actual, int expected) override
void resetState() override
void onTriggerError() override
void onNotEnoughTeeth(int actual, int expected) override
angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle)
static float getOrZero(SensorType type)
InstantRpmCalculator instantRpm
bool isEngineSnifferEnabled
const char *const PrintPrefix
trigger_config_s TriggerType
bool VerboseTriggerSynchDetails
virtual void resetState()
efitick_t mostRecentSyncTime
void resetCurrentCycleState()
void incrementShaftSynchronizationCounter()
TriggerDecoderBase(const char *name)
int getCrankSynchronizationCounter() const
virtual void onTriggerError()
float gapRatio[PWM_PHASE_MAX_COUNT *6]
void onShaftSynchronization(bool wasSynchronized, const efitick_t nowNt, const TriggerWaveform &triggerShape)
int getCurrentIndex() const
uint32_t findTriggerZeroEventIndex(TriggerWaveform &shape, const TriggerConfiguration &triggerConfiguration)
virtual void onNotEnoughTeeth(int, int)
virtual void onTooManyTeeth(int, int)
Timer m_timeSinceDecodeError
uint32_t orderingErrorCounter
bool validateEventCounters(const TriggerWaveform &triggerShape) const
efitick_t toothed_previous_time
bool shaft_is_synchronized
void setShaftSynchronized(bool value)
int64_t totalEventCountBase
int64_t getTotalEventCounter() const
trigger_event_e prevSignal
expected< TriggerDecodeResult > decodeTriggerEvent(const char *msg, const TriggerWaveform &triggerShape, TriggerStateListener *triggerStateListener, const TriggerConfiguration &triggerConfiguration, const trigger_event_e signal, const efitick_t nowNt)
Trigger decoding happens here VR falls are filtered out and some VR noise detection happens prior to ...
bool isValidIndex(const TriggerWaveform &triggerShape) const
bool getShaftSynchronized()
current_cycle_state_s currentCycle
bool someSortOfTriggerError() const
void setTriggerErrorState(int errorIncrement=1)
uint32_t toothDurations[GAP_TRACKING_LENGTH+1]
uint32_t totalTriggerErrorCounter
bool isSyncPoint(const TriggerWaveform &triggerShape, trigger_type_e triggerType) const
static expected< uint32_t > findTriggerSyncPoint(TriggerWaveform &shape, const TriggerConfiguration &triggerConfiguration, TriggerDecoderBase &state)
static void assertSyncPosition(const TriggerConfiguration &triggerConfiguration, const uint32_t index, TriggerDecoderBase &state, TriggerWaveform &shape)
void onTooManyTeeth(int actual, int expected) override
void onNotEnoughTeeth(int actual, int expected) override
const char * boolToString(bool value)
bool isInRange(T min, T val, T max)
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
TriggerCentral * getTriggerCentral()
Main engine configuration data structure.
bool warning(ObdCode code, const char *fmt,...)
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_TRIGGER_SYNC_ANGLE_RANGE
@ CUSTOM_TRIGGER_SYNC_ANGLE2
@ CUSTOM_CAM_TOO_MANY_TEETH
@ OBD_PCM_Processor_Fault
@ CUSTOM_TRIGGER_SYNC_ANGLE
@ CUSTOM_PRIMARY_TOO_MANY_TEETH
@ CUSTOM_CAM_NOT_ENOUGH_TEETH
@ CUSTOM_PRIMARY_NOT_ENOUGH_TEETH
@ CUSTOM_TRIGGER_UNEXPECTED
engine_configuration_s * engineConfiguration
@ SHAFT_SECONDARY_FALLING
virtual void OnTriggerStateProperState(efitick_t nowNt)=0
virtual void OnTriggerSynchronization(bool wasSynchronized, bool isDecodingError)=0
virtual void OnTriggerSynchronizationLost()=0
size_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]
bool m_hasSynchronizedPhase
uint8_t triggerStateIndex
float triggerSyncGapRatio
uint32_t crankSynchronizationCounter
const char * getTrigger_event_e(trigger_event_e value)
static bool shouldConsiderEdge(const TriggerWaveform &triggerShape, TriggerWheel triggerWheel, TriggerValue edge)
static TriggerValue eventType[4]
const char * getTrigger_value_e(TriggerValue value)
static TriggerWheel eventIndex[4]
void wrapAngle(angle_t &angle, const char *msg, ObdCode code)