From e5a1b68eb2e804f1068511974f531e824c1c8ba8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 2 Jul 2021 20:28:15 -0400 Subject: [PATCH] Nissan VVT trigger decoder #2887 --- .../controllers/trigger/trigger_central.cpp | 2 +- .../tests/trigger/test_nissan_vq_vvt.cpp | 27 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 770abafe76..f06d4583da 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -133,7 +133,7 @@ void hwHandleVvtCamSignal(trigger_value_e front, efitick_t nowNt, int index DECL tooth = front == TV_RISE ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING; } else { // todo: nicer solution is needed - tooth = front == TV_RISE ? SHAFT_3RD_FALLING : SHAFT_3RD_FALLING; + tooth = front == TV_RISE ? SHAFT_3RD_RISING : SHAFT_3RD_FALLING; } LogTriggerTooth(tooth, nowNt PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp index d853cfd00f..c7f46a7b84 100644 --- a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp +++ b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp @@ -14,6 +14,7 @@ public: int toothIndex; TriggerWaveform *form; bool isVvt; + int vvtIndex; }; void func(TriggerCallback *callback) { @@ -25,14 +26,17 @@ void func(TriggerCallback *callback) { efitick_t nowNt = getTimeNowNt(); if (callback->isVvt) { trigger_value_e v = value ? TV_RISE : TV_FALL; - hwHandleVvtCamSignal(v, nowNt, 0 PASS_ENGINE_PARAMETER_SUFFIX); + hwHandleVvtCamSignal(v, nowNt, callback->vvtIndex PASS_ENGINE_PARAMETER_SUFFIX); } else { handleShaftSignal(0, value, nowNt PASS_ENGINE_PARAMETER_SUFFIX); } } -static void scheduleTriggerEvents(TriggerWaveform *shape, int count, bool isVvt DECLARE_ENGINE_PARAMETER_SUFFIX) { +static void scheduleTriggerEvents(TriggerWaveform *shape, int count, bool isVvt, + int vvtIndex, + int vvtOffset + DECLARE_ENGINE_PARAMETER_SUFFIX) { int totalIndex = 0; /** @@ -41,12 +45,13 @@ static void scheduleTriggerEvents(TriggerWaveform *shape, int count, bool isVvt */ for (int r = 0; r < count; r++) { for (int i = 0; i < shape->getSize(); i++) { - float angle = shape->getAngle(totalIndex); + float angle = vvtOffset + shape->getAngle(totalIndex); TriggerCallback *param = new TriggerCallback(); param->engine = engine; param->toothIndex = totalIndex; param->form = shape; param->isVvt = isVvt; + param->vvtIndex = vvtIndex; scheduling_s *sch = new scheduling_s(); engine->executor.scheduleByTimestamp(sch, 1000 * angle, { func, param }); @@ -67,16 +72,28 @@ TEST(nissan, vq_vvt) { static TriggerWaveform crank; initializeNissanVQcrank(&crank); - scheduleTriggerEvents(&crank, cyclesCount, false PASS_ENGINE_PARAMETER_SUFFIX); + scheduleTriggerEvents(&crank, cyclesCount, false, -1, 0 PASS_ENGINE_PARAMETER_SUFFIX); } { static TriggerWaveform vvt; initializeNissanVQvvt(&vvt); - scheduleTriggerEvents(&vvt, cyclesCount / 6, true PASS_ENGINE_PARAMETER_SUFFIX); + scheduleTriggerEvents(&vvt, cyclesCount / 6, true, + /* vvtIndex */ 0, + /* vvtOffset */ 0 + PASS_ENGINE_PARAMETER_SUFFIX); } + { + static TriggerWaveform vvt; + initializeNissanVQvvt(&vvt); + + scheduleTriggerEvents(&vvt, cyclesCount / 6, true, + /* vvtIndex */1, + /* vvtOffset */ 360 + PASS_ENGINE_PARAMETER_SUFFIX); + } scheduling_s *head; while ((head = engine->executor.getHead()) != nullptr) {