From a65c8c9295dceebe0c950f412e562d8a5f64b51c Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 8 Oct 2019 02:35:21 -0400 Subject: [PATCH] something is over-complicated here? looks like two classes should become one? --- firmware/controllers/algo/engine.h | 3 +-- firmware/controllers/algo/event_registry.h | 27 ++++++++++++++++++- firmware/controllers/engine_controller.cpp | 2 +- .../controllers/scheduling/signal_executor.h | 27 +------------------ .../trigger/main_trigger_callback.cpp | 4 +-- unit_tests/engine_test_helper.cpp | 4 +-- 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index b4c899789e..fa12c32967 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -53,8 +53,6 @@ public: void setConfig(persistent_config_s *config); injection_mode_e getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); - InjectionSignalPair fuelActuators[INJECTION_PIN_COUNT]; - IgnitionEventList ignitionEvents; LocalVersionHolder versionForConfigurationListeners; LocalVersionHolder auxParametersVersion; operation_mode_e getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); @@ -93,6 +91,7 @@ public: #if EFI_ENGINE_CONTROL FuelSchedule injectionEvents; + IgnitionEventList ignitionEvents; #endif /* EFI_ENGINE_CONTROL */ WallFuel wallFuel; diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index afb9abaf38..ebf910e073 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -13,10 +13,32 @@ #include "trigger_structure.h" #define MAX_INJECTION_OUTPUT_COUNT INJECTION_PIN_COUNT - +#define MAX_WIRES_COUNT 2 class Engine; +class InjectionEvent; + +class InjectionSignalPair { +public: + InjectionSignalPair(); + scheduling_s signalTimerUp; + scheduling_s endOfInjectionEvent; + + /** + * we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed. + * + * That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see + * overlaps so we need the end counter to always have zero. + * TODO: make watchdog decrement relevant counter + */ + bool isScheduled; + + InjectorOutputPin *outputs[MAX_WIRES_COUNT]; + + InjectionEvent *event; +}; + class InjectionEvent { public: InjectionEvent(); @@ -31,8 +53,11 @@ public: Engine *engine; #endif event_trigger_position_s injectionStart; + + InjectionSignalPair pair; }; + /** * This class knows about when to inject fuel */ diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index d858741a00..c797354288 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -832,6 +832,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20191006; + return 20191007; } #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/scheduling/signal_executor.h b/firmware/controllers/scheduling/signal_executor.h index c8070a0a53..7679c42a3a 100644 --- a/firmware/controllers/scheduling/signal_executor.h +++ b/firmware/controllers/scheduling/signal_executor.h @@ -6,8 +6,7 @@ * @author Andrey Belomutskiy, (c) 2012-2017 */ -#ifndef SIGNAL_EXECUTOR_H_ -#define SIGNAL_EXECUTOR_H_ +#pragma once #include "global.h" #include "scheduler.h" @@ -17,28 +16,4 @@ #include "signal_executor_sleep.h" #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ -#define MAX_WIRES_COUNT 2 -class InjectionEvent; - -class InjectionSignalPair { -public: - InjectionSignalPair(); - scheduling_s signalTimerUp; - scheduling_s endOfInjectionEvent; - - /** - * we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed. - * - * That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see - * overlaps so we need the end counter to always have zero. - * TODO: make watchdog decrement relevant counter - */ - bool isScheduled; - - InjectorOutputPin *outputs[MAX_WIRES_COUNT]; - - InjectionEvent *event; -}; - -#endif /* SIGNAL_EXECUTOR_H_ */ diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 78703084ed..6b046a40d6 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -271,7 +271,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE getRevolutionCounter()); #endif /* EFI_DEFAILED_LOGGING */ - InjectionSignalPair *pair = &ENGINE(fuelActuators[injEventIndex]); + InjectionSignalPair *pair = &event->pair; if (event->isSimultanious) { /** @@ -582,7 +582,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { primeInjEvent.ownIndex = 0; primeInjEvent.isSimultanious = true; - scheduling_s *sDown = &ENGINE(fuelActuators[0]).endOfInjectionEvent; + scheduling_s *sDown = &ENGINE(injectionEvents.elements[0].pair).endOfInjectionEvent; // When the engine is hot, basically we don't need prime inj.pulse, so we use an interpolation over temperature (falloff). // If 'primeInjFalloffTemperature' is not specified (by default), we have a prime pulse deactivation at zero celsius degrees, which is okay. const float maxPrimeInjAtTemperature = -40.0f; // at this temperature the pulse is maximal. diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 6fb93e48df..4b219a89bb 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -152,12 +152,12 @@ void EngineTestHelper::fireTriggerEvents(int count) { } void EngineTestHelper::assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) { - InjectionSignalPair *pair = &engine.fuelActuators[injectorIndex]; + InjectionSignalPair *pair = &engine.injectionEvents.elements[injectorIndex].pair; assertEvent(msg, eventIndex, (void*)seTurnPinHigh, momentX, (long)pair); } void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex) { - InjectionSignalPair *pair = &engine.fuelActuators[injectorIndex]; + InjectionSignalPair *pair = &engine.injectionEvents.elements[injectorIndex].pair; assertEvent(msg, eventIndex, (void*)seTurnPinLow, momentX, (long)pair); }