From a57d7c48fba385ac8b83f59b263ecb50adf26224 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 23 Jun 2021 06:10:27 -0400 Subject: [PATCH] global static not good, there shall be only one god object /s --- firmware/controllers/algo/engine.h | 4 ++++ .../engine_cycle/main_trigger_callback.cpp | 14 +++++--------- .../tests/trigger/test_real_cranking_miata_NA.cpp | 2 +- .../tests/trigger/test_real_cranking_miata_na6.cpp | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index d65561ca8a..c574839b43 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -87,6 +87,10 @@ public: bool isPwmEnabled = true; int triggerActivitySecond = 0; + const char *prevOutputName = nullptr; + + InjectionEvent primeInjEvent; + IEtbController *etbControllers[ETB_COUNT] = {nullptr}; IFuelComputer *fuelComputer = nullptr; IInjectorModel *injectorModel = nullptr; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index b3ea328d94..a04c3caa39 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -61,10 +61,6 @@ EXTERN_ENGINE; -static const char *prevOutputName = nullptr; - -static InjectionEvent primeInjEvent; - // todo: figure out if this even helps? //#if defined __GNUC__ //#define RAM_METHOD_PREFIX __attribute__((section(".ram"))) @@ -259,12 +255,12 @@ void InjectionEvent::onTriggerTooth(size_t trgEventIndex, int rpm, efitick_t now // we are ignoring low RPM in order not to handle "engine was stopped to engine now running" transition if (rpm > 2 * engineConfiguration->cranking.rpm) { const char *outputName = outputs[0]->name; - if (prevOutputName == outputName + if (engine->prevOutputName == outputName && engineConfiguration->injectionMode != IM_SIMULTANEOUS && engineConfiguration->injectionMode != IM_SINGLE_POINT) { warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event revCounter=%d %s", getRevolutionCounter(), outputName); } - prevOutputName = outputName; + engine->prevOutputName = outputName; } #if EFI_PRINTF_FUEL_DETAILS @@ -481,7 +477,7 @@ static bool isPrimeInjectionPulseSkipped(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * See testStartOfCrankingPrimingPulse() */ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - INJECT_ENGINE_REFERENCE(&primeInjEvent); + INJECT_ENGINE_REFERENCE(&engine->primeInjEvent); // First, we need a protection against 'fake' ignition switch on and off (i.e. no engine started), to avoid repeated prime pulses. // So we check and update the ignition switch counter in non-volatile backup-RAM @@ -500,8 +496,8 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { ignSwitchCounter = -1; // start prime injection if this is a 'fresh start' if (ignSwitchCounter == 0) { - primeInjEvent.ownIndex = 0; - primeInjEvent.isSimultanious = true; + engine->primeInjEvent.ownIndex = 0; + engine->primeInjEvent.isSimultanious = true; scheduling_s *sDown = &ENGINE(injectionEvents.elements[0]).endOfInjectionEvent; // When the engine is hot, basically we don't need prime inj.pulse, so we use an interpolation over temperature (falloff). diff --git a/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp b/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp index 3fb3c472a8..efe0b3cde6 100644 --- a/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp +++ b/unit_tests/tests/trigger/test_real_cranking_miata_NA.cpp @@ -54,7 +54,7 @@ TEST(cranking, realCrankingFromFile) { } trigger_event_e event = (newState[index] ? riseEvents : fallEvents)[index]; efitick_t nowNt = getTimeNowNt(); -// engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX); + engine->triggerCentral.handleShaftSignal(event, nowNt PASS_ENGINE_PARAMETER_SUFFIX); currentState[index] = newState[index]; } diff --git a/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp b/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp index 66d44230f6..ffdd41b06b 100644 --- a/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp +++ b/unit_tests/tests/trigger/test_real_cranking_miata_na6.cpp @@ -27,8 +27,8 @@ static void fireTriggerEvent(EngineTestHelper*eth, double timestampS, int channe Engine *engine = ð->engine; EXPAND_Engine; - timeNowUs = 1000000 * timestampS; - printf("MIATANA: posting time=%d event=%d\r\n", timeNowUs, event); + timeNowUs = 1'000'000 * timestampS; + printf("MIATANA: posting time=%d event=%d\n", timeNowUs, event); engine->triggerCentral.handleShaftSignal(event, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX); }