rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
trigger_central.cpp File Reference

Functions

int getCrankDivider (operation_mode_e operationMode)
 
PUBLIC_API_WEAK bool boardIsSpecialVvtDecoder (vvt_mode_e vvtMode)
 
PUBLIC_API_WEAK void boardTriggerCallback (efitick_t timestamp, float currentPhase)
 
static bool vvtWithRealDecoder (vvt_mode_e vvtMode)
 
PUBLIC_API_WEAK angle_t customAdjustCustom (TriggerCentral *tc, vvt_mode_e vvtMode)
 
static angle_t adjustCrankPhase (int camIndex)
 
static angle_t wrapVvt (angle_t vvtPosition, int period)
 
static void logVvtFront (bool useOnlyRise, bool isImportantFront, TriggerValue front, efitick_t nowNt, int index)
 
static bool tooSoonToHandleSignal ()
 
void hwHandleVvtCamSignal (bool isRising, efitick_t nowNt, int index)
 
void hwHandleVvtCamSignal (TriggerValue front, efitick_t nowNt, int index)
 
PUBLIC_API_WEAK bool skipToothSpecialShape (size_t index, vvt_mode_e vvtMode, angle_t currentPosition)
 
void handleVvtCamSignal (TriggerValue front, efitick_t nowNt, int index)
 
void hwHandleShaftSignal (int signalIndex, bool isRising, efitick_t timestamp)
 
void handleShaftSignal (int signalIndex, bool isRising, efitick_t timestamp)
 
static void reportEventToWaveChart (trigger_event_e ckpSignalType, int triggerEventIndex, bool addOppositeEvent)
 
PUBLIC_API_WEAK bool boardAllowTriggerActions ()
 
static void triggerShapeInfo ()
 
void triggerInfo (void)
 
static void resetRunningTriggerCounters ()
 
void onConfigurationChangeTriggerCallback ()
 
static void initVvtShape (int camIndex, TriggerWaveform &shape, const TriggerConfiguration &p_config, TriggerDecoderBase &initState)
 
static void calculateTriggerSynchPoint (const PrimaryTriggerConfiguration &primaryTriggerConfiguration, TriggerWaveform &shape, TriggerDecoderBase &initState)
 
void validateTriggerInputs ()
 
void initTriggerCentral ()
 

Variables

WaveChart waveChart
 
int triggerReentrant = 0
 
int maxTriggerReentrant = 0
 
uint32_t triggerDuration
 
uint32_t triggerMaxDuration = 0
 
static const int wheelIndeces [4] = { 0, 0, 1, 1}
 
float mapAtAngle [200]
 
PwmConfig triggerEmulatorSignals [NUM_EMULATOR_CHANNELS]
 
TriggerDecoderBase initState ("init")
 

Function Documentation

◆ adjustCrankPhase()

static angle_t adjustCrankPhase ( int  camIndex)
static

Definition at line 155 of file trigger_central.cpp.

155 {
156 float maxSyncThreshold = engineConfiguration->maxCamPhaseResolveRpm;
157 if (maxSyncThreshold != 0 && Sensor::getOrZero(SensorType::Rpm) > maxSyncThreshold) {
158 // The user has elected to stop trying to resolve crank phase after some RPM.
159 // Maybe their cam sensor only works at low RPM or something.
160 // Anyway, don't try to change crank phase at all, and return that we made no change.
161 return 0;
162 }
163
165
166 auto crankDivider = getCrankDivider(operationMode);
167 if (crankDivider == 1) {
168 // Crank divider of 1 means there's no ambiguity, so don't try to resolve it
169 return 0;
170 }
171
173
174 vvt_mode_e vvtMode = engineConfiguration->vvtMode[camIndex];
175 switch (vvtMode) {
176 case VVT_MAP_V_TWIN:
177 case VVT_MITSUBISHI_4G63:
178 case VVT_UNUSED_17:
179 return tc->syncEnginePhaseAndReport(crankDivider, 1);
180 case VVT_SINGLE_TOOTH:
181 case VVT_NISSAN_VQ:
182 case VVT_BOSCH_QUICK_START:
183 case VVT_MIATA_NB:
184 case VVT_TOYOTA_3TOOTH_UZ:
185 case VVT_TOYOTA_3_TOOTH:
186 case VVT_TOYOTA_4_1:
187 case VVT_FORD_COYOTE:
188 case VVT_DEV:
189 case VVT_FORD_ST170:
190 case VVT_BARRA_3_PLUS_1:
191 case VVT_NISSAN_MR:
192 case VVT_HR12DDR_IN:
193 case VVT_MAZDA_SKYACTIV:
194 case VVT_MAZDA_L:
195 case VVT_MITSUBISHI_4G69:
196 case VVT_MITSUBISHI_3A92:
197 case VVT_MITSUBISHI_6G72:
198 case VVT_CHRYSLER_PHASER:
199 case VVT_HONDA_K_EXHAUST:
200 case VVT_HONDA_CBR_600:
201 case VVT_SUBARU_7TOOTH:
202 return tc->syncEnginePhaseAndReport(crankDivider, 0);
203 case VVT_CUSTOM_25:
204 case VVT_CUSTOM_26:
205 return customAdjustCustom(tc, vvtMode);
206
207 case VVT_HONDA_K_INTAKE:
208 // with 4 evenly spaced tooth we cannot use this wheel for engine sync
209 criticalError("Honda K Intake is not suitable for engine sync");
210 [[fallthrough]];
211 case VVT_CUSTOM_1:
212 case VVT_CUSTOM_2:
213 case VVT_INACTIVE:
214 // do nothing
215 return 0;
216 }
217 return 0;
218}
virtual operation_mode_e getOperationMode() const =0
static float getOrZero(SensorType type)
Definition sensor.h:83
angle_t syncEnginePhaseAndReport(int divider, int remainder)
TriggerCentral * getTriggerCentral()
Definition engine.cpp:590
EngineRotationState * getEngineRotationState()
Definition engine.cpp:573
static constexpr engine_configuration_s * engineConfiguration
vvt_mode_e
operation_mode_e
int getCrankDivider(operation_mode_e operationMode)
PUBLIC_API_WEAK angle_t customAdjustCustom(TriggerCentral *tc, vvt_mode_e vvtMode)

