diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 6f47d12c7a..3280d7f2c7 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -328,6 +328,13 @@ void Engine::prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F) { injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); + if (ENGINE(engineConfiguration2)->processing->usedAtEngineCycle != 0 && + ENGINE(engineConfiguration2)->processing->usedAtEngineCycle == ENGINE(rpmCalculator).getRevolutionCounter()) { + // we are here if engine is still using this older fuel schedule, not yet time to override it +// scheduleMsg(&logger, "still need %d", ENGINE(rpmCalculator).getRevolutionCounter()); + return; + } + ENGINE(engineConfiguration2)->processing->addFuelEvents( mode PASS_ENGINE_PARAMETER); ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index dc4fc46ea1..ffd63f626a 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -43,6 +43,8 @@ public: */ void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S); + uint32_t usedAtEngineCycle; + InjectionEventList injectionEvents; /** @@ -258,6 +260,14 @@ public: WallFuel wallFuel; + /** + * we have a background thread preparing new fuel schedule while engine is running using existing + * copy of fuel schedule. This pointer allows us to use the same schedule for the whole duration of an + * engine cycle. + * + */ + FuelSchedule *fuelScheduleForThisEngineCycle; + /** * That's the list of pending spark firing events */ diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index f13c992541..e85b61c647 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -128,12 +128,22 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int eventIndex, bool limitedF return; } + // scheduleMsg(logger, "handleFuel totalPerCycle=%f", totalPerCycle); + // scheduleMsg(logger, "handleFuel engineCycleDuration=%f", engineCycleDuration); + if (engine->isCylinderCleanupMode) { return; } floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset; +// scheduleMsg(logger, "handleFuel pin=%s eventIndex %d duration=%fms %d", event->output->name, +// eventIndex, +// injectionDuration, +// getRevolutionCounter()); +// scheduleMsg(logger, "handleFuel pin=%s delay=%f %d", event->output->name, injectionStartDelayUs, +// getRevolutionCounter()); + OutputSignal *signal = &ENGINE(engineConfiguration2)->fuelActuators[eventIndex]; if (event->isSimultanious) { @@ -179,13 +189,15 @@ static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t eventIndex, int * Ignition events are defined by addFuelEvents() according to selected * fueling strategy */ - FuelSchedule *fs = ENGINE(engineConfiguration2)->injectionEvents; + FuelSchedule *fs = engine->fuelScheduleForThisEngineCycle; InjectionEventList *injectionEvents = &fs->injectionEvents; if (!fs->hasEvents[eventIndex]) return; +// scheduleMsg(logger, "handleFuel ind=%d %d", eventIndex, getRevolutionCounter()); + ENGINE(tpsAccelEnrichment.onNewValue(getTPS(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER)); ENGINE(engineLoadAccelEnrichment.onEngineCycle(PASS_ENGINE_PARAMETER_F)); @@ -453,6 +465,10 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL int revolutionIndex = ENGINE(rpmCalculator).getRevolutionCounter() % 2; if (eventIndex == 0) { + // these two statements should be atomic, but in reality we should be fine, right? + engine->fuelScheduleForThisEngineCycle = ENGINE(engineConfiguration2)->injectionEvents; + engine->fuelScheduleForThisEngineCycle->usedAtEngineCycle = ENGINE(rpmCalculator).getRevolutionCounter(); + if (triggerVersion.isOld()) { prepareOutputSignals(PASS_ENGINE_PARAMETER_F); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 42beb67484..938e36c90e 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -296,5 +296,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 20160715; + return 20160805; }