From b178ee956faa2771c5df67f9fa76684d51c91d2e Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 25 Jan 2016 03:02:33 -0500 Subject: [PATCH] auto-sync --- firmware/config/engines/mazda_626.cpp | 3 +++ .../controllers/algo/accel_enrichment.cpp | 2 +- firmware/controllers/algo/engine.cpp | 23 ++++++++++++++++--- firmware/controllers/algo/engine.h | 5 +++- .../controllers/algo/engine_configuration.cpp | 2 ++ firmware/controllers/math/engine_math.cpp | 2 +- .../trigger/main_trigger_callback.cpp | 9 +------- firmware/rusefi.cpp | 2 +- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/firmware/config/engines/mazda_626.cpp b/firmware/config/engines/mazda_626.cpp index 8d4d6bd996..72a8f71e6d 100644 --- a/firmware/config/engines/mazda_626.cpp +++ b/firmware/config/engines/mazda_626.cpp @@ -26,6 +26,9 @@ void setMazda626EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->trigger.type = TT_60_2_VW; // engineConfiguration->trigger.type = TT_MAZDA_DOHC_1_4; + // with this complex trigger we do not need this by default + boardConfiguration->sensorChartMode = SC_OFF; + engineConfiguration->injectionMode = IM_BATCH; // enable two_wire_batch_injection diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index 479a7d6fb9..47a4e18943 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -100,7 +100,7 @@ void AccelEnrichmemnt::reset() { void AccelEnrichmemnt::onNewValue(float currentValue DECLARE_ENGINE_PARAMETER_S) { if (!cisnan(this->currentValue)) { delta = currentValue - this->currentValue; - FuelSchedule *fs = &engine->engineConfiguration2->injectionEvents; + FuelSchedule *fs = engine->engineConfiguration2->injectionEvents; cb.add(delta * fs->eventsCount); } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index aa538dcbcc..0c482ac0ec 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -19,6 +19,7 @@ #include "advance_map.h" #include "speed_density.h" #include "advance_map.h" +#include "efilib2.h" #if EFI_PROD_CODE || defined(__DOXYGEN__) #include "injector_central.h" @@ -86,6 +87,7 @@ void Engine::addConfigurationListener(configuration_callback_t callback) { } Engine::Engine(persistent_config_s *config) { + init(config); /** * it's important for fixAngle() that engineCycle field never has zero */ @@ -98,12 +100,9 @@ Engine::Engine(persistent_config_s *config) { isTestMode = false; isSpinning = false; adcToVoltageInputDividerCoefficient = NAN; - this->config = config; - engineConfiguration = &config->engineConfiguration; engineConfiguration2 = NULL; engineState.iat = engineState.clt = NAN; memset(&ignitionPin, 0, sizeof(ignitionPin)); - memset(config, 0, sizeof(persistent_config_s)); knockNow = false; knockEver = false; @@ -181,6 +180,9 @@ void Engine::preCalculate() { } void Engine::init(persistent_config_s *config) { + this->config = config; + engineConfiguration = &config->engineConfiguration; + memset(config, 0, sizeof(persistent_config_s)); } static bool stopPin(NamedOutputPin *output) { @@ -304,6 +306,21 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { } engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_F); + + ENGINE(m.beforeInjectonSch) = GET_TIMESTAMP(); + + injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); + + ENGINE(engineConfiguration2)->processing->addFuelEvents( + mode PASS_ENGINE_PARAMETER); + ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); + + /** + * Swap pointers. This way we are always reading from one instance while adjusting scheduling of another instance. + */ + FuelSchedule * t = ENGINE(engineConfiguration2)->injectionEvents; + ENGINE(engineConfiguration2)->injectionEvents = ENGINE(engineConfiguration2)->processing; + ENGINE(engineConfiguration2)->processing = t; } StartupFuelPumping::StartupFuelPumping() { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e5a5111add..ccd70eea6c 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -70,7 +70,10 @@ public: engine_configuration2_s(); #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) - FuelSchedule injectionEvents; + FuelSchedule injectionEvents0; + FuelSchedule injectionEvents1; + FuelSchedule *injectionEvents; + FuelSchedule *processing; #endif OutputSignal fuelActuators[MAX_INJECTION_OUTPUT_COUNT]; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index cd6f90c7cb..0a2813ee3f 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -864,6 +864,8 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN } engine_configuration2_s::engine_configuration2_s() { + injectionEvents = &injectionEvents0; + processing = &injectionEvents0; } void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S) { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index eb8957beb7..86db8f4b20 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -407,7 +407,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { TRIGGER_SHAPE(triggerIndexByAngle[angle]) = triggerShapeIndex; } - engineConfiguration2->injectionEvents.addFuelEvents( + engineConfiguration2->injectionEvents->addFuelEvents( engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 9ffb2a8db9..f45d476f26 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -170,7 +170,7 @@ 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(engineConfiguration2)->injectionEvents; InjectionEventList *source = &fs->injectionEvents; @@ -360,13 +360,6 @@ static ALWAYS_INLINE void scheduleIgnitionAndFuelEvents(int rpm, int revolutionI initializeIgnitionActions(ENGINE(engineState.timingAdvance), ENGINE(engineState.dwellAngle), list PASS_ENGINE_PARAMETER); engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch; - ENGINE(m.beforeInjectonSch) = GET_TIMESTAMP(); - - injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); - - ENGINE(engineConfiguration2)->injectionEvents.addFuelEvents( - mode PASS_ENGINE_PARAMETER); - ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); } /** diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 33905fac6c..922c659d0b 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -186,7 +186,7 @@ void runRusEfi(void) { */ initializeConsole(&sharedLogger); - engine->init(); + engine->init(config); addConsoleAction("reboot", scheduleReboot);