Referenced by handleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boardAllowTriggerActions()

PUBLIC_API_WEAK bool boardAllowTriggerActions ( )

Definition at line 785 of file trigger_central.cpp.

785{ return true; }

Referenced by TriggerCentral::handleShaftSignal().

Here is the caller graph for this function:

◆ boardIsSpecialVvtDecoder()

PUBLIC_API_WEAK bool boardIsSpecialVvtDecoder ( vvt_mode_e  vvtMode)

Definition at line 119 of file trigger_central.cpp.

119 {
120 UNUSED(vvtMode);
121
122 return false;
123}
UNUSED(samplingTimeSeconds)

Referenced by vvtWithRealDecoder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boardTriggerCallback()

PUBLIC_API_WEAK void boardTriggerCallback ( efitick_t  timestamp,
float  currentPhase 
)

Definition at line 125 of file trigger_central.cpp.

125{ UNUSED(timestamp); UNUSED(currentPhase); }

Referenced by TriggerCentral::handleShaftSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateTriggerSynchPoint()

static void calculateTriggerSynchPoint ( const PrimaryTriggerConfiguration primaryTriggerConfiguration,
TriggerWaveform shape,
TriggerDecoderBase initState 
)
static

Calculate 'shape.triggerShapeSynchPointIndex' value using 'TriggerDecoderBase *state'

Definition at line 1132 of file trigger_central.cpp.

1135 {
1136
1137#if EFI_PROD_CODE
1138 efiAssertVoid(ObdCode::CUSTOM_TRIGGER_STACK, hasLotsOfRemainingStack(), "calc s");
1139#endif
1140
1141 shape.initializeSyncPoint(initState, primaryTriggerConfiguration);
1142
1143 if (shape.getSize() >= PWM_PHASE_MAX_COUNT) {
1144 // todo: by the time we are here we had already modified a lot of RAM out of bounds!
1145 firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG, "Trigger length above maximum: %d", shape.getSize());
1146 shape.setShapeDefinitionError(true);
1147 return;
1148 }
1149
1150 if (shape.getSize() == 0) {
1151 firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero");
1152 }
1153}
void setShapeDefinitionError(bool value)
void initializeSyncPoint(TriggerDecoderBase &state, const TriggerConfiguration &triggerConfiguration)
size_t getSize() const
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_TRIGGER_ZERO
@ CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG
@ CUSTOM_TRIGGER_STACK
TriggerDecoderBase initState("init")

Referenced by TriggerCentral::applyShapesConfiguration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ customAdjustCustom()

PUBLIC_API_WEAK angle_t customAdjustCustom ( TriggerCentral tc,
vvt_mode_e  vvtMode 
)

Definition at line 148 of file trigger_central.cpp.

148 {
149 UNUSED(tc);
150 UNUSED(vvtMode);
151
152 return 0;
153}

Referenced by adjustCrankPhase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCrankDivider()

int getCrankDivider ( operation_mode_e  operationMode)

todo: why is this method NOT reciprocal to getRpmMultiplier?!

wow even while we explicitly handle all enumerations in the switch above we still need a return statement due to https://stackoverflow.com/questions/34112483/gcc-how-best-to-handle-warning-about-unreachable-end-of-function-after-switch

Definition at line 92 of file trigger_central.cpp.

92 {
93 switch (operationMode) {
95 return 2;
97 return SYMMETRICAL_CRANK_SENSOR_DIVIDER;
99 return SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER;
101 return SYMMETRICAL_SIX_TIMES_CRANK_SENSOR_DIVIDER;
103 return SYMMETRICAL_TWELVE_TIMES_CRANK_SENSOR_DIVIDER;
104 case OM_NONE:
106 case TWO_STROKE:
107 // That's easy - trigger cycle matches engine cycle
108 return 1;
109 /* let's NOT handle default in order to benefit from -Werror=switch */
110 }
111 /**
112 wow even while we explicitly handle all enumerations in the switch above we still need a return statement due to
113 https://stackoverflow.com/questions/34112483/gcc-how-best-to-handle-warning-about-unreachable-end-of-function-after-switch
114 */
115 criticalError("unreachable getCrankDivider");
116 return 1;
117}
@ FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR
@ FOUR_STROKE_TWELVE_TIMES_CRANK_SENSOR
@ FOUR_STROKE_THREE_TIMES_CRANK_SENSOR
@ FOUR_STROKE_CRANK_SENSOR
@ OM_NONE
@ FOUR_STROKE_CAM_SENSOR
@ TWO_STROKE
@ FOUR_STROKE_SIX_TIMES_CRANK_SENSOR

