From 8c0308cca7ed241905fd53892ad3dbb6fcc90a74 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 28 Nov 2016 14:01:52 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/algo/event_registry.cpp | 1 + firmware/controllers/algo/event_registry.h | 4 ++ firmware/controllers/trigger/spark_logic.cpp | 48 +++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/firmware/controllers/algo/event_registry.cpp b/firmware/controllers/algo/event_registry.cpp index 2313406c72..354486f74d 100644 --- a/firmware/controllers/algo/event_registry.cpp +++ b/firmware/controllers/algo/event_registry.cpp @@ -43,6 +43,7 @@ IgnitionEvent::IgnitionEvent() { memset(outputs, 0, sizeof(outputs)); advance = NAN; sparkId = 0; + cylinderIndex = 0; } IgnitionOutputPin * IgnitionEvent::getOutputForLoggins() { diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index 97d6e26345..500e2ce433 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -56,7 +56,11 @@ public: event_trigger_position_s dwellPosition; event_trigger_position_s sparkPosition; IgnitionEvent *next; + /** + * @see globalSparkIdCoutner + */ int sparkId; + int cylinderIndex; char *name; IgnitionOutputPin *getOutputForLoggins(); }; diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index c950813a20..4ebde5d857 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -222,29 +222,33 @@ static void addIgnitionEvent(int cylinderIndex, angle_t localAdvance, angle_t dw } -static void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, - IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { +static void prepareIgnitionSchedule(int cylinderIndex, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { + // todo: clean up this implementation? does not look too nice as is. + + // change of sign here from 'before TDC' to 'after TDC' + angle_t localAdvance = -ENGINE(engineState.timingAdvance) + ENGINE(angleExtra[cylinderIndex]); + const int index = ENGINE(ignitionPin[cylinderIndex]); + const int coilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); + IgnitionOutputPin *output = &enginePins.coils[coilIndex]; + + IgnitionOutputPin *secondOutput; + if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { + int secondIndex = index + CONFIG(specs.cylindersCount) / 2; + int secondCoilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), secondIndex)); + secondOutput = &enginePins.coils[secondCoilIndex]; + } else { + secondOutput = NULL; + } + + addIgnitionEvent(cylinderIndex, localAdvance, ENGINE(engineState.dwellAngle), list, output, secondOutput PASS_ENGINE_PARAMETER); +} + +static void initializeIgnitionActions(IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { efiAssertVoid(engineConfiguration->specs.cylindersCount > 0, "cylindersCount"); - for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - // todo: clean up this implementation? does not look too nice as is. - - // change of sign here from 'before TDC' to 'after TDC' - angle_t localAdvance = -advance + ENGINE(angleExtra[i]); - const int index = ENGINE(ignitionPin[i]); - const int coilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); - IgnitionOutputPin *output = &enginePins.coils[coilIndex]; - - IgnitionOutputPin *secondOutput; - if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { - int secondIndex = index + CONFIG(specs.cylindersCount) / 2; - int secondCoilIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), secondIndex)); - secondOutput = &enginePins.coils[secondCoilIndex]; - } else { - secondOutput = NULL; - } - - addIgnitionEvent(i, localAdvance, dwellAngle, list, output, secondOutput PASS_ENGINE_PARAMETER); + for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) { + list->elements[cylinderIndex].cylinderIndex = cylinderIndex; + prepareIgnitionSchedule(cylinderIndex, list PASS_ENGINE_PARAMETER); } list->isReady = true; } @@ -282,7 +286,7 @@ static ALWAYS_INLINE void prepareIgnitionSchedule(int rpm, int revolutionIndex D list->isReady = false; return; } - initializeIgnitionActions(ENGINE(engineState.timingAdvance), ENGINE(engineState.dwellAngle), list PASS_ENGINE_PARAMETER); + initializeIgnitionActions(list PASS_ENGINE_PARAMETER); engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch; }