diff --git a/firmware/config/engines/audi_aan.cpp b/firmware/config/engines/audi_aan.cpp index b6e8225629..40ebfd33d2 100644 --- a/firmware/config/engines/audi_aan.cpp +++ b/firmware/config/engines/audi_aan.cpp @@ -26,8 +26,6 @@ #include "engine_controller.h" -extern engine_configuration2_s engineConfiguration2; - static void configureShaftPositionEmulatorShapeWhat(PwmConfig *state) { /** * One signal per cam shaft revolution diff --git a/firmware/controllers/algo/accel_enrichment.cpp b/firmware/controllers/algo/accel_enrichment.cpp index b8d0442897..74b91fbe09 100644 --- a/firmware/controllers/algo/accel_enrichment.cpp +++ b/firmware/controllers/algo/accel_enrichment.cpp @@ -96,7 +96,6 @@ int AccelEnrichmemnt::getMaxDeltaIndex(DECLARE_ENGINE_PARAMETER_F) { float AccelEnrichmemnt::getMaxDelta(DECLARE_ENGINE_PARAMETER_F) { int index = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_F); - FuelSchedule *fs = engine->engineConfiguration2->injectionEvents; return (cb.get(index) - (cb.get(index - 1))) * CONFIG(specs.cylindersCount); } @@ -136,7 +135,6 @@ floatms_t AccelEnrichmemnt::getTpsEnrichment(DECLARE_ENGINE_PARAMETER_F) { float AccelEnrichmemnt::getEngineLoadEnrichment(DECLARE_ENGINE_PARAMETER_F) { int index = getMaxDeltaIndex(PASS_ENGINE_PARAMETER_F); - FuelSchedule *fs = engine->engineConfiguration2->injectionEvents; float d = (cb.get(index) - (cb.get(index - 1))) * CONFIG(specs.cylindersCount); float result = 0; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 4c24f592ba..bbee071e69 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -96,7 +96,6 @@ void Engine::reset() { isEngineChartEnabled = false; sensorChartMode = SC_OFF; actualLastInjection = 0; - fuelScheduleForThisEngineCycle = NULL; isAlternatorControlEnabled = false; wallFuelCorrection = 0; /** @@ -111,7 +110,6 @@ void Engine::reset() { isTestMode = false; isSpinning = false; adcToVoltageInputDividerCoefficient = NAN; - engineConfiguration2 = NULL; engineState.iat = engineState.clt = NAN; memset(&ignitionPin, 0, sizeof(ignitionPin)); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 1cec530d93..c5d6121994 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -46,8 +46,6 @@ public: void addFuelEvents(DECLARE_ENGINE_PARAMETER_F); void addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_S); - uint32_t usedAtEngineCycle; - InjectionEvent elements[MAX_INJECTION_OUTPUT_COUNT]; bool isReady; @@ -55,32 +53,6 @@ private: void clear(); }; -/** - * This structure is still separate from Engine simply because this goes into CCM memory and Engine is in main memory - * todo: re-arrange global variables to put something else into CCM so that this can go into main - * so that this could be mergeed into Engine - * todo: move these fields into Engine class, eliminate this class - */ -class engine_configuration2_s { -public: - engine_configuration2_s(); - -#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) - /** - * Lock-free multithreading: two instances, while one is being modified another one is used read-only - */ - FuelSchedule injectionEvents0; - /** - * this points at an instance we use to run the engine - */ - FuelSchedule *injectionEvents; -#endif - - - float fsioLastValue[LE_COMMAND_COUNT]; - -}; - class ThermistorMath { public: ThermistorMath(); @@ -249,15 +221,13 @@ public: IgnitionEventList ignitionEvents; - WallFuel wallFuel; +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) + FuelSchedule injectionEvents; +#endif /* EFI_ENGINE_CONTROL */ - /** - * 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; + float fsioLastValue[LE_COMMAND_COUNT]; + + WallFuel wallFuel; /** * That's the list of pending spark firing events @@ -279,7 +249,6 @@ public: RpmCalculator rpmCalculator; persistent_config_s *config; engine_configuration_s *engineConfiguration; - engine_configuration2_s *engineConfiguration2; /** * this is about 'stopengine' command diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 63096cf9da..cae6296827 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -1004,18 +1004,12 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN #endif } -engine_configuration2_s::engine_configuration2_s() { - injectionEvents = &injectionEvents0; -} - void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S) { #if EFI_PROD_CODE || defined(__DOXYGEN__) efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "apply c"); scheduleMsg(logger, "applyNonPersistentConfiguration()"); #endif -// todo: this would require 'initThermistors() to re-establish a reference, todo: fix -// memset(engineConfiguration2, 0, sizeof(engine_configuration2_s)); #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) engine->triggerShape.initializeTriggerShape(logger PASS_ENGINE_PARAMETER); #endif @@ -1032,10 +1026,9 @@ void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) void prepareShapes(DECLARE_ENGINE_PARAMETER_F) { - engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; prepareOutputSignals(PASS_ENGINE_PARAMETER_F); - engineConfiguration2->injectionEvents->addFuelEvents(PASS_ENGINE_PARAMETER_F); + engine->injectionEvents.addFuelEvents(PASS_ENGINE_PARAMETER_F); } #endif diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index deaf0d91de..25d8cf7975 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -245,9 +245,9 @@ static void handleFsio(Engine *engine, int index) { warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioPins[index])); fvalue = NAN; } else { - fvalue = calc.getValue2(engine->engineConfiguration2->fsioLastValue[index], fsioLogics[index], engine); + fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index], engine); } - engine->engineConfiguration2->fsioLastValue[index] = fvalue; + engine->fsioLastValue[index] = fvalue; if (isPwmMode) { fsioPwm[index].setSimplePwmDutyCycle(fvalue); @@ -378,7 +378,7 @@ static void showFsioInfo(void) { */ scheduleMsg(logger, "FSIO #%d [%s] at %s@%dHz value=%f", (i + 1), exp, hwPortname(boardConfiguration->fsioPins[i]), boardConfiguration->fsioFrequency[i], - engineConfiguration2->fsioLastValue[i]); + engine->fsioLastValue[i]); // scheduleMsg(logger, "user-defined #%d value=%f", i, engine->engineConfiguration2->fsioLastValue[i]); showFsio(NULL, fsioLogics[i]); } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 1ab71c67e3..bd54f6500d 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -90,11 +90,6 @@ static virtual_timer_t periodicFastTimer; static LoggingWithStorage logger("Engine Controller"); -#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) -static engine_configuration2_s ec2 CCM_OPTIONAL; -engine_configuration2_s * engineConfiguration2 = &ec2; -#endif /* EFI_ENGINE_CONTROL */ - #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) /** diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 7fe158c38a..1525ea7cf4 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -99,7 +99,6 @@ FuelSchedule::FuelSchedule() { void FuelSchedule::clear() { isReady = false; - usedAtEngineCycle = 0; } void FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_S) { @@ -419,8 +418,6 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { getIgnition_mode_e(engineConfiguration->ignitionMode)); #endif - engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; - for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); diff --git a/firmware/controllers/sensors/thermistors.cpp b/firmware/controllers/sensors/thermistors.cpp index e71c4da6ad..fe9b9b0167 100644 --- a/firmware/controllers/sensors/thermistors.cpp +++ b/firmware/controllers/sensors/thermistors.cpp @@ -222,7 +222,6 @@ static void testCltByR(float resistance) { void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { logger = sharedLogger; efiAssertVoid(engine!=NULL, "e NULL initThermistors"); - efiAssertVoid(engine->engineConfiguration2!=NULL, "e2 NULL initThermistors"); #if EFI_PROD_CODE addConsoleActionF("test_clt_by_r", testCltByR); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 28128f79e5..b638f41cb1 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -75,7 +75,6 @@ void printSpiState(Logging *logger, board_configuration_s *boardConfiguration) { extern board_configuration_s *boardConfiguration; static void printOutputs(engine_configuration_s *engineConfiguration) { - // engine_configuration2_s *engineConfiguration2 scheduleMsg(&logger, "injectionPins: mode %s", getPin_output_mode_e(boardConfiguration->injectionPinMode)); for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { brain_pin_e brainPin = boardConfiguration->injectionPins[i]; diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index d8e8159c39..725194ca59 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -88,12 +88,11 @@ static void endSimultaniousInjection(InjectionEvent *event) { #if EFI_UNIT_TEST || defined(__DOXYGEN__) Engine *engine = event->engine; EXPAND_Engine; - engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; #endif for (int i = 0; i < engine->engineConfiguration->specs.cylindersCount; i++) { turnPinLow(&enginePins.injectors[i]); } - engineConfiguration2->injectionEvents->addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER); + engine->injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER); } static void tempTurnPinHigh(InjectorOutputPin *output) { @@ -189,9 +188,8 @@ void seTurnPinLow(OutputSignalPair *pair) { #if EFI_UNIT_TEST || defined(__DOXYGEN__) Engine *engine = pair->event->engine; EXPAND_Engine; - engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; #endif - engineConfiguration2->injectionEvents->addFuelEventsForCylinder(pair->event->ownIndex PASS_ENGINE_PARAMETER); + engine->injectionEvents.addFuelEventsForCylinder(pair->event->ownIndex PASS_ENGINE_PARAMETER); } static void seScheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, OutputSignalPair *pair) { @@ -384,7 +382,7 @@ static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIn * Ignition events are defined by addFuelEvents() according to selected * fueling strategy */ - FuelSchedule *fs = engine->fuelScheduleForThisEngineCycle; + FuelSchedule *fs = &engine->injectionEvents; if (!fs->isReady) { fs->addFuelEvents(PASS_ENGINE_PARAMETER_F); } @@ -484,13 +482,10 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D int revolutionIndex = ENGINE(rpmCalculator).getRevolutionCounter() % 2; if (trgEventIndex == 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()) { engine->ignitionEvents.isReady = false; // we need to rebuild ignition schedule - engine->fuelScheduleForThisEngineCycle->isReady = false; + engine->injectionEvents.isReady = false; // todo: move 'triggerIndexByAngle' change into trigger initialization, why is it invoked from here if it's only about trigger shape & optimization? prepareOutputSignals(PASS_ENGINE_PARAMETER_F); // we need this to apply new 'triggerIndexByAngle' values diff --git a/firmware/global.h b/firmware/global.h index 6a76eac9ec..e857814d98 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -92,7 +92,6 @@ typedef VirtualTimer virtual_timer_t; extern persistent_config_container_s persistentState; \ extern Engine _engine; \ extern persistent_config_s *config; \ - extern engine_configuration2_s * engineConfiguration2; \ extern EnginePins enginePins #define DECLARE_ENGINE_PARAMETER_F void diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index bef1a3e6e8..0ec60ab9d5 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -183,11 +183,6 @@ void runRusEfi(void) { msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0); -#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) - engine->engineConfiguration2 = engineConfiguration2; -#endif - - prepareVoidConfiguration(&activeConfiguration); /** diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index c1824632c2..cd398f33a7 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -44,9 +44,6 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste setTableValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 60, 1.03); setTableValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 70, 1.01); - - engine.engineConfiguration2 = &ec2; - Engine *engine = &this->engine; prepareFuelMap(PASS_ENGINE_PARAMETER_F); diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index c34de9ae6e..7195bdb88a 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -22,12 +22,10 @@ public: void fireTriggerEvents2(int count, int duration); persistent_config_s persistentConfig; - engine_configuration2_s ec2; Engine engine; engine_configuration_s *ec; engine_configuration_s *engineConfiguration; - }; #endif /* ENGINE_TEST_HELPER_H_ */ diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index c856c4c1aa..2c8d3e31de 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -166,7 +166,7 @@ void testAngleResolver(void) { EXPAND_EngineTestHelper; engineConfiguration->globalTriggerAngleOffset = 175; - assertTrue(engine->engineConfiguration2!=NULL); + TriggerShape * ts = &engine->triggerShape; ts->initializeTriggerShape(NULL PASS_ENGINE_PARAMETER); diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index fa433c5de7..4df79369c4 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -345,7 +345,7 @@ void testRpmCalculator(void) { eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); assertEqualsM("fuel #1", 4.5450, eth.engine.fuelMs); - InjectionEvent *ie0 = ð.engine.engineConfiguration2->injectionEvents->elements[0]; + InjectionEvent *ie0 = ð.engine.injectionEvents.elements[0]; assertEqualsM("injection angle", 31.365, ie0->injectionStart.angleOffset); eth.engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_RISING PASS_ENGINE_PARAMETER); @@ -662,7 +662,7 @@ static void setTestBug299(EngineTestHelper *eth) { assertInjectorDownEvent("1@3", 3, MS2US(20), 1); assertEqualsM("exec#0", 0, schedulingQueue.executeAll(timeNow)); - FuelSchedule * t = ENGINE(engineConfiguration2)->injectionEvents; + FuelSchedule * t = &ENGINE(injectionEvents); assertInjectionEvent("#0", &t->elements[0], 0, 1, 153, false); assertInjectionEvent("#1_i_@", &t->elements[1], 1, 1, 333, false); @@ -833,7 +833,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); - t = ENGINE(engineConfiguration2)->injectionEvents; + t = &ENGINE(injectionEvents); assertInjectionEvent("#0", &t->elements[0], 0, 0, 315, false); assertInjectionEvent("#1__", &t->elements[1], 1, 1, 135, false); @@ -921,15 +921,13 @@ void testFuelSchedulerBug299smallAndMedium(void) { timeNow += MS2US(20); assertEqualsM("executeAll#4", 4, schedulingQueue.executeAll(timeNow)); - - t = ENGINE(engineConfiguration2)->injectionEvents; + t = &ENGINE(injectionEvents); assertInjectionEvent("#0#", &t->elements[0], 0, 0, 315, false); assertInjectionEvent("#1#", &t->elements[1], 1, 1, 135, false); assertInjectionEvent("#2#", &t->elements[2], 0, 1, 315, true); assertInjectionEvent("#3#", &t->elements[3], 1, 0, 45 + 90, false); - setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 35); setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 35); engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); @@ -973,7 +971,7 @@ void testFuelSchedulerBug299smallAndMedium(void) { engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); - t = ENGINE(engineConfiguration2)->injectionEvents; + t = &ENGINE(injectionEvents); assertInjectionEvent("#00", &t->elements[0], 0, 0, 225, false); // 87.5 duty cycle assertInjectionEvent("#10", &t->elements[1], 1, 1, 45, false); diff --git a/win32_functional_tests/simulator/global.h b/win32_functional_tests/simulator/global.h index db2fa294e6..70e96e5700 100644 --- a/win32_functional_tests/simulator/global.h +++ b/win32_functional_tests/simulator/global.h @@ -102,7 +102,6 @@ void applyNewConfiguration(void); extern board_configuration_s *boardConfiguration; \ extern persistent_config_s *config; \ extern persistent_config_container_s persistentState; \ - extern engine_configuration2_s * engineConfiguration2; \ extern EnginePins enginePins #define DECLARE_ENGINE_PARAMETER_F void diff --git a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp index 0cc514eb01..f08d39a9cb 100644 --- a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp +++ b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp @@ -34,7 +34,6 @@ #define DEFAULT_SNIFFER_THR 2500 EXTERN_ENGINE; -extern engine_configuration2_s * engineConfiguration2; extern WaveChart waveChart; @@ -66,7 +65,6 @@ void rusEfiFunctionalTest(void) { initStatusLoop(engine); initDataStructures(PASS_ENGINE_PARAMETER_F); - engine->engineConfiguration2 = engineConfiguration2; // todo: reduce code duplication with initEngineContoller