Referenced by adjustCrankPhase(), getRpmMultiplier(), and TriggerCentral::handleShaftSignal().

Here is the caller graph for this function:

◆ handleShaftSignal()

void handleShaftSignal ( int  signalIndex,
bool  isRising,
efitick_t  timestamp 
)

no need to process VR falls further

Definition at line 485 of file trigger_central.cpp.

485 {
486 bool isPrimary = signalIndex == 0;
487 if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) {
488 return;
489 }
490
491 trigger_event_e signal;
492 // todo: add support for 3rd channel
493 if (isRising) {
494 signal = isPrimary ?
496 (engineConfiguration->invertSecondaryTriggerSignal ? SHAFT_SECONDARY_FALLING : SHAFT_SECONDARY_RISING);
497 } else {
498 signal = isPrimary ?
500 (engineConfiguration->invertSecondaryTriggerSignal ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING);
501 }
502 if (isPrimary) {
504 } else {
506 }
507
508 // Don't accept trigger input in case of some problems
509 if (!getLimpManager()->allowTriggerInput()) {
510 return;
511 }
512
513#if EFI_TOOTH_LOGGER
514 // Log to the Tunerstudio tooth logger
515 // We want to do this before anything else as we
516 // actually want to capture any noise/jitter that may be occurring
517
519
520 if (!logLogicState) {
521 // we log physical state even if displayLogicLevelsInEngineSniffer if both fronts are used by decoder
522 LogTriggerTooth(signal, timestamp);
523 }
524
525#endif /* EFI_TOOTH_LOGGER */
526
527 // for effective noise filtering, we need both signal edges,
528 // so we pass them to handleShaftSignal() and defer this test
530 if (!isUsefulSignal(signal, getTriggerCentral()->triggerShape)) {
531 /**
532 * no need to process VR falls further
533 */
534 return;
535 }
536 }
537
538#if EFI_TOOTH_LOGGER
539 if (logLogicState) {
540 // first log rising normally
541 LogTriggerTooth(signal, timestamp);
542 // in 'logLogicState' mode we log opposite front right after logical rising away
543 if (signal == SHAFT_PRIMARY_RISING) {
545 } else {
547 }
548 }
549#endif /* EFI_TOOTH_LOGGER */
550
551 uint32_t triggerHandlerEntryTime = getTimeNowLowerNt();
555
556 getTriggerCentral()->handleShaftSignal(signal, timestamp);
557
559 triggerDuration = getTimeNowLowerNt() - triggerHandlerEntryTime;
561}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
TriggerWaveform triggerShape
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp)
LimpManager * getLimpManager()
Definition engine.cpp:596
static EngineAccessor engine
Definition engine.h:413
uint32_t getTimeNowLowerNt()
@ LogTriggerTooth
trigger_event_e
@ SHAFT_SECONDARY_RISING
@ SHAFT_SECONDARY_FALLING
@ SHAFT_PRIMARY_FALLING
@ SHAFT_PRIMARY_RISING
uint32_t triggerDuration
int maxTriggerReentrant
int triggerReentrant
uint32_t triggerMaxDuration
bool isUsefulSignal(trigger_event_e signal, const TriggerWaveform &shape)

Referenced by TriggerEmulatorHelper::handleEmulatorCallback(), and hwHandleShaftSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleVvtCamSignal()

void handleVvtCamSignal ( TriggerValue  front,
efitick_t  nowNt,
int  index 
)

we prefer not to have VVT sync right at trigger sync so that we do not have phase detection error if things happen a bit in wrong order due to belt flex or else https://github.com/rusefi/rusefi/issues/3269

Definition at line 323 of file trigger_central.cpp.

