2021-11-24 18:53:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
#include "pch.h"
|
2021-11-24 19:36:36 -08:00
|
|
|
#include "trigger_central.h"
|
2022-04-23 15:46:12 -07:00
|
|
|
#include "spark_logic.h"
|
2021-11-24 18:53:32 -08:00
|
|
|
|
2021-12-07 17:00:04 -08:00
|
|
|
TEST(trigger, map_cam_by_magic_point) {
|
|
|
|
|
2021-12-07 18:08:25 -08:00
|
|
|
EngineTestHelper eth(TEST_CRANK_ENGINE);
|
2022-04-23 06:51:47 -07:00
|
|
|
engineConfiguration->isFasterEngineSpinUpEnabled = false;
|
2021-12-07 17:00:04 -08:00
|
|
|
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->camInputs[0] = Gpio::A0;
|
2022-08-31 21:18:06 -07:00
|
|
|
engineConfiguration->vvtMode[0] = VVT_MAP_V_TWIN;
|
2022-04-23 16:45:29 -07:00
|
|
|
eth.engine.periodicFastCallback(); // trigger limp mode
|
2022-10-04 17:36:03 -07:00
|
|
|
ASSERT_FALSE(getLimpManager()->allowIgnition());
|
|
|
|
ASSERT_FALSE(getLimpManager()->allowInjection());
|
|
|
|
ASSERT_EQ(ClearReason::EnginePhase, getLimpManager()->allowIgnition().reason);
|
|
|
|
ASSERT_EQ(ClearReason::EnginePhase, getLimpManager()->allowInjection().reason);
|
2021-12-07 17:00:04 -08:00
|
|
|
|
2021-12-10 23:01:28 -08:00
|
|
|
engine->outputChannels.instantMAPValue = 100;
|
2021-12-07 17:00:04 -08:00
|
|
|
|
|
|
|
engineConfiguration->mapCamDetectionAnglePosition = 90;
|
|
|
|
|
|
|
|
eth.smartFireTriggerEvents2(/*count*/10, /*delayMs*/200);
|
2022-01-20 19:58:12 -08:00
|
|
|
ASSERT_EQ(150, Sensor::getOrZero(SensorType::Rpm)) << "RPM";
|
2021-12-07 18:08:25 -08:00
|
|
|
|
2022-04-23 17:38:48 -07:00
|
|
|
ASSERT_EQ(1, engine->triggerCentral.mapVvt_map_peak);
|
2022-08-09 17:32:39 -07:00
|
|
|
ASSERT_EQ(0, engine->triggerCentral.triggerState.camResyncCounter);
|
2021-12-07 17:00:04 -08:00
|
|
|
|
2021-12-30 22:21:21 -08:00
|
|
|
// Nothing should have been scheduled yet
|
2022-04-23 16:45:29 -07:00
|
|
|
ASSERT_EQ(1, engine->executor.size());
|
|
|
|
scheduling_s* next = engine->executor.getForUnitTest(0);
|
|
|
|
eth.assertEvent5("spark down#0", 0, (void*)fireSparkAndPrepareNextSchedule, 188333);
|
2021-12-07 17:00:04 -08:00
|
|
|
|
2021-12-10 23:01:28 -08:00
|
|
|
engine->outputChannels.instantMAPValue = 120;
|
2021-12-07 18:08:25 -08:00
|
|
|
eth.smartFireTriggerEvents2(/*count*/4, /*delayMs*/200);
|
|
|
|
|
2022-04-23 17:38:48 -07:00
|
|
|
ASSERT_EQ(2, engine->triggerCentral.mapVvt_map_peak);
|
2022-08-09 17:32:39 -07:00
|
|
|
ASSERT_EQ(1, engine->triggerCentral.triggerState.camResyncCounter);
|
2022-04-23 17:38:48 -07:00
|
|
|
ASSERT_EQ(10, engine->triggerCentral.mapVvt_MAP_AT_CYCLE_COUNT);
|
2021-12-07 17:00:04 -08:00
|
|
|
|
2022-10-04 17:36:03 -07:00
|
|
|
ASSERT_EQ(ClearReason::None, getLimpManager()->allowIgnition().reason);
|
|
|
|
ASSERT_EQ(ClearReason::None, getLimpManager()->allowInjection().reason);
|
2022-04-23 16:45:29 -07:00
|
|
|
|
2021-12-30 22:21:21 -08:00
|
|
|
// We have "VVT" sync, things should be scheduled!
|
2022-04-23 15:46:12 -07:00
|
|
|
ASSERT_EQ(2, engine->executor.size());
|
|
|
|
eth.assertEvent5("spark down#0", 0, (void*)turnSparkPinHigh, 185333);
|
|
|
|
eth.assertEvent5("spark down#1", 1, (void*)fireSparkAndPrepareNextSchedule, 188333);
|
2021-12-07 17:00:04 -08:00
|
|
|
}
|