From 65c46cacd3a15c031731c46ddcb40b5b4d91dffb Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 15 Oct 2014 16:02:58 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/algo/ec2.h | 6 ++++++ firmware/controllers/engine_controller.cpp | 16 ++++++++++++++++ .../trigger/main_trigger_callback.cpp | 17 +++++++++++------ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/algo/ec2.h b/firmware/controllers/algo/ec2.h index 3163dc2214..5168114e12 100644 --- a/firmware/controllers/algo/ec2.h +++ b/firmware/controllers/algo/ec2.h @@ -56,6 +56,12 @@ public: * voltage divider configuration. This is a future (?) performance optimization. */ float adcToVoltageInputDividerCoefficient; + + /** + * This field is true if we are in 'cylinder cleanup' state right now + * see isCylinderCleanupEnabled + */ + bool isCylinderCleanupMode; }; typedef struct { diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 9df282f130..36c6c61f59 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -168,6 +168,20 @@ int getTimeNowSeconds(void) { return chTimeNow() / CH_FREQUENCY; } +static void cylinderCleanupControl(Engine *engine) { + bool newValue; + if (engineConfiguration->isCylinderCleanupEnabled) { + newValue = !engine->rpmCalculator->isRunning() && getTPS() > 95; + } else { + newValue = false; + } + if (newValue != engineConfiguration2->isCylinderCleanupMode) { + engineConfiguration2->isCylinderCleanupMode = newValue; + scheduleMsg(&logger, "isCylinderCleanupMode %s", boolToString(newValue)); + } + +} + static void onEvenyGeneralMilliseconds(void *arg) { (void) arg; /** @@ -205,6 +219,8 @@ static void onEvenyGeneralMilliseconds(void *arg) { fanRelayControl(); + cylinderCleanupControl(&engine); + setOutputPinValue(O2_HEATER, engine.rpmCalculator->isRunning()); // schedule next invocation diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index d526173097..cbe3b8ebc4 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -87,6 +87,9 @@ static void handleFuelInjectionEvent(MainTriggerCallback *mainTriggerCallback, A return; } + if (mainTriggerCallback->engineConfiguration2->isCylinderCleanupMode) + return; + float delay = getOneDegreeTimeMs(rpm) * event->position.angleOffset; // if (isCranking()) @@ -107,9 +110,9 @@ static void handleFuel(Engine *engine, MainTriggerCallback *mainTriggerCallback, * fueling strategy */ ActuatorEventList *source = - isCrankingR(rpm) ? - &mainTriggerCallback->engineConfiguration2->engineEventConfiguration.crankingInjectionEvents : - &mainTriggerCallback->engineConfiguration2->engineEventConfiguration.injectionEvents; + isCrankingR(rpm) ? + &mainTriggerCallback->engineConfiguration2->engineEventConfiguration.crankingInjectionEvents : + &mainTriggerCallback->engineConfiguration2->engineEventConfiguration.injectionEvents; for (int i = 0; i < source->size; i++) { ActuatorEvent *event = &source->events[i]; @@ -119,7 +122,8 @@ static void handleFuel(Engine *engine, MainTriggerCallback *mainTriggerCallback, } } -static void handleSparkEvent(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, IgnitionEvent *iEvent, int rpm) { +static void handleSparkEvent(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, IgnitionEvent *iEvent, + int rpm) { engine_configuration_s *engineConfiguration = mainTriggerCallback->engineConfiguration; engine_configuration2_s *engineConfiguration2 = mainTriggerCallback->engineConfiguration2; @@ -183,7 +187,8 @@ static void handleSparkEvent(MainTriggerCallback *mainTriggerCallback, uint32_t } } -static void handleSpark(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, int rpm, IgnitionEventList *list) { +static void handleSpark(MainTriggerCallback *mainTriggerCallback, uint32_t eventIndex, int rpm, + IgnitionEventList *list) { if (!isValidRpm(rpm) || !mainTriggerCallback->engineConfiguration->isIgnitionEnabled) return; // this might happen for instance in case of a single trigger event after a pause @@ -233,7 +238,7 @@ extern Engine engine; * Both injection and ignition are controlled from this method. */ void onTriggerEvent(trigger_event_e ckpSignalType, uint32_t eventIndex, MainTriggerCallback *mainTriggerCallback) { - (void)ckpSignalType; + (void) ckpSignalType; efiAssertVoid(eventIndex < 2 * mainTriggerCallback->engineConfiguration2->triggerShape.shaftPositionEventCount, "event index"); efiAssertVoid(getRemainingStack(chThdSelf()) > 16, "stack#3");