323 {
325 if (index == 0) {
327 } else if (index == 1) {
329 } else if (index == 2) {
331 } else if (index == 3) {
333 }
334
335 int bankIndex = BANK_BY_INDEX(index);
336 int camIndex = CAM_BY_INDEX(index);
337 if (front == TriggerValue::RISE) {
338 tc->vvtEventRiseCounter[index]++;
339 } else {
340 tc->vvtEventFallCounter[index]++;
341 }
342 if (engineConfiguration->vvtMode[camIndex] == VVT_INACTIVE) {
343 warning(ObdCode::CUSTOM_VVT_MODE_NOT_SELECTED, "VVT: event on %d but no mode", camIndex);
344 }
345
346 const auto& vvtShape = tc->vvtShape[camIndex];
347
348 bool isVvtWithRealDecoder = vvtWithRealDecoder(engineConfiguration->vvtMode[camIndex]);
349
350 // Non real decoders only use the rising edge
351 bool vvtUseOnlyRise = !isVvtWithRealDecoder || vvtShape.useOnlyRisingEdges;
352 bool isImportantFront = !vvtUseOnlyRise || (front == TriggerValue::RISE);
353
354 logVvtFront(vvtUseOnlyRise, isImportantFront, front, nowNt, index);
355
356 if (!isImportantFront) {
357 // This edge is unimportant, ignore it.
358 return;
359 }
360
361 // If the main trigger is not synchronized, don't decode VVT yet
363 return;
364 }
365
366 TriggerDecoderBase& vvtDecoder = tc->vvtState[bankIndex][camIndex];
367
368 if (isVvtWithRealDecoder) {
369 vvtDecoder.decodeTriggerEvent(
370 "vvt",
371 vvtShape,
372 nullptr,
373 tc->vvtTriggerConfiguration[camIndex],
375 vvtDecoder.vvtToothDurations0 = (uint32_t)NT2US(vvtDecoder.toothDurations[0]);
376 }
377
378 // here we count all cams together
379 tc->vvtCamCounter++;
380
381 auto currentPhase = tc->getCurrentEnginePhase(nowNt);
382 if (!currentPhase) {
383 // If we couldn't resolve engine speed (yet primary trigger is sync'd), this
384 // probably means that we have partial crank sync, but not RPM information yet
385 return;
386 }
387
388 angle_t angleFromPrimarySyncPoint = currentPhase.Value;
389 // convert trigger cycle angle into engine cycle angle
390 angle_t currentPosition = angleFromPrimarySyncPoint - tdcPosition();
391 // https://github.com/rusefi/rusefi/issues/1713 currentPosition could be negative that's expected
392
393#if EFI_UNIT_TEST
394 tc->currentVVTEventPosition[bankIndex][camIndex] = currentPosition;
395#endif // EFI_UNIT_TEST
396
397 tc->triggerState.vvtCurrentPosition = currentPosition;
398
399 if (isVvtWithRealDecoder && vvtDecoder.currentCycle.current_index != 0) {
400 // this is not sync tooth - exiting
401 return;
402 }
403
404 auto vvtPosition = engineConfiguration->vvtOffsets[bankIndex * CAMS_PER_BANK + camIndex] - currentPosition;
405 tc->triggerState.vvtToothPosition[index] = vvtPosition;
406
407 bool skipTooth = skipToothSpecialShape(index, engineConfiguration->vvtMode[camIndex], currentPosition);
408 if (skipTooth) {
409 return;
410 }
411
412 // this could be just an 'if' but let's have it expandable for future use :)
413 switch(engineConfiguration->vvtMode[camIndex]) {
414 case VVT_HONDA_K_INTAKE:
415 // honda K has four tooth in VVT intake trigger, so we just wrap each of those to 720 / 4
416 vvtPosition = wrapVvt(vvtPosition, 180);
417 break;
418 default:
419 // else, do nothing
420 break;
421 }
422
423#if EFI_PROD_CODE
426 criticalError("Selected engine sync input not configured: %d", engineConfiguration->engineSyncCam);
427 }
428#endif // EFI_PROD_CODE
429
430 // Only do engine sync using one cam, other cams just provide VVT position.
431 if (index == engineConfiguration->engineSyncCam) {
432 angle_t crankOffset = adjustCrankPhase(camIndex);
433 // vvtPosition was calculated against wrong crank zero position. Now that we have adjusted crank position we
434 // shall adjust vvt position as well
435 vvtPosition -= crankOffset;
436 vvtPosition = wrapVvt(vvtPosition, FOUR_STROKE_CYCLE_DURATION);
437
438 if (absF(angleFromPrimarySyncPoint) < 7) {
439 /**
440 * we prefer not to have VVT sync right at trigger sync so that we do not have phase detection error if things happen a bit in
441 * wrong order due to belt flex or else
442 * https://github.com/rusefi/rusefi/issues/3269
443 */
444 warning(ObdCode::CUSTOM_VVT_SYNC_POSITION, "VVT sync position too close to trigger sync");
445 }
446 } else {
447 // Not using this cam for engine sync, just wrap the value in to the reasonable range
448 vvtPosition = wrapVvt(vvtPosition, FOUR_STROKE_CYCLE_DURATION);
449 }
450
451 // Only record VVT position if we have full engine sync - may be bogus before that point
453 tc->vvtPosition[bankIndex][camIndex] = vvtPosition;
454 } else {
455 tc->vvtPosition[bankIndex][camIndex] = 0;
456 }
457}
bool hasSynchronizedPhase() const
VvtTriggerDecoder vvtState[BANKS_COUNT][CAMS_PER_BANK]
PrimaryTriggerDecoder triggerState
TriggerWaveform vvtShape[CAMS_PER_BANK]
angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK]
VvtTriggerConfiguration vvtTriggerConfiguration[CAMS_PER_BANK]
expected< float > getCurrentEnginePhase(efitick_t nowNt) const
angle_t currentVVTEventPosition[BANKS_COUNT][CAMS_PER_BANK]
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 ...
current_cycle_state_s currentCycle
uint32_t toothDurations[GAP_TRACKING_LENGTH+1]
bool getShaftSynchronized() const
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_VVT_SYNC_POSITION
@ CUSTOM_VVT_MODE_NOT_SELECTED
bool isBrainPinValid(brain_pin_e brainPin)
float angle_t
uint16_t vvtEventRiseCounter[CAM_INPUTS_COUNT]
uint16_t vvtEventFallCounter[CAM_INPUTS_COUNT]
static bool vvtWithRealDecoder(vvt_mode_e vvtMode)
static void logVvtFront(bool useOnlyRise, bool isImportantFront, TriggerValue front, efitick_t nowNt, int index)
static angle_t wrapVvt(angle_t vvtPosition, int period)
PUBLIC_API_WEAK bool skipToothSpecialShape(size_t index, vvt_mode_e vvtMode, angle_t currentPosition)
static angle_t adjustCrankPhase(int camIndex)

