diff --git a/firmware/config/engines/sachs.cpp b/firmware/config/engines/sachs.cpp index 0cfd4f1dc4..604d31174f 100644 --- a/firmware/config/engines/sachs.cpp +++ b/firmware/config/engines/sachs.cpp @@ -17,7 +17,6 @@ EXTERN_ENGINE; void setSachs(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->specs.displacement = 0.1; // 100cc engineConfiguration->specs.cylindersCount = 1; - engineConfiguration->engineCycleDuration = 360; setOperationMode(engineConfiguration, TWO_STROKE); engineConfiguration->specs.firingOrder = FO_ONE_CYLINDER; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index ff308b6175..be9a2795fc 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -69,6 +69,10 @@ void Engine::addConfigurationListener(configuration_callback_t callback) { } Engine::Engine(persistent_config_s *config) { + /** + * it's important for fixAngle() that engineCycle field never has zero + */ + engineCycle = getEngineCycle(FOUR_STROKE_CRANK_SENSOR); lastTriggerEventTimeNt = 0; isCylinderCleanupMode = false; engineCycleEventCount = 0; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 5f3403d8e5..312f0ade2b 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -209,6 +209,8 @@ public: */ efitick_t stopEngineRequestTimeNt; + angle_t engineCycle; + AccelEnrichmemnt engineLoadAccelEnrichment; AccelEnrichmemnt tpsAccelEnrichment; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 2af7df2c53..2d53e3ec66 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -533,8 +533,6 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->engineChartSize = 400; #endif - engineConfiguration->engineCycleDuration = 720; - engineConfiguration->primingSquirtDurationMs = 5; engineConfiguration->isInjectionEnabled = true; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index c79139731b..11377b39dd 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 07 13:56:04 EST 2016 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 14 23:21:45 EST 2016 // begin #include "rusefi_types.h" typedef struct { @@ -852,13 +852,9 @@ typedef struct { */ float cylinderBore; /** - * todo:see getEngineCycle(operation_mode_e operationMode) eliminate this? - * todo:operationMode should be enough - * 360 for two-stroke - * 720 for four-stroke * offset 416 */ - int engineCycleDuration; + int unused34234; /** * offset 420 */ @@ -1612,4 +1608,4 @@ typedef struct { } persistent_config_s; // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 07 13:56:04 EST 2016 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 14 23:21:45 EST 2016 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 711eb8349f..9dac8f5e66 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -127,7 +127,7 @@ #define firingOrder_offset 408 #define firingOrder_offset_hex 198 #define cylinderBore_offset 412 -#define engineCycleDuration_offset 416 +#define unused34234_offset 416 #define rpmHardLimit_offset 420 #define algorithm_offset 424 #define crankingInjectionMode_offset 428 diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index ee97f437f3..4024cbc623 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -169,7 +169,7 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_ * injection phase is scheduled by injection end, so we need to step the angle back * for the duration of the injection */ - float baseAngle = ENGINE(engineState.injectionOffset) + angle_t baseAngle = ENGINE(engineState.injectionOffset) + CONFIG(injectionOffset) - MS2US(ENGINE(fuelMs)) / ENGINE(rpmCalculator.oneDegreeUs); switch (mode) { @@ -177,14 +177,14 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_ for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { int index = getCylinderId(engineConfiguration->specs.firingOrder, i) - 1; float angle = baseAngle - + (float) CONFIG(engineCycleDuration) * i / CONFIG(specs.cylindersCount); + + ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); registerInjectionEvent(index, angle, false PASS_ENGINE_PARAMETER); } break; case IM_SIMULTANEOUS: for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { float angle = baseAngle - + (float) CONFIG(engineCycleDuration) * i / CONFIG(specs.cylindersCount); + + ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); /** * We do not need injector pin here because we will control all injectors @@ -197,7 +197,7 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_ for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { int index = i % (engineConfiguration->specs.cylindersCount / 2); float angle = baseAngle - + i * (float) CONFIG(engineCycleDuration) / CONFIG(specs.cylindersCount); + + i * ENGINE(engineCycle) / CONFIG(specs.cylindersCount); registerInjectionEvent(index, angle, false PASS_ENGINE_PARAMETER); if (CONFIG(twoWireBatchInjection)) { @@ -368,22 +368,23 @@ static NamedOutputPin * getIgnitionPinForIndex(int i DECLARE_ENGINE_PARAMETER_S #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) -int is700 = 0; +/** + * This heavy method is only invoked in case of a configuration change or initialization. + */ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { + ENGINE(engineCycle) = getEngineCycle(CONFIG(operationMode)); engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - ENGINE(angleExtra[i])= (float) CONFIG(engineCycleDuration) * i / CONFIG(specs.cylindersCount); + ENGINE(angleExtra[i])= ENGINE(engineCycle) * i / CONFIG(specs.cylindersCount); ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER); } - for (int angle = 0; angle < CONFIG(engineCycleDuration); angle++) { - if (angle==700) { - is700++; - } + int engineCycleInt = (int) ENGINE(engineCycle); + for (int angle = 0; angle < engineCycleInt; angle++) { int triggerShapeIndex = findAngleIndex(angle PASS_ENGINE_PARAMETER); if (engineConfiguration->useOnlyFrontForTrigger) triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; // we need even index for front_only diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index a1cdf704e3..705c6cf5d8 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -29,18 +29,15 @@ void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, * I guess this implementation would be faster than 'angle % engineCycle' */ #define fixAngle(angle) \ - { \ - float engineCycleDurationLocalCopy = CONFIG(engineCycleDuration); \ - /* \ - * could be zero if the middle of setDefaultConfiguration \ - * todo: anything else should be done to handle this condition? \ - */ \ - if (engineCycleDurationLocalCopy != 0) { \ - while (angle < 0) \ - angle += engineCycleDurationLocalCopy; \ - while (angle >= engineCycleDurationLocalCopy) \ - angle -= engineCycleDurationLocalCopy; \ - } \ + { \ + float engineCycleDurationLocalCopy = ENGINE(engineCycle); \ + /* todo: split this method into 'fixAngleUp' and 'fixAngleDown'*/ \ + /* as a performance optimization?*/ \ + while (angle < 0) \ + angle += engineCycleDurationLocalCopy; \ + /* todo: would 'if' work as good as 'while'? */ \ + while (angle >= engineCycleDurationLocalCopy) \ + angle -= engineCycleDurationLocalCopy; \ } /** diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index d8dcee99c7..959133b5c0 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -248,7 +248,6 @@ void printAllTriggers() { engine_configuration_s *engineConfiguration = &pc.engineConfiguration; board_configuration_s *boardConfiguration = &engineConfiguration->bc; - engineConfiguration->engineCycleDuration = 720; engineConfiguration->trigger.type = tt; engineConfiguration->operationMode = FOUR_STROKE_CAM_SENSOR; diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index a356829067..abc1be1487 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -332,7 +332,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no } } -float getEngineCycle(operation_mode_e operationMode) { +angle_t getEngineCycle(operation_mode_e operationMode) { return operationMode == TWO_STROKE ? 360 : 720; } diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index cbee70ea8c..d76cc0ec07 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -107,7 +107,7 @@ private: efitick_t startOfCycleNt; }; -float getEngineCycle(operation_mode_e operationMode); +angle_t getEngineCycle(operation_mode_e operationMode); void addSkippedToothTriggerEvents(trigger_wheel_e wheel, TriggerShape *s, int totalTeethCount, int skippedCount, float toothWidth, diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 78a0285abd..94db1e954f 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -188,8 +188,7 @@ end_struct specs_s specs float cylinderBore;Cylinder diameter, in mm. -int engineCycleDuration;todo:see getEngineCycle(operation_mode_e operationMode) eliminate this?\ntodo:operationMode should be enough\n360 for two-stroke\n720 for four-stroke;"engine cycle", 1, 0, 0, 1000, 0 - +int unused34234; int rpmHardLimit;;"rpm", 1, 0, 0, 20000.0, 2 diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index b9d50f7390..fc68ed87ae 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160104; + return 20160114; } diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index d64426a29a..81f38d5796 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -41,7 +41,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 07 13:56:04 EST 2016 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jan 14 23:21:45 EST 2016 pageSize = 16088 page = 1 @@ -96,7 +96,7 @@ page = 1 cylindersCount = bits, U32, 404, [0:3], "INVALID", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, "INVALID", "INVALID", "INVALID" firingOrder = bits, U32, 408, [0:3], "One Cylinder", "1-3-4-2", "1-2-4-3", "1-3-2-4", "1-5-3-6-2-4", "1-8-4-3-6-5-7-2", "1-5-3-6-2-4", "1-4-2-5-3-6", "1-2", "1_2_3_4_5_6", "1-2-3", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" ;skipping cylinderBore offset 412 - engineCycleDuration = scalar, S32, 416, "engine cycle", 1, 0, 0, 1000, 0 +;skipping unused34234 offset 416 rpmHardLimit = scalar, S32, 420, "rpm", 1, 0, 0, 20000.0, 2 algorithm = bits, U32, 424, [0:1], "MAF", "Alpha-N/TPS", "MAP", "SPEED DENSITY" crankingInjectionMode = bits, U32, 428, [0:1], "Simultaneous", "Sequential", "Batch", "INVALID" @@ -1137,7 +1137,6 @@ fileVersion = { 20151201 } field = "Injector Open Time", injector_lag field = "Injector Flow", injector_flow field = "phase offset", injectionOffset - field = "Engine Cycle", engineCycleDuration dialog = injIO, "Injector Output", yAxis field = "injection Pin Mode", injectionPinMode diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index ecc5038e50..22b8a28f6d 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -283,8 +283,7 @@ static void testRpmCalculator(void) { IgnitionEventList *ilist = ð.engine.engineConfiguration2->ignitionEvents[0]; assertEqualsM("size", 6, ilist->size); - assertEquals(720, eth.engine.engineConfiguration->engineCycleDuration); - assertEquals(720, eth.ec->engineCycleDuration); + assertEqualsM("engineCycle", 720, eth.engine.engineCycle); efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine");