From 2b77901e534731db4210076a323605e0d4ad35c3 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 27 Aug 2020 00:06:10 -0400 Subject: [PATCH] VVT support for VAG trigger #883 --- firmware/controllers/algo/engine.cpp | 10 +++------- firmware/controllers/algo/engine2.cpp | 4 ++-- firmware/controllers/trigger/trigger_central.cpp | 8 ++++++++ firmware/controllers/trigger/trigger_central.h | 1 + firmware/controllers/trigger/trigger_decoder.cpp | 4 ++++ 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index a9866bbaa1..c7cb2f616f 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -102,27 +102,23 @@ void Engine::initializeTriggerWaveform(Logging *logger DECLARE_ENGINE_PARAMETER_ * 'initState' instance of TriggerState is used only to initialize 'this' TriggerWaveform instance * #192 BUG real hardware trigger events could be coming even while we are initializing trigger */ - initState.resetTriggerState(); calculateTriggerSynchPoint(&ENGINE(triggerCentral.triggerShape), &initState PASS_ENGINE_PARAMETER_SUFFIX); - if (engine->triggerCentral.triggerShape.getSize() == 0) { - firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); - } engine->engineCycleEventCount = TRIGGER_WAVEFORM(getLength()); } if (engineConfiguration->vvtMode != VVT_INACTIVE) { trigger_config_s config; - config.type = getVvtTriggerType(engineConfiguration->vvtMode); + ENGINE(triggerCentral).vvtTriggerType = config.type = getVvtTriggerType(engineConfiguration->vvtMode); ENGINE(triggerCentral).vvtShape.initializeTriggerWaveform(logger, engineConfiguration->ambiguousOperationMode, - engineConfiguration->useOnlyRisingEdgeForTrigger, &config); + engine->engineConfigurationPtr->vvtCamSensorUseRise, &config); ENGINE(triggerCentral).vvtShape.initializeSyncPoint(&initState, - &engine->primaryTriggerConfiguration, + &engine->vvtTriggerConfiguration, &config); } diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 383158ee1c..731f4e24c9 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -310,7 +310,7 @@ VvtTriggerConfiguration::VvtTriggerConfiguration(Engine *engine) { } bool VvtTriggerConfiguration::isUseOnlyRisingEdgeForTrigger() const { - return engine->engineConfigurationPtr->useOnlyRisingEdgeForTrigger; + return engine->engineConfigurationPtr->vvtCamSensorUseRise; } debug_mode_e VvtTriggerConfiguration::getDebugMode() const { @@ -318,7 +318,7 @@ debug_mode_e VvtTriggerConfiguration::getDebugMode() const { } trigger_type_e VvtTriggerConfiguration::getType() const { - return engine->engineConfigurationPtr->trigger.type; + return engine->triggerCentral.vvtTriggerType; } bool VvtTriggerConfiguration::isSilentTriggerError() const { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 625c42db15..77a4fbd80d 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -145,6 +145,14 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt DECLARE_ENGINE_ return; } + ENGINE(triggerCentral).vvtState.decodeTriggerEvent( + &ENGINE(triggerCentral).vvtShape, + nullptr, + nullptr, + &engine->vvtTriggerConfiguration, + front == TV_RISE ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING, nowNt); + + tc->vvtCamCounter++; efitick_t offsetNt = nowNt - tc->timeAtVirtualZeroNt; diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index cae3d819b4..4f815c4ae7 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -45,6 +45,7 @@ public: TriggerNoiseFilter noiseFilter; + trigger_type_e vvtTriggerType; angle_t getVVTPosition(); // latest VVT event position (could be not synchronization event) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 871ee7336d..4534babc31 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -126,6 +126,7 @@ void TriggerWaveform::initializeSyncPoint(TriggerState *state, */ void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) { + state->resetTriggerState(); #if EFI_PROD_CODE efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s"); #endif @@ -144,6 +145,9 @@ void calculateTriggerSynchPoint(TriggerWaveform *shape, shape->setShapeDefinitionError(true); return; } + if (shape->getSize() == 0) { + firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero"); + } } void prepareEventAngles(TriggerWaveform *shape,