Referenced by TriggerEmulatorHelper::handleEmulatorCallback(), and hwHandleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwHandleShaftSignal()

void hwHandleShaftSignal ( int  signalIndex,
bool  isRising,
efitick_t  timestamp 
)

This function is called by all "hardware" trigger inputs:

  • Hardware triggers
  • Trigger replay from CSV (unit tests)

Definition at line 469 of file trigger_central.cpp.

469 {
470 if (tooSoonToHandleSignal()) {
471 return;
472 }
475
477 // sensor noise + self-stim = loss of trigger sync
478 return;
479 }
480
481 handleShaftSignal(signalIndex, isRising, timestamp);
482}
@ HandleShaftSignal
static bool tooSoonToHandleSignal()
void handleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp)

Referenced by comp_shaft_callback(), onTriggerChanged(), and shaft_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwHandleVvtCamSignal() [1/2]

void hwHandleVvtCamSignal ( bool  isRising,
efitick_t  nowNt,
int  index 
)

This function is called by all "hardware" trigger inputs:

  • Hardware triggers
  • Trigger replay from CSV (unit tests)

Definition at line 272 of file trigger_central.cpp.

272 {
273 int camIndex = CAM_BY_INDEX(index);
275
276 if (isRising ^ invertSetting) {
278 } else {
280 }
281}
void hwHandleVvtCamSignal(bool isRising, efitick_t nowNt, int index)

Referenced by cam_callback(), comp_cam_callback(), and hwHandleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hwHandleVvtCamSignal() [2/2]

void hwHandleVvtCamSignal ( TriggerValue  front,
efitick_t  nowNt,
int  index 
)

Definition at line 284 of file trigger_central.cpp.

284 {
285 if (tooSoonToHandleSignal()) {
286 return;
287 }
290 // sensor noise + self-stim = loss of trigger sync
291 return;
292 }
293 handleVvtCamSignal(front, nowNt, index);
294}
void handleVvtCamSignal(TriggerValue front, efitick_t nowNt, int index)

Referenced by TriggerCentral::decodeMapCam().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initTriggerCentral()

void initTriggerCentral ( )

Definition at line 1276 of file trigger_central.cpp.

1276 {
1277
1278#if EFI_ENGINE_SNIFFER
1280#endif /* EFI_ENGINE_SNIFFER */
1281
1282#if EFI_PROD_CODE || EFI_SIMULATOR
1283 addConsoleAction(CMD_TRIGGERINFO, triggerInfo);
1284 addConsoleAction("trigger_shape_info", triggerShapeInfo);
1286#endif // EFI_PROD_CODE || EFI_SIMULATOR
1287
1288}
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void initWaveChart(WaveChart *chart)
static void triggerShapeInfo()
void triggerInfo(void)
static void resetRunningTriggerCounters()
WaveChart waveChart

Referenced by commonEarlyInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initVvtShape()

static void initVvtShape ( int  camIndex,
TriggerWaveform shape,
const TriggerConfiguration p_config,
TriggerDecoderBase initState 
)
static

Definition at line 1109 of file trigger_central.cpp.

1109 {
1110 shape.initializeTriggerWaveform(FOUR_STROKE_CAM_SENSOR, p_config.TriggerType, /*isCrank*/ false);
1111 if (camIndex == 0) {
1112 // at the moment we only support override of first cam
1113 // nasty code: this implicitly adjusts 'shape' parameter
1115 }
1116 shape.initializeSyncPoint(initState, p_config);
1117}
trigger_config_s TriggerType
void initializeTriggerWaveform(operation_mode_e triggerOperationMode, const trigger_config_s &triggerType, bool isCrankWheel=true)

Referenced by TriggerCentral::applyShapesConfiguration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logVvtFront()

static void logVvtFront ( bool  useOnlyRise,
bool  isImportantFront,
TriggerValue  front,
efitick_t  nowNt,
int  index 
)
static

Definition at line 234 of file trigger_central.cpp.

234 {
236 // If we care about both edges OR displayLogicLevel is set, log every front exactly as it is
238
239#if EFI_TOOTH_LOGGER
240 LogTriggerCamTooth(front == TriggerValue::RISE, nowNt, index);
241#endif /* EFI_TOOTH_LOGGER */
242 } else {
243 if (isImportantFront) {
244 // On the important edge, log a rise+fall pair, and nothing on the real falling edge
247
248#if EFI_TOOTH_LOGGER
249 LogTriggerCamTooth(true, nowNt, index);
250 LogTriggerCamTooth(false, nowNt, index);
251#endif /* EFI_TOOTH_LOGGER */
252 }
253 }
254}
void addEngineSnifferVvtEvent(int vvtIndex, FrontDirection frontDirection)
FrontDirection
void LogTriggerCamTooth(bool isRising, efitick_t timestamp, int index)

