From ebf6c75a50ece1e10b3d884b0af771a8aa147b7a Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 16 Jan 2016 17:02:38 -0500 Subject: [PATCH] auto-sync --- firmware/config/engines/mazda_626.cpp | 3 ++ firmware/controllers/algo/engine.h | 3 +- firmware/controllers/math/engine_math.cpp | 48 ++++++++++++++++------- firmware/rusefi.cpp | 2 +- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/firmware/config/engines/mazda_626.cpp b/firmware/config/engines/mazda_626.cpp index 0a80b759b7..8d4d6bd996 100644 --- a/firmware/config/engines/mazda_626.cpp +++ b/firmware/config/engines/mazda_626.cpp @@ -28,7 +28,10 @@ void setMazda626EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->injectionMode = IM_BATCH; + // enable two_wire_batch_injection engineConfiguration->twoWireBatchInjection = true; + // enable two_wire_wasted_spark + engineConfiguration->twoWireBatchIgnition = true; // chartsize 600 engineConfiguration->engineChartSize = 600; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 312f0ade2b..271b8b4da6 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -275,8 +275,9 @@ public: /** * pre-calculated reference to which output pin should be used for * given sequence index within engine cycle + * todo: update documentation */ - NamedOutputPin *ignitionPin[IGNITION_PIN_COUNT]; + int ignitionPin[IGNITION_PIN_COUNT]; void onTriggerEvent(efitick_t nowNt); EngineState engineState; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 4024cbc623..b4c82ac13b 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -90,6 +90,20 @@ void setSingleCoilDwell(engine_configuration_s *engineConfiguration) { #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) + +static void addIgnitionEvent(angle_t localAdvance, angle_t dwellAngle, IgnitionEventList *list, NamedOutputPin *output DECLARE_ENGINE_PARAMETER_S) { + IgnitionEvent *event = list->add(); + + if (!isPinAssigned(output)) { + // todo: extact method for this index math + warning(OBD_PCM_Processor_Fault, "no_pin_cl #%s", output->name); + } + event->output = output; + event->advance = localAdvance; + + findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle PASS_ENGINE_PARAMETER); +} + void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, IgnitionEventList *list DECLARE_ENGINE_PARAMETER_S) { efiAssertVoid(engineConfiguration->specs.cylindersCount > 0, "cylindersCount"); @@ -97,19 +111,23 @@ void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, list->reset(); for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { + // todo: clean up this implementation? does not look too nice as is. + angle_t localAdvance = advance + ENGINE(angleExtra[i]); - NamedOutputPin *output = ENGINE(ignitionPin[i]); + int index = ENGINE(ignitionPin[i]); + int cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); + NamedOutputPin *output = &enginePins.coils[cylinderIndex]; - IgnitionEvent *event = list->add(); + addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); - if (!isPinAssigned(output)) { - // todo: extact method for this index math - warning(OBD_PCM_Processor_Fault, "no_pin_cl #%s", output->name); + if (CONFIG(ignitionMode) == IM_WASTED_SPARK && CONFIG(twoWireBatchIgnition)) { + index += CONFIG(specs.cylindersCount) / 2; + cylinderIndex = ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), index)); + output = &enginePins.coils[cylinderIndex]; + + addIgnitionEvent(localAdvance, dwellAngle, list, output PASS_ENGINE_PARAMETER); } - event->output = output; - event->advance = localAdvance; - findTriggerPosition(&event->dwellPosition, localAdvance - dwellAngle PASS_ENGINE_PARAMETER); } } @@ -344,25 +362,23 @@ int getCylinderId(firing_order_e firingOrder, int index) { return 1; } -static NamedOutputPin * getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S +static int getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S ) { switch (CONFIG(ignitionMode)) { case IM_ONE_COIL: - return &enginePins.coils[0]; + return 0; break; case IM_WASTED_SPARK: { - int wastedIndex = i % (CONFIG(specs.cylindersCount) / 2); - int id = getCylinderId(CONFIG(specs.firingOrder), wastedIndex); - return &enginePins.coils[ID2INDEX(id)]; + return i % (CONFIG(specs.cylindersCount) / 2); } break; case IM_INDIVIDUAL_COILS: - return &enginePins.coils[ID2INDEX(getCylinderId(CONFIG(specs.firingOrder), i))]; + return i; break; default: warning(OBD_PCM_Processor_Fault, "unsupported ignitionMode %d in initializeIgnitionActions()", engineConfiguration->ignitionMode); - return &enginePins.coils[0]; + return 0; } } @@ -379,6 +395,8 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); + + ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index fc68ed87ae..a8a3e6892f 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160114; + return 20160116; }