2021-07-02 11:56:12 -07:00
|
|
|
/*
|
|
|
|
* @file test_nissan_vq_vvt.cpp
|
|
|
|
*
|
|
|
|
* Created on: Jul 2, 2021
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2021
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2021-07-02 14:32:29 -07:00
|
|
|
#include "trigger_nissan.h"
|
2021-07-03 09:43:01 -07:00
|
|
|
#include "nissan_vq.h"
|
2021-07-02 14:32:29 -07:00
|
|
|
|
|
|
|
class TriggerCallback {
|
|
|
|
public:
|
|
|
|
Engine *engine;
|
2021-07-02 16:23:37 -07:00
|
|
|
int toothIndex;
|
2021-07-02 14:32:29 -07:00
|
|
|
TriggerWaveform *form;
|
2021-07-02 16:23:37 -07:00
|
|
|
bool isVvt;
|
2021-07-03 08:08:22 -07:00
|
|
|
int vvtBankIndex;
|
2021-09-05 02:56:59 -07:00
|
|
|
scheduling_s sched;
|
2021-07-02 14:32:29 -07:00
|
|
|
};
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
static void func(TriggerCallback *callback) {
|
2021-07-02 16:23:37 -07:00
|
|
|
int formIndex = callback->toothIndex % callback->form->getSize();
|
2021-07-02 14:32:29 -07:00
|
|
|
Engine *engine = callback->engine;
|
|
|
|
EXPAND_Engine;
|
|
|
|
|
2021-11-11 10:19:25 -08:00
|
|
|
int value = callback->form->wave->getChannelState(0, formIndex);
|
2021-07-02 16:23:37 -07:00
|
|
|
efitick_t nowNt = getTimeNowNt();
|
|
|
|
if (callback->isVvt) {
|
|
|
|
trigger_value_e v = value ? TV_RISE : TV_FALL;
|
2021-11-16 01:15:29 -08:00
|
|
|
hwHandleVvtCamSignal(v, nowNt, callback->vvtBankIndex * CAMS_PER_BANK);
|
2021-07-02 14:32:29 -07:00
|
|
|
} else {
|
2021-11-16 01:15:29 -08:00
|
|
|
handleShaftSignal(0, value, nowNt);
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-02 16:23:37 -07:00
|
|
|
}
|
|
|
|
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
static void scheduleTriggerEvents(TriggerWaveform *shape,
|
|
|
|
float timeScale,
|
|
|
|
int count,
|
|
|
|
bool isVvt,
|
2021-07-03 08:08:22 -07:00
|
|
|
int vvtBankIndex,
|
2021-09-05 02:56:59 -07:00
|
|
|
int vvtOffset,
|
2021-11-16 01:15:29 -08:00
|
|
|
std::vector<std::shared_ptr<TriggerCallback>>& ptrs) {
|
2021-07-02 16:23:37 -07:00
|
|
|
int totalIndex = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* yet another approach to trigger testing: let's schedule a huge list of events from heap
|
|
|
|
* and then execute those one
|
|
|
|
*/
|
2021-07-02 16:57:26 -07:00
|
|
|
for (int r = 0; r < count; r++) {
|
2021-07-03 08:08:22 -07:00
|
|
|
for (size_t i = 0; i < shape->getSize(); i++) {
|
2021-07-02 17:28:15 -07:00
|
|
|
float angle = vvtOffset + shape->getAngle(totalIndex);
|
2021-09-05 02:56:59 -07:00
|
|
|
|
|
|
|
std::shared_ptr<TriggerCallback> param = std::make_shared<TriggerCallback>();
|
|
|
|
ptrs.push_back(param);
|
|
|
|
|
2021-07-02 16:23:37 -07:00
|
|
|
param->engine = engine;
|
|
|
|
param->toothIndex = totalIndex;
|
|
|
|
param->form = shape;
|
|
|
|
param->isVvt = isVvt;
|
2021-07-03 08:08:22 -07:00
|
|
|
param->vvtBankIndex = vvtBankIndex;
|
2021-07-02 16:23:37 -07:00
|
|
|
|
2021-09-05 02:56:59 -07:00
|
|
|
engine->executor.scheduleByTimestamp("test", ¶m->sched, timeScale * 1000 * angle, { func, param.get() });
|
2021-07-02 16:23:37 -07:00
|
|
|
totalIndex++;
|
|
|
|
}
|
|
|
|
}
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-02 11:56:12 -07:00
|
|
|
|
2021-07-02 16:23:37 -07:00
|
|
|
|
2021-07-02 11:56:12 -07:00
|
|
|
TEST(nissan, vq_vvt) {
|
2021-09-05 02:56:59 -07:00
|
|
|
// hold a reference to the heap allocated scheduling events until the test is done
|
|
|
|
std::vector<std::shared_ptr<TriggerCallback>> ptrs;
|
|
|
|
|
2021-08-08 04:04:18 -07:00
|
|
|
WITH_ENGINE_TEST_HELPER (HELLEN_121_NISSAN_6_CYL);
|
2021-07-02 15:33:32 -07:00
|
|
|
engineConfiguration->isIgnitionEnabled = false;
|
|
|
|
engineConfiguration->isInjectionEnabled = false;
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-05 19:17:26 -07:00
|
|
|
int cyclesCount = 48;
|
2021-07-02 16:57:26 -07:00
|
|
|
|
2021-07-02 14:32:29 -07:00
|
|
|
{
|
2021-07-02 15:33:32 -07:00
|
|
|
static TriggerWaveform crank;
|
2021-07-16 21:46:24 -07:00
|
|
|
initializeNissanVQ35crank(&crank);
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&crank,
|
|
|
|
/* timeScale */ 1,
|
2021-11-16 01:15:29 -08:00
|
|
|
cyclesCount, false, -1, 0, ptrs);
|
2021-07-02 14:32:29 -07:00
|
|
|
}
|
2021-07-05 19:17:26 -07:00
|
|
|
float vvtTimeScale = 1;
|
2021-07-02 14:32:29 -07:00
|
|
|
|
2021-07-05 20:15:44 -07:00
|
|
|
angle_t testVvtOffset = 13;
|
2021-07-03 09:43:01 -07:00
|
|
|
|
2021-07-02 16:23:37 -07:00
|
|
|
{
|
|
|
|
static TriggerWaveform vvt;
|
|
|
|
initializeNissanVQvvt(&vvt);
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&vvt,
|
|
|
|
/* timeScale */ vvtTimeScale,
|
|
|
|
cyclesCount / 6, true,
|
2021-07-03 08:08:22 -07:00
|
|
|
/* vvtBankIndex */ 0,
|
2021-09-05 02:56:59 -07:00
|
|
|
/* vvtOffset */ testVvtOffset,
|
2021-11-16 01:15:29 -08:00
|
|
|
ptrs);
|
2021-07-02 16:23:37 -07:00
|
|
|
}
|
|
|
|
|
2021-07-02 17:28:15 -07:00
|
|
|
{
|
|
|
|
static TriggerWaveform vvt;
|
|
|
|
initializeNissanVQvvt(&vvt);
|
|
|
|
|
2021-07-03 07:15:41 -07:00
|
|
|
scheduleTriggerEvents(&vvt,
|
|
|
|
/* timeScale */ vvtTimeScale,
|
|
|
|
cyclesCount / 6, true,
|
2021-07-03 08:08:22 -07:00
|
|
|
/* vvtBankIndex */1,
|
2021-09-05 02:56:59 -07:00
|
|
|
/* vvtOffset */ testVvtOffset + NISSAN_VQ_CAM_OFFSET,
|
2021-11-16 01:15:29 -08:00
|
|
|
ptrs);
|
2021-07-02 17:28:15 -07:00
|
|
|
}
|
2021-07-02 16:23:37 -07:00
|
|
|
|
2021-07-07 20:55:33 -07:00
|
|
|
eth.executeUntil(1473000);
|
|
|
|
ASSERT_EQ(0, GET_RPM());
|
2021-07-02 11:56:12 -07:00
|
|
|
|
2021-07-07 20:55:33 -07:00
|
|
|
eth.executeUntil(1475000);
|
2021-07-05 20:15:44 -07:00
|
|
|
ASSERT_EQ(167, GET_RPM());
|
2021-07-03 07:15:41 -07:00
|
|
|
TriggerCentral *tc = &engine->triggerCentral;
|
|
|
|
|
2021-07-07 20:55:33 -07:00
|
|
|
eth.executeUntil(3593000);
|
2021-07-03 07:37:03 -07:00
|
|
|
ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized());
|
2021-07-07 20:55:33 -07:00
|
|
|
|
|
|
|
scheduling_s *head;
|
|
|
|
while ((head = engine->executor.getHead()) != nullptr) {
|
|
|
|
eth.setTimeAndInvokeEventsUs(head->momentX);
|
|
|
|
|
|
|
|
ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized());
|
|
|
|
// let's celebrate that vvtPosition stays the same
|
|
|
|
ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[0][0], EPS2D);
|
|
|
|
}
|
|
|
|
|
2021-07-03 08:08:22 -07:00
|
|
|
ASSERT_TRUE(tc->vvtState[1][0].getShaftSynchronized());
|
2021-07-03 07:15:41 -07:00
|
|
|
|
2021-07-05 20:15:44 -07:00
|
|
|
ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[0][0], EPS2D);
|
|
|
|
ASSERT_NEAR(-testVvtOffset, tc->vvtPosition[1][0], EPS2D);
|
2021-07-03 08:08:22 -07:00
|
|
|
|
2021-07-12 13:29:07 -07:00
|
|
|
EXPECT_EQ(0, eth.recentWarnings()->getCount());
|
2021-07-02 11:56:12 -07:00
|
|
|
}
|