Referenced by handleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onConfigurationChangeTriggerCallback()

void onConfigurationChangeTriggerCallback ( )

Definition at line 1057 of file trigger_central.cpp.

1057 {
1058 bool changed = false;
1059 // todo: how do we static_assert here?
1060 criticalAssertVoid(efi::size(engineConfiguration->camInputs) == efi::size(engineConfiguration->vvtOffsets), "sizes");
1061
1062 for (size_t camIndex = 0; camIndex < efi::size(engineConfiguration->camInputs); camIndex++) {
1063 changed |= isConfigurationChanged(camInputs[camIndex]);
1064 changed |= isConfigurationChanged(vvtOffsets[camIndex]);
1065 }
1066
1067 for (size_t i = 0; i < efi::size(engineConfiguration->triggerGapOverrideFrom); i++) {
1068 changed |= isConfigurationChanged(triggerGapOverrideFrom[i]);
1069 changed |= isConfigurationChanged(triggerGapOverrideTo[i]);
1070 }
1071
1072 for (size_t i = 0; i < efi::size(engineConfiguration->triggerInputPins); i++) {
1073 changed |= isConfigurationChanged(triggerInputPins[i]);
1075 if (engineConfiguration->vvtMode[0] == VVT_MAP_V_TWIN && isBrainPinValid(pin)) {
1076 criticalError("Please no physical sensors in CAM by MAP mode index=%d %s", i, hwPortname(pin));
1077 }
1078 }
1079
1080 for (size_t i = 0; i < efi::size(engineConfiguration->vvtMode); i++) {
1081 changed |= isConfigurationChanged(vvtMode[i]);
1082 }
1083
1084 changed |= isConfigurationChanged(trigger.type);
1085 changed |= isConfigurationChanged(skippedWheelOnCam);
1086 changed |= isConfigurationChanged(twoStroke);
1087 changed |= isConfigurationChanged(globalTriggerAngleOffset);
1088 changed |= isConfigurationChanged(trigger.customTotalToothCount);
1089 changed |= isConfigurationChanged(trigger.customSkippedToothCount);
1090 changed |= isConfigurationChanged(overrideTriggerGaps);
1091 changed |= isConfigurationChanged(gapTrackingLengthOverride);
1092 changed |= isConfigurationChanged(overrideVvtTriggerGaps);
1093 changed |= isConfigurationChanged(gapVvtTrackingLengthOverride);
1094
1095 if (changed) {
1096 #if EFI_ENGINE_CONTROL
1099 #endif
1100 }
1101#if EFI_DETAILED_LOGGING
1102 efiPrintf("isTriggerConfigChanged=%d", triggerConfigChanged);
1103#endif /* EFI_DETAILED_LOGGING */
1104
1105 // we do not want to miss two updates in a row
1107}
void updateTriggerConfiguration()
Definition engine.cpp:133
TriggerNoiseFilter noiseFilter
bool triggerConfigChangedOnLastConfigurationChange
const char * hwPortname(brain_pin_e brainPin)
brain_pin_e pin
Definition stm32_adc.cpp:15
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]

Referenced by incrementGlobalConfigurationVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportEventToWaveChart()

static void reportEventToWaveChart ( trigger_event_e  ckpSignalType,
int  triggerEventIndex,
bool  addOppositeEvent 
)
static

Definition at line 569 of file trigger_central.cpp.

569 {
570 if (!getTriggerCentral()->isEngineSnifferEnabled) { // this is here just as a shortcut so that we avoid engine sniffer as soon as possible
571 return; // engineSnifferRpmThreshold is accounted for inside getTriggerCentral()->isEngineSnifferEnabled
572 }
573
574 int wheelIndex = wheelIndeces[(int )ckpSignalType];
575
576 bool isUp = isTriggerUpEvent(ckpSignalType);
577
578 addEngineSnifferCrankEvent(wheelIndex, triggerEventIndex, isUp ? FrontDirection::UP : FrontDirection::DOWN);
579 if (addOppositeEvent) {
580 // let's add the opposite event right away
581 addEngineSnifferCrankEvent(wheelIndex, triggerEventIndex, isUp ? FrontDirection::DOWN : FrontDirection::UP);
582 }
583}
void addEngineSnifferCrankEvent(int wheelIndex, int triggerEventIndex, FrontDirection frontDirection)
static const int wheelIndeces[4]
constexpr bool isTriggerUpEvent(trigger_event_e event)

Referenced by TriggerCentral::handleShaftSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetRunningTriggerCounters()

static void resetRunningTriggerCounters ( )
static

Definition at line 1050 of file trigger_central.cpp.

1050 {
1051#if !EFI_UNIT_TEST
1053 triggerInfo();
1054#endif
1055}

Referenced by initTriggerCentral().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipToothSpecialShape()

PUBLIC_API_WEAK bool skipToothSpecialShape ( size_t  index,
vvt_mode_e  vvtMode,
angle_t  currentPosition 
)
Returns
true if tooth should be ignored

Definition at line 299 of file trigger_central.cpp.

299 {
300 UNUSED(index);
301
302 switch(vvtMode) {
303 case VVT_TOYOTA_3_TOOTH:
304 {
307 // we do not know if we are in sync or out of sync, so we have to be looking for both possibilities
308 if ((currentPosition < from || currentPosition > to) &&
309 (currentPosition < from + 360 || currentPosition > to + 360)) {
310 // outside of the expected range
311 return true;
312 }
313 }
314 break;
315 default:
316
317 // else, do nothing
318 break;
319 }
320 return false;
321}

Referenced by handleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tooSoonToHandleSignal()

static bool tooSoonToHandleSignal ( )
static

Definition at line 256 of file trigger_central.cpp.

256 {
257#if EFI_PROD_CODE
258extern bool main_loop_started;
259 if (!main_loop_started) {
261 return true;
262 }
263#endif //EFI_PROD_CODE
264 return false;
265}
bool main_loop_started
Definition rusefi.cpp:143
@ CUSTOM_ERR_INPUT_DURING_INITIALISATION

Referenced by hwHandleShaftSignal(), and hwHandleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triggerInfo()

void triggerInfo ( void  )

Definition at line 952 of file trigger_central.cpp.

952 {
953#if EFI_PROD_CODE || EFI_SIMULATOR
954
956 TriggerWaveform *ts = &tc->triggerShape;
957
958
959#if (HAL_TRIGGER_USE_PAL == TRUE) && (PAL_USE_CALLBACKS == TRUE)
960 efiPrintf("trigger PAL mode %d", tc->hwTriggerInputEnabled);
961#else
962
963#endif /* HAL_TRIGGER_USE_PAL */
964
965 efiPrintf("Template %s (%d) trigger %s (%d) syncEdge=%s tdcOffset=%.2f",
970 getSyncEdge(TRIGGER_WAVEFORM(syncEdge)), TRIGGER_WAVEFORM(tdcPosition));
971
973 efiPrintf("total %d/skipped %d", engineConfiguration->trigger.customTotalToothCount,
975 }
976
977
978 efiPrintf("trigger#1 event counters up=%d/down=%d", tc->getHwEventCounter(0),
979 tc->getHwEventCounter(1));
980
981 if (ts->needSecondTriggerInput) {
982 efiPrintf("trigger#2 event counters up=%d/down=%d", tc->getHwEventCounter(2),
983 tc->getHwEventCounter(3));
984 }
985 efiPrintf("expected cycle events %d/%d",
986 TRIGGER_WAVEFORM(getExpectedEventCount(TriggerWheel::T_PRIMARY)),
987 TRIGGER_WAVEFORM(getExpectedEventCount(TriggerWheel::T_SECONDARY)));
988
989 efiPrintf("trigger type=%d/need2ndChannel=%s", (int)engineConfiguration->trigger.type,
990 boolToString(TRIGGER_WAVEFORM(needSecondTriggerInput)));
991
992
993 efiPrintf("synchronizationNeeded=%s/isError=%s/total errors=%lu ord_err=%lu/total revolutions=%d/self=%s",
1000
1001 if (TRIGGER_WAVEFORM(isSynchronizationNeeded)) {
1002 efiPrintf("gap from %.2f to %.2f", TRIGGER_WAVEFORM(synchronizationRatioFrom[0]), TRIGGER_WAVEFORM(synchronizationRatioTo[0]));
1003 }
1004
1005#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
1006
1007#if EFI_PROD_CODE
1008
1009 efiPrintf("primary trigger input: %s", hwPortname(engineConfiguration->triggerInputPins[0]));
1010 efiPrintf("primary trigger simulator: %s %s freq=%d",
1014
1015 if (ts->needSecondTriggerInput) {
1016 efiPrintf("secondary trigger input: %s", hwPortname(engineConfiguration->triggerInputPins[1]));
1017#if EFI_EMULATE_POSITION_SENSORS
1018 efiPrintf("secondary trigger simulator: %s %s phase=%d",
1021#endif /* EFI_EMULATE_POSITION_SENSORS */
1022 }
1023
1024
1025 for (int camInputIndex = 0; camInputIndex<CAM_INPUTS_COUNT;camInputIndex++) {
1026 if (isBrainPinValid(engineConfiguration->camInputs[camInputIndex])) {
1027 int camLogicalIndex = camInputIndex % CAMS_PER_BANK;
1028 efiPrintf("VVT input: %s mode %s", hwPortname(engineConfiguration->camInputs[camInputIndex]),
1029 getVvt_mode_e(engineConfiguration->vvtMode[camLogicalIndex]));
1030 efiPrintf("VVT %d event counters: %d/%d",
1031 camInputIndex,
1032 tc->vvtEventRiseCounter[camInputIndex], tc->vvtEventFallCounter[camInputIndex]);
1033 }
1034 }
1035
1036 efiPrintf("primary logic input: %s", hwPortname(engineConfiguration->logicAnalyzerPins[0]));
1037 efiPrintf("secondary logic input: %s", hwPortname(engineConfiguration->logicAnalyzerPins[1]));
1038
1039
1040 efiPrintf("totalTriggerHandlerMaxTime=%lu", triggerMaxDuration);
1041
1042#endif /* EFI_PROD_CODE */
1043
1044#if EFI_ENGINE_SNIFFER
1045 efiPrintf("engine sniffer current size=%d", waveChart.getSize());
1046#endif /* EFI_ENGINE_SNIFFER */
1047
1048}
const char * getPin_output_mode_e(pin_output_mode_e value)
const char * getVvt_mode_e(vvt_mode_e value)
const char * getEngine_type_e(engine_type_e value)
const char * getTrigger_type_e(trigger_type_e value)
const char * getSyncEdge(SyncEdge value)
pwm_config_safe_state_s safe
int getHwEventCounter(int index) const
int getSynchronizationCounter() const
uint32_t totalTriggerErrorCounter
Trigger shape has all the fields needed to describe and decode trigger signal.
const char * boolToString(bool value)
Definition efilib.cpp:19
brain_input_pin_e logicAnalyzerPins[LOGIC_ANALYZER_CHANNEL_COUNT]
pin_output_mode_e triggerSimulatorPinModes[TRIGGER_SIMULATOR_PIN_COUNT]
PwmConfig triggerEmulatorSignals[NUM_EMULATOR_CHANNELS]

Referenced by initTriggerCentral(), and resetRunningTriggerCounters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triggerShapeInfo()

static void triggerShapeInfo ( )
static

Definition at line 935 of file trigger_central.cpp.

935 {
936#if EFI_PROD_CODE || EFI_SIMULATOR
939 efiPrintf("syncEdge=%s", getSyncEdge(TRIGGER_WAVEFORM(syncEdge)));
940 efiPrintf("gap from %.2f to %.2f", TRIGGER_WAVEFORM(synchronizationRatioFrom[0]), TRIGGER_WAVEFORM(synchronizationRatioTo[0]));
941
942 for (size_t i = 0; i < shape->getSize(); i++) {
943 efiPrintf("event %d %.2f", i, triggerFormDetails->eventAngles[i]);
944 }
945#endif
946}
TriggerFormDetails triggerFormDetails
angle_t eventAngles[2 *PWM_PHASE_MAX_COUNT]

Referenced by initTriggerCentral().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateTriggerInputs()

void validateTriggerInputs ( )

Definition at line 1266 of file trigger_central.cpp.

1266 {
1268 criticalError("First trigger channel not configured while second one is.");
1269 }
1270
1272 criticalError("First bank cam input is required if second bank specified");
1273 }
1274}

Referenced by startHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vvtWithRealDecoder()

static bool vvtWithRealDecoder ( vvt_mode_e  vvtMode)
static

Definition at line 127 of file trigger_central.cpp.

127 {
128 return vvtMode != VVT_INACTIVE
129 && vvtMode != VVT_TOYOTA_3_TOOTH /* VVT_2JZ is an unusual 3/0 missed tooth symmetrical wheel */
130 && vvtMode != VVT_HONDA_K_INTAKE
131 && vvtMode != VVT_MAP_V_TWIN
132 && !boardIsSpecialVvtDecoder(vvtMode)
133 && vvtMode != VVT_SINGLE_TOOTH;
134}
PUBLIC_API_WEAK bool boardIsSpecialVvtDecoder(vvt_mode_e vvtMode)

Referenced by handleVvtCamSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wrapVvt()

static angle_t wrapVvt ( angle_t  vvtPosition,
int  period 
)
static

See also wrapAngle

Definition at line 223 of file trigger_central.cpp.

223 {
224 // Wrap VVT position in to the range [-360, 360)
225 while (vvtPosition < -period / 2) {
226 vvtPosition += period;
227 }
228 while (vvtPosition >= period / 2) {
229 vvtPosition -= period;
230 }
231 return vvtPosition;
232}
beuint32_t period

Referenced by handleVvtCamSignal().

Here is the caller graph for this function:

Variable Documentation

◆ initState

TriggerDecoderBase initState("init") ( "init"  )

◆ mapAtAngle

float mapAtAngle[200]

Definition at line 690 of file trigger_central.cpp.

Referenced by TriggerCentral::decodeMapCam().

◆ maxTriggerReentrant

int maxTriggerReentrant = 0

◆ triggerDuration

uint32_t triggerDuration

Definition at line 461 of file trigger_central.cpp.

Referenced by handleShaftSignal().

◆ triggerEmulatorSignals

PwmConfig triggerEmulatorSignals[NUM_EMULATOR_CHANNELS]
extern

◆ triggerMaxDuration

uint32_t triggerMaxDuration = 0

Definition at line 462 of file trigger_central.cpp.

Referenced by handleShaftSignal(), resetMaxValues(), and triggerInfo().

◆ triggerReentrant

int triggerReentrant = 0

Definition at line 459 of file trigger_central.cpp.

Referenced by handleShaftSignal().

◆ waveChart

WaveChart waveChart

◆ wheelIndeces

const int wheelIndeces[4] = { 0, 0, 1, 1}
static

Definition at line 567 of file trigger_central.cpp.

567{ 0, 0, 1, 1};

Referenced by reportEventToWaveChart().

Go to the source code of this file.