diff --git a/firmware/config/engines/nissan_primera.cpp b/firmware/config/engines/nissan_primera.cpp index 7fab2aae1c..5e319d17e9 100644 --- a/firmware/config/engines/nissan_primera.cpp +++ b/firmware/config/engines/nissan_primera.cpp @@ -20,7 +20,13 @@ void setNissanPrimeraEngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->trigger.type = TT_NISSAN_SR20VE; -// engineConfiguration->auxValves[0] + boardConfiguration->ignitionPins[0] = GPIOD_7; + boardConfiguration->ignitionPins[1] = GPIO_UNASSIGNED; + boardConfiguration->ignitionPins[2] = GPIOD_6; + + + engineConfiguration->auxValves[0] = GPIOE_14; + engineConfiguration->auxValves[1] = GPIOE_12; } void setNissanPrimeraEngineConfiguration_360(DECLARE_CONFIG_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index a9918adc59..c2b16dd290 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -45,6 +45,8 @@ class RpmCalculator; #define CLEANUP_MODE_TPS 90 #define STEPPER_PARKING_TPS CLEANUP_MODE_TPS +#define CYCLE_ALTERNATION 2 + class Engine { public: explicit Engine(persistent_config_s *config); @@ -56,6 +58,14 @@ public: LocalVersionHolder auxParametersVersion; operation_mode_e getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); + + scheduling_s auxTurnOnEvent[AUX_DIGITAL_VALVE_COUNT][/* we have two 180 cycles within engine 360 revolution */ 2][CYCLE_ALTERNATION]; + scheduling_s auxTurnOffEvent[AUX_DIGITAL_VALVE_COUNT][2][CYCLE_ALTERNATION]; + + + int auxSchedulingIndex = 2; + bool needTdcCallback = true; + /** * By the way 32-bit value should hold at least 400 hours of events at 6K RPM x 12 events per revolution */ diff --git a/firmware/controllers/trigger/aux_valves.cpp b/firmware/controllers/trigger/aux_valves.cpp index 972373e0ca..2edee85fcb 100644 --- a/firmware/controllers/trigger/aux_valves.cpp +++ b/firmware/controllers/trigger/aux_valves.cpp @@ -21,26 +21,19 @@ EXTERN_ENGINE ; -#define CYCLE_ALTERNATION 2 - -static scheduling_s turnOnEvent[AUX_DIGITAL_VALVE_COUNT][/* we have two 180 cycles within engine 360 revolution */ 2][CYCLE_ALTERNATION]; -static scheduling_s turnOffEvent[AUX_DIGITAL_VALVE_COUNT][2][CYCLE_ALTERNATION]; - -static void turnOn(NamedOutputPin *output) { +void plainPinTurnOn(NamedOutputPin *output) { output->setHigh(); } -static void turnOff(NamedOutputPin *output) { +void plainPinTurnOff(NamedOutputPin *output) { output->setLow(); } -#define SCHEDULING_TRIGGER_INDEX 2 - static void auxValveTriggerCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { UNUSED(ckpSignalType); - if (index != SCHEDULING_TRIGGER_INDEX) { + if (index != engine->auxSchedulingIndex) { return; } int rpm = GET_RPM_VALUE; @@ -71,8 +64,8 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, */ angle_t extra = phaseIndex * 360 + valveIndex * 180; angle_t onTime = extra + engine->engineState.auxValveStart; - scheduling_s *onEvent = &turnOnEvent[valveIndex][phaseIndex][engineCycleAlternation]; - scheduling_s *offEvent = &turnOffEvent[valveIndex][phaseIndex][engineCycleAlternation]; + scheduling_s *onEvent = &engine->auxTurnOnEvent[valveIndex][phaseIndex][engineCycleAlternation]; + scheduling_s *offEvent = &engine->auxTurnOffEvent[valveIndex][phaseIndex][engineCycleAlternation]; bool isOverlap = onEvent->isScheduled || offEvent->isScheduled; if (isOverlap) { enginePins.debugTriggerSync.setValue(1); @@ -81,12 +74,12 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, fixAngle(onTime, "onTime", CUSTOM_ERR_6556); scheduleByAngle(rpm, onEvent, onTime, - (schfunc_t) &turnOn, output PASS_ENGINE_PARAMETER_SUFFIX); + (schfunc_t) &plainPinTurnOn, output PASS_ENGINE_PARAMETER_SUFFIX); angle_t offTime = extra + engine->engineState.auxValveEnd; fixAngle(offTime, "offTime", CUSTOM_ERR_6557); scheduleByAngle(rpm, offEvent, offTime, - (schfunc_t) &turnOff, output PASS_ENGINE_PARAMETER_SUFFIX); + (schfunc_t) &plainPinTurnOff, output PASS_ENGINE_PARAMETER_SUFFIX); if (isOverlap) { enginePins.debugTriggerSync.setValue(0); } diff --git a/firmware/controllers/trigger/aux_valves.h b/firmware/controllers/trigger/aux_valves.h index 172b488cff..8cda4a0515 100644 --- a/firmware/controllers/trigger/aux_valves.h +++ b/firmware/controllers/trigger/aux_valves.h @@ -1,16 +1,15 @@ /* - * aux_valves.h + * @file aux_valves.h * * @date Nov 25, 2017 * @author Andrey Belomutskiy, (c) 2012-2017 */ -#ifndef CONTROLLERS_TRIGGER_AUX_VALVES_H_ -#define CONTROLLERS_TRIGGER_AUX_VALVES_H_ +#pragma once #include "engine.h" void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE); - -#endif /* CONTROLLERS_TRIGGER_AUX_VALVES_H_ */ +void plainPinTurnOn(NamedOutputPin *output); +void plainPinTurnOff(NamedOutputPin *output); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 107f47f7d8..6d2c802970 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -296,6 +296,9 @@ static char rpmBuffer[_MAX_FILLER]; * digital sniffer. */ static void onTdcCallback(Engine *engine) { + if (!engine->needTdcCallback) { + return; + } EXPAND_Engine; itoa10(rpmBuffer, GET_RPM()); #if EFI_ENGINE_SNIFFER diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 176015f60c..e0d0eb4ce4 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -258,7 +258,7 @@ static bool scheduleOrQueue(AngleBasedEvent *event, uint32_t trgEventIndex, angl bool isPending = assertNotInIgnitionList(ENGINE(ignitionEventsHead), event); if (isPending) { #if SPARK_EXTREME_LOGGING - scheduleMsg(logger, "isPending thus nt adding to queue index=%d rev=%d now=%d", trgEventIndex, getRevolutionCounter(), (int)getTimeNowUs()); + scheduleMsg(logger, "isPending thus not adding to queue index=%d rev=%d now=%d", trgEventIndex, getRevolutionCounter(), (int)getTimeNowUs()); #endif /* FUEL_MATH_EXTREME_LOGGING */ } else { LL_APPEND2(ENGINE(ignitionEventsHead), event, nextToothEvent); diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 08c0e1f6fb..7bc1b53137 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -163,14 +163,19 @@ void EngineTestHelper::assertInjectorDownEvent(const char *msg, int eventIndex, scheduling_s * EngineTestHelper::assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp) { TestExecutor *executor = &engine.executor; - EXPECT_TRUE(executor->size() > index) << msg; + EXPECT_TRUE(executor->size() > index) << msg << " valid index"; scheduling_s *event = executor->getForUnitTest(index); - assertEqualsM4(msg, " up/down", (void*)event->action.getCallback() == (void*) callback, 1); + assertEqualsM4(msg, " callback up/down", (void*)event->action.getCallback() == (void*) callback, 1); efitime_t start = getTimeNowUs(); - assertEqualsM(msg, expectedTimestamp, event->momentX - start); + assertEqualsM4(msg, " timestamp", expectedTimestamp, event->momentX - start); return event; } +scheduling_s * EngineTestHelper::assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitime_t expectedTimestamp) { + scheduling_s * actual = assertEvent5(msg, index, callback, expectedTimestamp); + +} + void EngineTestHelper::assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *expectedEvent) { scheduling_s *event = assertEvent5(msg, index, callback, momentX); diff --git a/unit_tests/engine_test_helper.h b/unit_tests/engine_test_helper.h index 265b660c18..36fe344547 100644 --- a/unit_tests/engine_test_helper.h +++ b/unit_tests/engine_test_helper.h @@ -47,6 +47,7 @@ public: void clearQueue(); scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitime_t expectedTimestamp); + scheduling_s * assertScheduling(const char *msg, int index, scheduling_s *expected, void *callback, efitime_t expectedTimestamp); void assertEvent(const char *msg, int index, void *callback, efitime_t momentX, InjectionEvent *event); void assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex); void assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex); diff --git a/unit_tests/tests/test_aux_valves.cpp b/unit_tests/tests/test_aux_valves.cpp new file mode 100644 index 0000000000..7a74d90fe6 --- /dev/null +++ b/unit_tests/tests/test_aux_valves.cpp @@ -0,0 +1,30 @@ +/* + * @file test_aux_valves.cpp + * + * @date: Nov 23, 2019 + * @Author: Andrey Belomutskiy, (c) 2012-2019 + */ + +#include "engine_test_helper.h" +#include "aux_valves.h" + +TEST(misc, testAuxValves) { + WITH_ENGINE_TEST_HELPER(NISSAN_PRIMERA); + + engine->auxSchedulingIndex = 0; + engine->needTdcCallback = false; + + setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL); + engineConfiguration->isInjectionEnabled = false; + + eth.fireTriggerEvents2(2 /* count */ , 600 /* ms */); + ASSERT_EQ( 100, GET_RPM()) << "spinning-RPM#1"; + + scheduling_s *sch; + + sch = eth.assertScheduling("a0", 0, (void*)&engine->auxTurnOnEvent, &plainPinTurnOn, -600000); + + sch = eth.assertScheduling("a1", 1, (void*)&engine->auxTurnOffEvent, &plainPinTurnOff, -550000); + sch = eth.assertScheduling("a2", 2, (void*)&engine->auxTurnOnEvent[1][0][0], &plainPinTurnOn, -300000); + +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index c7b3e3866d..dc6e721b4f 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -1,6 +1,7 @@ TESTS_SRC_CPP = \ tests/test_util.cpp \ tests/test_ion.cpp \ + tests/test_aux_valves.cpp \ tests/test_on_demand_parameters.cpp \ tests/test_hip9011.cpp \ tests/test_cj125.cpp \