From d8b9ad9fa99b540e0938d1d5853bb6573f04739a Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 24 Nov 2014 14:06:11 -0600 Subject: [PATCH] auto-sync --- .../controllers/algo/engine_configuration.cpp | 2 +- firmware/controllers/math/engine_math.cpp | 10 ++---- .../controllers/trigger/trigger_decoder.cpp | 2 +- .../controllers/trigger/trigger_decoder.h | 5 ++- unit_tests/engine_test_helper.cpp | 2 +- unit_tests/test_fuel_map.cpp | 4 +-- unit_tests/test_trigger_decoder.cpp | 35 +++++++++++-------- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index db7f869517..d67e54c4eb 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -585,7 +585,7 @@ void applyNonPersistentConfiguration(Logging * logger, Engine *engine) { #if EFI_PROD_CODE scheduleMsg(logger, "applyNonPersistentConfiguration()"); #endif - initializeTriggerShape(logger, engineConfiguration, engineConfiguration2); + initializeTriggerShape(logger, engineConfiguration, engineConfiguration2, engine); if (engineConfiguration2->triggerShape.getSize() == 0) { firmwareError("triggerShape size is zero"); return; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index aaf1c96a07..f1f658c11d 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -271,16 +271,12 @@ float getSparkDwellMsT(int rpm DECLARE_ENGINE_PARAMETER_S) { return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE); } -int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s) { - return mode == FOUR_STROKE_CAM_SENSOR ? s->getSize() : 2 * s->getSize(); -} - /** * Trigger event count equals engine cycle event count if we have a cam sensor. * Two trigger cycles make one engine cycle in case of a four stroke engine If we only have a cranksensor. */ -int getEngineCycleEventCount(engine_configuration_s const *engineConfiguration, trigger_shape_s * s) { - return getEngineCycleEventCount2(getOperationMode(engineConfiguration), s); +int getEngineCycleEventCount2(operation_mode_e mode, trigger_shape_s * s) { + return mode == FOUR_STROKE_CAM_SENSOR ? s->getSize() : 2 * s->getSize(); } void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position, @@ -288,7 +284,7 @@ void findTriggerPosition(trigger_shape_s * s, event_trigger_position_s *position angleOffset = fixAngle(angleOffset + engineConfiguration->globalTriggerAngleOffset PASS_ENGINE_PARAMETER); - int engineCycleEventCount = getEngineCycleEventCount(engineConfiguration, s); + int engineCycleEventCount = getEngineCycleEventCount2(getOperationMode(engineConfiguration), s); efiAssertVoid(engineCycleEventCount > 0, "engineCycleEventCount"); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index d837fd3d46..53f7fee0b4 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -220,7 +220,7 @@ void initializeSkippedToothTriggerShapeExt(trigger_shape_s *s, int totalTeethCou * External logger is needed because at this point our logger is not yet initialized */ void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration, - engine_configuration2_s *engineConfiguration2) { + engine_configuration2_s *engineConfiguration2, Engine *engine) { #if EFI_PROD_CODE scheduleMsg(logger, "initializeTriggerShape()"); #endif diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index bd49f69752..861abd9e82 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -88,7 +88,10 @@ private: void initializeSkippedToothTriggerShapeExt(trigger_shape_s *s, int totalTeethCount, int skippedCount, operation_mode_e operationMode); uint32_t findTriggerZeroEventIndex(trigger_shape_s * shape, trigger_config_s const*triggerConfig); -void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration, engine_configuration2_s *engineConfiguration2); + +class Engine; + +void initializeTriggerShape(Logging *logger, engine_configuration_s const *engineConfiguration, engine_configuration2_s *engineConfiguration2, Engine *engine); void initTriggerDecoder(void); bool_t isTriggerDecoderError(void); diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 99b6814501..35dbcf1f6f 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -40,7 +40,7 @@ void EngineTestHelper::fireTriggerEvents() { } void EngineTestHelper::initTriggerShapeAndRpmCalculator() { - initializeTriggerShape(NULL, ec, &ec2); + initializeTriggerShape(NULL, ec, &ec2, &engine); incrementGlobalConfigurationVersion(); triggerCentral.addEventListener((ShaftPositionListener) &rpmShaftPositionCallback, "rpm reporter", &engine); diff --git a/unit_tests/test_fuel_map.cpp b/unit_tests/test_fuel_map.cpp index 1d0e8efe6a..9c866e1100 100644 --- a/unit_tests/test_fuel_map.cpp +++ b/unit_tests/test_fuel_map.cpp @@ -178,14 +178,14 @@ void testAngleResolver(void) { ae.resetEventList(); printf("*************************************************** testAngleResolver 0\r\n"); - findTriggerPosition(&engineConfiguration2->triggerShape, &ae.getNextActuatorEvent()->position, 53 - 175 PASS_ENGINE_PARAMETER); + findTriggerPosition(ts, &ae.getNextActuatorEvent()->position, 53 - 175 PASS_ENGINE_PARAMETER); assertEqualsM("size", 1, ae.size); assertEquals(0, ae.events[0].position.eventIndex); assertEquals(53, ae.events[0].position.angleOffset); printf("*************************************************** testAngleResolver 2\r\n"); ae.resetEventList(); - findTriggerPosition(&engineConfiguration2->triggerShape, &ae.getNextActuatorEvent()->position, 51 + 180 - 175 PASS_ENGINE_PARAMETER); + findTriggerPosition(ts, &ae.getNextActuatorEvent()->position, 51 + 180 - 175 PASS_ENGINE_PARAMETER); assertEquals(2, ae.events[0].position.eventIndex); assertEquals(109.1, ae.events[0].position.angleOffset); } diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index bdaf4a7907..f3e36894a0 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -57,9 +57,9 @@ static void testDodgeNeonDecoder(void) { EngineTestHelper eth(DODGE_NEON_1995); engine_configuration_s *ec = eth.ec; - assertEquals(8, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex()); - trigger_shape_s * shape = ð.ec2.triggerShape; + assertEquals(8, shape->getTriggerShapeSynchPointIndex()); + TriggerState state; assertFalseM("1 shaft_is_synchronized", state.shaft_is_synchronized); @@ -116,9 +116,10 @@ static void test1995FordInline6TriggerDecoder(void) { engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration; Engine *engine = ð.engine; - assertEqualsM("triggerShapeSynchPointIndex", 0, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex()); - trigger_shape_s * shape = ð.ec2.triggerShape; + + assertEqualsM("triggerShapeSynchPointIndex", 0, shape->getTriggerShapeSynchPointIndex()); + event_trigger_position_s position; assertEqualsM("globalTriggerAngleOffset", 0, engineConfiguration->globalTriggerAngleOffset); findTriggerPosition(shape, &position, 0 PASS_ENGINE_PARAMETER); @@ -207,10 +208,10 @@ void testMazdaMianaNbDecoder(void) { engine_configuration_s *ec = eth.ec; Engine *engine = ð.engine; engine_configuration_s *engineConfiguration = ec; - assertEquals(11, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex()); + trigger_shape_s * shape = ð.ec2.triggerShape; + assertEquals(11, shape->getTriggerShapeSynchPointIndex()); TriggerState state; - trigger_shape_s * shape = ð.ec2.triggerShape; int a = 0; state.decodeTriggerEvent(shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 20); @@ -293,10 +294,12 @@ static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPo initSpeedDensity(ec); - assertEqualsM("synchPointIndex", synchPointIndex, eth.ec2.triggerShape.getTriggerShapeSynchPointIndex()); + trigger_shape_s *t = ð.ec2.triggerShape; - assertEqualsM("channel1duty", channel1duty, eth.ec2.triggerShape.dutyCycle[0]); - assertEqualsM("channel2duty", channel2duty, eth.ec2.triggerShape.dutyCycle[1]); + assertEqualsM("synchPointIndex", synchPointIndex, t->getTriggerShapeSynchPointIndex()); + + assertEqualsM("channel1duty", channel1duty, t->dutyCycle[0]); + assertEqualsM("channel2duty", channel2duty, t->dutyCycle[1]); } void testGY6_139QMB(void) { @@ -482,13 +485,15 @@ void testTriggerDecoder(void) { printf("*************************************************** testTriggerDecoder\r\n"); engine_configuration2_s ec2; + trigger_shape_s * s = &ec2.triggerShape; - initializeSkippedToothTriggerShapeExt(&ec2.triggerShape, 2, 0, FOUR_STROKE_CAM_SENSOR); - assertEqualsM("shape size", ec2.triggerShape.getSize(), 4); - assertEquals(ec2.triggerShape.wave.switchTimes[0], 0.25); - assertEquals(ec2.triggerShape.wave.switchTimes[1], 0.5); - assertEquals(ec2.triggerShape.wave.switchTimes[2], 0.75); - assertEquals(ec2.triggerShape.wave.switchTimes[3], 1); + + initializeSkippedToothTriggerShapeExt(s, 2, 0, FOUR_STROKE_CAM_SENSOR); + assertEqualsM("shape size", s->getSize(), 4); + assertEquals(s->wave.switchTimes[0], 0.25); + assertEquals(s->wave.switchTimes[1], 0.5); + assertEquals(s->wave.switchTimes[2], 0.75); + assertEquals(s->wave.switchTimes[3], 1); testDodgeNeonDecoder(); testTriggerDecoder2("dodge neon", DODGE_NEON_1995, 8, 0.4931, 0.2070);