diff --git a/firmware/config/engines/sachs.cpp b/firmware/config/engines/sachs.cpp index 8985ebc21d..38fe7e34f6 100644 --- a/firmware/config/engines/sachs.cpp +++ b/firmware/config/engines/sachs.cpp @@ -17,7 +17,7 @@ EXTERN_ENGINE; void setSachs(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->specs.displacement = 0.1; // 100cc engineConfiguration->specs.cylindersCount = 1; - engineConfiguration->engineCycle = 360; + engineConfiguration->engineCycleDuration = 360; setOperationMode(engineConfiguration, TWO_STROKE); engineConfiguration->specs.firingOrder = FO_ONE_CYLINDER; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 1051168285..0dc026c997 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -500,7 +500,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->engineChartSize = 400; #endif - engineConfiguration->engineCycle = 720; + engineConfiguration->engineCycleDuration = 720; engineConfiguration->primingSquirtDurationMs = 5; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 7b0ffd2fe4..d511931b8d 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 Wed Nov 11 21:47:19 EST 2015 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Nov 12 10:32:55 EST 2015 // begin #include "rusefi_types.h" typedef struct { @@ -859,7 +859,7 @@ typedef struct { * 720 for four-stroke * offset 416 */ - int engineCycle; + int engineCycleDuration; /** * offset 420 */ @@ -1571,4 +1571,4 @@ typedef struct { } persistent_config_s; // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Wed Nov 11 21:47:19 EST 2015 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Nov 12 10:32:55 EST 2015 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 8abd1de27c..19c3c458bf 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -126,7 +126,7 @@ #define firingOrder_offset 408 #define firingOrder_offset_hex 198 #define cylinderBore_offset 412 -#define engineCycle_offset 416 +#define engineCycleDuration_offset 416 #define rpmHardLimit_offset 420 #define algorithm_offset 424 #define crankingInjectionMode_offset 428 diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index dd4a21908f..6439e4838c 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -207,7 +207,7 @@ static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { angle_t offsetAngle = TRIGGER_SHAPE(eventAngles[CONFIG(mapAveragingSchedulingAtIndex)]); for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - angle_t cylinderOffset = engineConfiguration->engineCycle * i / engineConfiguration->specs.cylindersCount; + angle_t cylinderOffset = engineConfiguration->engineCycleDuration * i / engineConfiguration->specs.cylindersCount; float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); fixAngle(cylinderStart); engine->engineState.mapAveragingStart[i] = cylinderStart; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index cddd965307..7c17987fcb 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -176,14 +176,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(engineCycle) * i / CONFIG(specs.cylindersCount); + + (float) CONFIG(engineCycleDuration) * 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(engineCycle) * i / CONFIG(specs.cylindersCount); + + (float) CONFIG(engineCycleDuration) * i / CONFIG(specs.cylindersCount); /** * We do not need injector pin here because we will control all injectors @@ -196,7 +196,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(engineCycle) / CONFIG(specs.cylindersCount); + + i * (float) CONFIG(engineCycleDuration) / CONFIG(specs.cylindersCount); registerInjectionEvent(index, angle, false PASS_ENGINE_PARAMETER); if (CONFIG(twoWireBatch)) { @@ -372,13 +372,13 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F) { engine_configuration2_s *engineConfiguration2 = engine->engineConfiguration2; for (int i = 0; i < CONFIG(specs.cylindersCount); i++) { - ENGINE(angleExtra[i])= (float) CONFIG(engineCycle) * i / CONFIG(specs.cylindersCount); + ENGINE(angleExtra[i])= (float) CONFIG(engineCycleDuration) * i / CONFIG(specs.cylindersCount); ENGINE(ignitionPin[i]) = getIgnitionPinForIndex(i PASS_ENGINE_PARAMETER); } - for (int angle = 0; angle < CONFIG(engineCycle); angle++) { + for (int angle = 0; angle < CONFIG(engineCycleDuration); angle++) { if (angle==700) { is700++; } diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 9faf2d4788..68fb5ca6dd 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -28,14 +28,20 @@ void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, * @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke * I guess this implementation would be faster than 'angle % engineCycle' */ -#define fixAngle(angle) \ - if (CONFIG(engineCycle) == 0) { \ - firmwareError("zero engineCycle"); \ - } \ - while (angle < 0) \ - angle += CONFIG(engineCycle); \ - while (angle >= CONFIG(engineCycle)) \ - angle -= CONFIG(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; \ + } \ + } /** * @return time needed to rotate crankshaft by one degree, in milliseconds. diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 375eff06a9..b989bc2496 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -339,10 +339,10 @@ static ALWAYS_INLINE void scheduleIgnitionAndFuelEvents(int rpm, int revolutionI * but we are already re-purposing the output signals, but everything works because we * are not affecting that space in memory. todo: use two instances of 'ignitionSignals' */ - float maxAllowedDwellAngle = (int) (engineConfiguration->engineCycle / 2); // the cast is about making Coverity happy + float maxAllowedDwellAngle = (int) (engineConfiguration->engineCycleDuration / 2); // the cast is about making Coverity happy if (engineConfiguration->ignitionMode == IM_ONE_COIL) { - maxAllowedDwellAngle = engineConfiguration->engineCycle / engineConfiguration->specs.cylindersCount / 1.1; + maxAllowedDwellAngle = engineConfiguration->engineCycleDuration / engineConfiguration->specs.cylindersCount / 1.1; } if (engine->engineState.dwellAngle == 0) { diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index df7383fca3..46812afecc 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -196,7 +196,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, if (diffNt == 0) { rpmState->setRpmValue(NOISY_RPM); } else { - int mult = engineConfiguration->engineCycle / 360; + int mult = engineConfiguration->engineCycleDuration / 360; int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt); rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm); } diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 005740af9b..5315ad2bac 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -245,7 +245,7 @@ void printAllTriggers() { engine_configuration_s *engineConfiguration = &pc.engineConfiguration; board_configuration_s *boardConfiguration = &engineConfiguration->bc; - engineConfiguration->engineCycle = 720; + engineConfiguration->engineCycleDuration = 720; engineConfiguration->trigger.type = tt; engineConfiguration->operationMode = FOUR_STROKE_CAM_SENSOR; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 7e04ae4fd0..8f980d99b2 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -187,7 +187,7 @@ end_struct specs_s specs float cylinderBore;Cylinder diameter, in mm. -int engineCycle;todo:eliminate this?\ntodo:operationMode should be enough\n360 for two-stroke\n720 for four-stroke;"engine cycle", 1, 0, 0, 1000, 0 +int engineCycleDuration;todo:eliminate this?\ntodo:operationMode should be enough\n360 for two-stroke\n720 for four-stroke;"engine cycle", 1, 0, 0, 1000, 0 int rpmHardLimit;;"rpm", 1, 0, 0, 20000.0, 2 diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index e5de76780d..6d10a34dc6 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -283,8 +283,8 @@ static void testRpmCalculator(void) { IgnitionEventList *ilist = ð.engine.engineConfiguration2->ignitionEvents[0]; assertEqualsM("size", 6, ilist->size); - assertEquals(720, eth.engine.engineConfiguration->engineCycle); - assertEquals(720, eth.ec->engineCycle); + assertEquals(720, eth.engine.engineConfiguration->engineCycleDuration); + assertEquals(720, eth.ec->engineCycleDuration); efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine");