From 67f5b18f344e22ca93d556e15be57d33a2cc66c7 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 13 Feb 2021 11:19:39 -0500 Subject: [PATCH] not great solution to code duplication, also helping QC build --- .../digital_input/trigger/trigger_input.h | 13 +++++++++ .../trigger/trigger_input_exti.cpp | 15 ++++++---- .../trigger/trigger_input_icu.cpp | 28 +++++++++++-------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input.h b/firmware/hw_layer/digital_input/trigger/trigger_input.h index f401b73c6b..ec9c360f59 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input.h +++ b/firmware/hw_layer/digital_input/trigger/trigger_input.h @@ -13,6 +13,19 @@ #include "trigger_structure.h" #include "trigger_central.h" + +#define TRIGGER_BAIL_IF_DISABLED \ + if (!engine->hwTriggerInputEnabled) { \ + return; \ + } + +#define TRIGGER_BAIL_IF_SELF_STIM \ + if (engine->directSelfStimulation) { \ + /* sensor noise + self-stim = loss of trigger sync */ \ + return; \ + } + + #define TRIGGER_SUPPORTED_CHANNELS 2 void turnOnTriggerInputPins(Logging *sharedLogger); diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp index 232f28784e..1d3d895a9c 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp @@ -31,9 +31,11 @@ static ioline_t camLines[CAM_INPUTS_COUNT]; static void shaft_callback(void *arg) { // do the time sensitive things as early as possible! efitick_t stamp = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif + int index = (int)arg; ioline_t pal_line = shaftLines[index]; bool rise = (palReadLine(pal_line) == PAL_HIGH); @@ -63,9 +65,10 @@ static void shaft_callback(void *arg) { static void cam_callback(void *arg) { efitick_t stamp = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif int index = (int)arg; ioline_t pal_line = camLines[index]; diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp index 6d4179e2ff..0a4554df00 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp @@ -29,9 +29,10 @@ static Logging *logger; static void vvtRisingCallback(void *arg) { efitick_t now = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif int index = (int)arg; #if EFI_TOOTH_LOGGER @@ -45,9 +46,10 @@ static void vvtRisingCallback(void *arg) { static void vvtFallingCallback(void * arg) { efitick_t now = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif int index = (int)arg; #if EFI_TOOTH_LOGGER if (!CONFIG(displayLogicLevelsInEngineSniffer)) { @@ -63,9 +65,10 @@ static void vvtFallingCallback(void * arg) { static void shaftRisingCallback(bool isPrimary) { efitick_t stamp = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif icuRisingCallbackCounter++; // todo: support for 3rd trigger input channel @@ -82,9 +85,10 @@ static void shaftRisingCallback(bool isPrimary) { static void shaftFallingCallback(bool isPrimary) { efitick_t stamp = getTimeNowNt(); - if (!engine->hwTriggerInputEnabled) { - return; - } + TRIGGER_BAIL_IF_DISABLED +#if HW_CHECK_MODE + TRIGGER_BAIL_IF_SELF_STIM +#endif icuFallingCallbackCounter++;