From 8ebb83b92a08e5395758acb1d73d68d11755ff36 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Fri, 27 Feb 2015 18:09:09 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/algo.cpp | 2 +- firmware/controllers/algo/engine.cpp | 1 + firmware/controllers/algo/engine.h | 1 + firmware/controllers/engine_controller.cpp | 2 + firmware/controllers/math/engine_math.cpp | 2 +- firmware/controllers/math/speed_density.cpp | 3 +- firmware/controllers/math/speed_density.h | 2 +- firmware/controllers/sensors/map.cpp | 4 +- .../controllers/trigger/trigger_structure.cpp | 2 +- .../controllers/trigger/trigger_structure.h | 2 +- firmware/global.h | 1 + unit_tests/engine_test_helper.cpp | 10 +++-- unit_tests/engine_test_helper.h | 2 + unit_tests/global.h | 8 ++-- unit_tests/test_fuel_map.cpp | 5 ++- unit_tests/test_idle_controller.cpp | 1 + unit_tests/test_speed_density.cpp | 1 + unit_tests/test_trigger_decoder.cpp | 37 ++++++++++++------- win32_functional_tests/simulator/global.h | 1 + 19 files changed, 56 insertions(+), 31 deletions(-) diff --git a/firmware/controllers/algo/algo.cpp b/firmware/controllers/algo/algo.cpp index a723cdff0c..a99c7f862f 100644 --- a/firmware/controllers/algo/algo.cpp +++ b/firmware/controllers/algo/algo.cpp @@ -32,7 +32,7 @@ EXTERN_ENGINE; void initDataStructures(DECLARE_ENGINE_PARAMETER_F) { prepareFuelMap(engineConfiguration); prepareTimingMap(PASS_ENGINE_PARAMETER_F); - initSpeedDensity(engineConfiguration); + initSpeedDensity(config); } void initAlgo(Logging *sharedLogger, engine_configuration_s *engineConfiguration) { diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 87d9deb034..b17b403c9c 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -62,6 +62,7 @@ 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; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 80fb3ad898..b8dea7c37b 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -121,6 +121,7 @@ public: Engine(persistent_config_s *config); void init(); RpmCalculator rpmCalculator; + persistent_config_s *config; engine_configuration_s *engineConfiguration; engine_configuration2_s *engineConfiguration2; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 1e13171092..56b2400c4a 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -66,6 +66,8 @@ extern bool hasFirmwareErrorFlag; persistent_config_container_s persistentState CCM_OPTIONAL; +persistent_config_s *config; + /** * todo: it really looks like these fields should become 'static', i.e. private * the whole 'extern ...' pattern is less then perfect, I guess the 'God object' Engine diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 49ce26f900..e15a6dfc08 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -345,7 +345,7 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; // todo: move this reset into decoder - engine->triggerShape.calculateTriggerSynchPoint(engineConfiguration, engine); + engine->triggerShape.calculateTriggerSynchPoint(PASS_ENGINE_PARAMETER_F); for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { ENGINE(angleExtra[i])= (float) CONFIG(engineCycle) * i / CONFIG(specs.cylindersCount); diff --git a/firmware/controllers/math/speed_density.cpp b/firmware/controllers/math/speed_density.cpp index 94fdcbcca5..3eedc2abe8 100644 --- a/firmware/controllers/math/speed_density.cpp +++ b/firmware/controllers/math/speed_density.cpp @@ -106,7 +106,8 @@ void setDetaultVETable(engine_configuration_s *engineConfiguration) { afrMap.setAll(14.7); } -void initSpeedDensity(engine_configuration_s *e) { +void initSpeedDensity(persistent_config_s *config) { + engine_configuration_s *e = &config->engineConfiguration; veMap.init(e->veTable, e->veLoadBins, e->veRpmBins); ve2Map.init(e->ve2Table, e->ve2LoadBins, e->ve2RpmBins); afrMap.init(e->afrTable, e->afrLoadBins, e->afrRpmBins); diff --git a/firmware/controllers/math/speed_density.h b/firmware/controllers/math/speed_density.h index d1a33b261c..a591a10c58 100644 --- a/firmware/controllers/math/speed_density.h +++ b/firmware/controllers/math/speed_density.h @@ -18,7 +18,7 @@ float sdMath(engine_configuration_s *engineConfiguration, float VE, float MAP, f #define cc_minute_to_gramm_second(ccm) ((ccm) * 0.0119997981) void setDetaultVETable(engine_configuration_s *engineConfiguration); -void initSpeedDensity(engine_configuration_s *engineConfiguration); +void initSpeedDensity(persistent_config_s *config); float getSpeedDensityFuel(int rpm DECLARE_ENGINE_PARAMETER_S); #endif /* SPEED_DENSITY_H_ */ diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index 6dc791c369..e60e3aba83 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -100,8 +100,8 @@ static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) { } static void applyConfiguration(DECLARE_ENGINE_PARAMETER_F) { - air_pressure_sensor_config_s * config = &engineConfiguration->map.sensor; - customMap.init(0, config->valueAt0, 5, config->valueAt5); + air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor; + customMap.init(0, apConfig->valueAt0, 5, apConfig->valueAt5); mapDecoder = getDecoder(engineConfiguration->map.sensor.type); } diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 8577c502ac..69c3759fe5 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -53,7 +53,7 @@ int TriggerShape::getTriggerShapeSynchPointIndex() { return triggerShapeSynchPointIndex; } -void TriggerShape::calculateTriggerSynchPoint(engine_configuration_s *engineConfiguration, Engine *engine) { +void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) { trigger_config_s const*triggerConfig = &engineConfiguration->trigger; setTriggerShapeSynchPointIndex(engineConfiguration, findTriggerZeroEventIndex(this, triggerConfig PASS_ENGINE_PARAMETER), engine); } diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 7656751add..ac3b09294b 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -103,7 +103,7 @@ public: int getTriggerShapeSynchPointIndex(); - void calculateTriggerSynchPoint(engine_configuration_s *engineConfiguration, Engine *engine); + void calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F); void setTriggerShapeSynchPointIndex(engine_configuration_s *engineConfiguration, int triggerShapeSynchPointIndex, Engine *engine); private: diff --git a/firmware/global.h b/firmware/global.h index c3af2b0c24..2b0ff529eb 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -81,6 +81,7 @@ typedef Thread thread_t; extern board_configuration_s *boardConfiguration; \ extern persistent_config_container_s persistentState; \ extern Engine _engine; \ + extern persistent_config_s *config; \ extern engine_configuration2_s * engineConfiguration2 #define DECLARE_ENGINE_PARAMETER_F void diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 410e19a147..13ec516226 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -14,7 +14,8 @@ extern int timeNow; EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persistentConfig) { - ec = &persistentConfig.engineConfiguration; + engineConfiguration = ec = &persistentConfig.engineConfiguration; + config = &persistentConfig; engine_configuration_s *engineConfiguration = ec; @@ -38,7 +39,7 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste prepareFuelMap(engine->engineConfiguration); - initSpeedDensity(ec); + initSpeedDensity(&persistentConfig); resetConfigurationExt(NULL, engineType PASS_ENGINE_PARAMETER); prepareShapes(PASS_ENGINE_PARAMETER_F); @@ -46,11 +47,12 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persiste } void EngineTestHelper::fireTriggerEvents() { + Engine *engine = &this->engine; for (int i = 0; i < 24; i++) { timeNow += 5000; // 5ms - triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &engine, engine.engineConfiguration); + triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); timeNow += 5000; - triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &engine, engine.engineConfiguration); + triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); } } diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index 71baab0629..f06f469c3b 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -18,10 +18,12 @@ public: void fireTriggerEvents(); persistent_config_s persistentConfig; + persistent_config_s *config; engine_configuration2_s ec2; Engine engine; engine_configuration_s *ec; + engine_configuration_s *engineConfiguration; TriggerCentral triggerCentral; }; diff --git a/unit_tests/global.h b/unit_tests/global.h index 2d05846d53..9b6bdee11c 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -38,10 +38,10 @@ typedef int bool_t; class Engine; #endif -#define DECLARE_ENGINE_PARAMETER_F Engine *engine, engine_configuration_s *engineConfiguration -#define DECLARE_ENGINE_PARAMETER_S , Engine *engine, engine_configuration_s *engineConfiguration -#define PASS_ENGINE_PARAMETER_F engine, engineConfiguration -#define PASS_ENGINE_PARAMETER , engine, engineConfiguration +#define DECLARE_ENGINE_PARAMETER_F Engine *engine, engine_configuration_s *engineConfiguration, persistent_config_s *config +#define DECLARE_ENGINE_PARAMETER_S , Engine *engine, engine_configuration_s *engineConfiguration, persistent_config_s *config +#define PASS_ENGINE_PARAMETER_F engine, engineConfiguration, config +#define PASS_ENGINE_PARAMETER , engine, engineConfiguration, config #define CONFIG(x) engineConfiguration->x #define ENGINE(x) engine->x diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 7c7a2f8538..4fcfa01503 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -24,6 +24,7 @@ void testMafFuelMath(void) { Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = engine->engineConfiguration; + persistent_config_s *config = engine->config; engineConfiguration->algorithm = LM_REAL_MAF; @@ -58,6 +59,7 @@ void testFuelMap(void) { Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = engine->engineConfiguration; + persistent_config_s *config = engine->config; initThermistors(NULL PASS_ENGINE_PARAMETER); @@ -174,6 +176,7 @@ void testAngleResolver(void) { Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration; + persistent_config_s *config = engine->config; engineConfiguration->globalTriggerAngleOffset = 175; assertTrue(engine->engineConfiguration2!=NULL); @@ -181,7 +184,7 @@ void testAngleResolver(void) { confgiureFordAspireTriggerShape(ts); - ts->calculateTriggerSynchPoint(engineConfiguration, engine); + ts->calculateTriggerSynchPoint(PASS_ENGINE_PARAMETER_F); assertEqualsM("index 2", 228.0450, ts->eventAngles[3]); // this angle is relation to synch point assertEqualsM("time 2", 0.3233, ts->wave.getSwitchTime(2)); diff --git a/unit_tests/test_idle_controller.cpp b/unit_tests/test_idle_controller.cpp index e1e46e073d..afdd210b86 100644 --- a/unit_tests/test_idle_controller.cpp +++ b/unit_tests/test_idle_controller.cpp @@ -20,6 +20,7 @@ void testIdleController(void) { EngineTestHelper eth(FORD_INLINE_6_1995); Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = engine->engineConfiguration; + persistent_config_s *config = engine->config; engineConfiguration->targetIdleRpm = 1200; diff --git a/unit_tests/test_speed_density.cpp b/unit_tests/test_speed_density.cpp index 86695c0eaf..7bc3f786d5 100644 --- a/unit_tests/test_speed_density.cpp +++ b/unit_tests/test_speed_density.cpp @@ -15,6 +15,7 @@ void testSpeedDensity(void) { EngineTestHelper eth(FORD_INLINE_6_1995); Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = engine->engineConfiguration; + persistent_config_s *config = engine->config; eth.ec->trigger.customTotalToothCount = 8; eth.initTriggerShapeAndRpmCalculator(); diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index ff6b09bf9e..83a67c7ade 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -46,6 +46,8 @@ int getTheAngle(engine_type_e engineType) { Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = eth.ec; + persistent_config_s *config = engine->config; + initDataStructures(PASS_ENGINE_PARAMETER_F); TriggerShape * shape = ð.engine.triggerShape; @@ -119,6 +121,7 @@ static void test1995FordInline6TriggerDecoder(void) { engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration; Engine *engine = ð.engine; + persistent_config_s *config = engine->config; TriggerShape * shape = ð.engine.triggerShape; @@ -184,6 +187,7 @@ void testFordAspire(void) { Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = eth.ec; + persistent_config_s *config = eth.config; assertEquals(4, eth.engine.triggerShape.getTriggerShapeSynchPointIndex()); assertEquals(800, engineConfiguration->fuelRpmBins[0]); @@ -211,6 +215,8 @@ void testMazdaMianaNbDecoder(void) { EngineTestHelper eth(MAZDA_MIATA_NB); engine_configuration_s *ec = eth.ec; Engine *engine = ð.engine; + persistent_config_s *config = eth.config; + engine_configuration_s *engineConfiguration = ec; TriggerShape * shape = ð.engine.triggerShape; assertEquals(11, shape->getTriggerShapeSynchPointIndex()); @@ -295,8 +301,9 @@ static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPo EngineTestHelper eth(type); engine_configuration_s *ec = eth.ec; + persistent_config_s *config = eth.config; - initSpeedDensity(ec); + initSpeedDensity(config); TriggerShape *t = ð.engine.triggerShape; @@ -324,6 +331,7 @@ static void testStartupFuelPumping(void) { Engine * engine = ð.engine; engine_configuration_s *engineConfiguration = engine->engineConfiguration; + persistent_config_s *config = engine->config; engine->rpmCalculator.mockRpm = 0; @@ -370,6 +378,7 @@ static void testRpmCalculator(void) { efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine"); Engine *engine = ð.engine; + persistent_config_s *config = eth.config; engine_configuration_s *engineConfiguration = ð.persistentConfig.engineConfiguration; initThermistors(NULL PASS_ENGINE_PARAMETER); @@ -399,7 +408,7 @@ static void testRpmCalculator(void) { prepareTimingMap(PASS_ENGINE_PARAMETER_F); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("index #2", 0, eth.triggerCentral.triggerState.getCurrentIndex()); assertEqualsM("queue size", 6, schedulingQueue.size()); assertEqualsM("ev 1", 246444, schedulingQueue.getForUnitText(0)->momentX); @@ -407,11 +416,11 @@ static void testRpmCalculator(void) { schedulingQueue.clear(); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("index #3", 3, eth.triggerCentral.triggerState.getCurrentIndex()); assertEqualsM("queue size 3", 6, schedulingQueue.size()); assertEqualsM("ev 3", 259777, schedulingQueue.getForUnitText(0)->momentX); @@ -421,24 +430,24 @@ static void testRpmCalculator(void) { schedulingQueue.clear(); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("index #4", 6, eth.triggerCentral.triggerState.getCurrentIndex()); assertEqualsM("queue size 4", 6, schedulingQueue.size()); assertEqualsM("4/0", 273111, schedulingQueue.getForUnitText(0)->momentX); schedulingQueue.clear(); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("queue size 5", 0, schedulingQueue.size()); // assertEqualsM("5/1", 284500, schedulingQueue.getForUnitText(0)->momentUs); schedulingQueue.clear(); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("queue size 6", 6, schedulingQueue.size()); assertEqualsM("6/0", 286444, schedulingQueue.getForUnitText(0)->momentX); assertEqualsM("6/1", 285944, schedulingQueue.getForUnitText(1)->momentX); @@ -446,12 +455,12 @@ static void testRpmCalculator(void) { schedulingQueue.clear(); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("queue size 7", 0, schedulingQueue.size()); schedulingQueue.clear(); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("queue size 8", 6, schedulingQueue.size()); assertEqualsM("8/0", 299777, schedulingQueue.getForUnitText(0)->momentX); assertEqualsM("8/1", 299277, schedulingQueue.getForUnitText(1)->momentX); @@ -460,12 +469,12 @@ static void testRpmCalculator(void) { schedulingQueue.clear(); timeNow += 5000; - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN PASS_ENGINE_PARAMETER); assertEqualsM("queue size 9", 0, schedulingQueue.size()); schedulingQueue.clear(); timeNow += 5000; // 5ms - eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, ð.engine, eth.ec); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); assertEqualsM("queue size 10", 0, schedulingQueue.size()); schedulingQueue.clear(); } diff --git a/win32_functional_tests/simulator/global.h b/win32_functional_tests/simulator/global.h index 285cfebecd..af7b669b7d 100644 --- a/win32_functional_tests/simulator/global.h +++ b/win32_functional_tests/simulator/global.h @@ -87,6 +87,7 @@ typedef EventListener event_listener_t; #define EXTERN_ENGINE extern Engine *engine; \ extern engine_configuration_s *engineConfiguration; \ extern board_configuration_s *boardConfiguration; \ + extern persistent_config_s *config; \ extern persistent_config_container_s persistentState #define DECLARE_ENGINE_PARAMETER_F void