From f7712aec07c1fcbea263cb1d0be92a9049d0f281 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 14 Nov 2016 15:04:44 -0500 Subject: [PATCH] auto-sync --- .../trigger/main_trigger_callback.cpp | 4 +- .../controllers/trigger/trigger_structure.cpp | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 0dd01cf911..1079db442a 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -376,7 +376,7 @@ static void handleFuelScheduleOverlap(InjectionEventList *injectionEvents DECLAR static ALWAYS_INLINE void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm DECLARE_ENGINE_PARAMETER_S) { efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#3"); - efiAssertVoid(trgEventIndex < ENGINE(triggerShape.getLength()), "handleFuel/event index"); + efiAssertVoid(trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index"); if (!isInjectionEnabled(engineConfiguration) || limitedFuel) { return; @@ -469,7 +469,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D } efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#2"); - if (trgEventIndex >= ENGINE(triggerShape.getLength())) { + if (trgEventIndex >= engine->engineCycleEventCount) { /** * this could happen in case of a trigger error, just exit silently since the trigger error is supposed to be handled already * todo: should this check be somewhere higher so that no trigger listeners are invoked with noise? diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index f5f1e5a941..ff996124bc 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -225,20 +225,33 @@ void TriggerState::resetCurrentCycleState() { currentCycle.current_index = 0; } +/** + * physical primary trigger duration + */ +angle_t TriggerShape::getCycleDuration() const { + switch (operationMode) { + case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR: + return 180; + case FOUR_STROKE_CRANK_SENSOR: + case TWO_STROKE: + return 360; + default: + return 720; + } +} + /** * 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. */ uint32_t TriggerShape::getLength() const { - // todo: reduce magic constants, reuse getCycleDuration method - switch (operationMode) { - case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR: - return 4 * getSize(); - case FOUR_STROKE_CRANK_SENSOR: - return 2 * getSize(); - default: - return getSize(); - } + /** + * 4 for FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR + * 2 for FOUR_STROKE_CRANK_SENSOR + * 1 otherwise + */ + int multiplier = getEngineCycle(operationMode) / getCycleDuration(); + return multiplier * getSize(); } angle_t TriggerShape::getAngle(int index) const { @@ -366,18 +379,6 @@ void TriggerShape::addEvent2(angle_t angle, trigger_wheel_e const waveIndex, tri wave.waves[waveIndex].pinStates[index] = state; } -angle_t TriggerShape::getCycleDuration() const { - switch (operationMode) { - case FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR: - return 180; - case FOUR_STROKE_CRANK_SENSOR: - case TWO_STROKE: - return 360; - default: - return 720; - } -} - angle_t TriggerShape::getSwitchAngle(int index) const { return getCycleDuration() * wave.getSwitchTime(index); }