From c64a52f20b46cde88cfcc6a0e358bd8608a9fdd6 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 21 Oct 2018 14:03:51 -0400 Subject: [PATCH] refactoring trigger sync layer --- firmware/controllers/trigger/trigger_decoder.cpp | 12 ++++++------ firmware/controllers/trigger/trigger_decoder.h | 4 ---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 6f52263307..ea38652367 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -135,7 +135,8 @@ void TriggerState::reset() { totalRevolutionCounter = 0; totalTriggerErrorCounter = 0; orderingErrorCounter = 0; - currentDuration = 0; + + memset(toothDurations, 0, sizeof(toothDurations)); curSignal = SHAFT_PRIMARY_FALLING; prevSignal = SHAFT_PRIMARY_FALLING; startOfCycleNt = 0; @@ -201,7 +202,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no * For performance reasons, we want to work with 32 bit values. If there has been more then * 10 seconds since previous trigger event we do not really care. */ - currentDuration = + toothDurations[0] = currentDurationLong > 10 * US2NT(US_PER_SECOND_LL) ? 10 * US2NT(US_PER_SECOND_LL) : currentDurationLong; bool isPrimary = triggerWheel == T_PRIMARY; @@ -236,7 +237,6 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no isFirstEvent = false; // todo: skip a number of signal from the beginning - toothDurations[0] = currentDuration; #if EFI_PROD_CODE || defined(__DOXYGEN__) // scheduleMsg(&logger, "from %.2f to %.2f %d %d", triggerConfig->syncRatioFrom, triggerConfig->syncRatioTo, toothDurations[0], shaftPositionState->toothDurations[1]); // scheduleMsg(&logger, "ratio %.2f", 1.0 * toothDurations[0]/ shaftPositionState->toothDurations[1]); @@ -280,7 +280,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no #else if (printTriggerDebug) { #endif /* EFI_PROD_CODE */ - float gap = 1.0 * currentDuration / toothDurations[1]; + float gap = 1.0 * toothDurations[0] / toothDurations[1]; float prevGap = 1.0 * toothDurations[1] / toothDurations[2]; float gap3 = 1.0 * toothDurations[2] / toothDurations[3]; #if EFI_PROD_CODE || defined(__DOXYGEN__) @@ -299,7 +299,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no #else actualSynchGap = gap; - print("current gap %.2f/%.2f/%.2f c=%d prev=%d\r\n", gap, prevGap, gap3, currentDuration, toothDurations[1]); + print("current gap %.2f/%.2f/%.2f c=%d prev=%d\r\n", gap, prevGap, gap3, toothDurations[0], toothDurations[1]); #endif /* EFI_PROD_CODE */ } @@ -425,7 +425,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no toothDurations[3] = toothDurations[2]; toothDurations[2] = toothDurations[1]; - toothDurations[1] = currentDuration; + toothDurations[1] = toothDurations[0]; toothed_previous_time = nowNt; } if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && !isInitializingTrigger) { diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 6a5bab143f..ddabbdb310 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -79,10 +79,6 @@ public: */ uint32_t toothDurations[GAP_TRACKING_LENGHT + 1]; - /** - * this could be a local variable, but it's better for debugging to have it as a field - */ - uint32_t currentDuration; efitime_t toothed_previous_time; current_cycle_state_s currentCycle;