diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index cce1e456f4..a3fa0ddcd8 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -189,8 +189,6 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_ return; } - efiAssertVoid(!cisnan(engine->rpmCalculator.oneDegreeUs), "NAN one deg"); - /** * injection phase is scheduled by injection end, so we need to step the angle back * for the duration of the injection diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 1b15961678..a05c279ef9 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -211,7 +211,9 @@ static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t currentEventInde for (int injEventIndex = 0; injEventIndex < injectionEvents->size; injEventIndex++) { InjectionEvent *event = &injectionEvents->elements[injEventIndex]; - if (event->injectionStart.eventIndex != currentEventIndex) { + uint32_t eventIndex = event->injectionStart.eventIndex; +// todo fix bug & uncomment this efiAssertVoid(eventIndex < ENGINE(triggerShape.getLength()), "handleFuel/event sch index"); + if (eventIndex != currentEventIndex) { continue; } handleFuelInjectionEvent(injEventIndex, limitedFuel, event, rpm PASS_ENGINE_PARAMETER); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 377c349151..dab4dc331e 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -71,6 +71,10 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) { return false; } } + if (lastRpmEventTimeNt == 0) { + // here we assume 64 bit time does not overflow, zero value is the default meaning no events so far + return false; + } /** * note that the result of this subtraction could be negative, that would happen if * we have a trigger event between the time we've invoked 'getTimeNow' and here diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 9bd1287c57..7183621894 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -87,6 +87,4 @@ void EngineTestHelper::applyTriggerShape() { engine->triggerShape.initializeTriggerShape(NULL PASS_ENGINE_PARAMETER); incrementGlobalConfigurationVersion(); - - } diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index c2effead02..be0a4b3fa6 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -604,8 +604,14 @@ void testFuelSchedulerBug299(void) { assertEqualsM("RPM=0", 0, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); + eth.fireTriggerEvents2(1, MS2US(20)); + assertEqualsM("RPM#1", 0, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); - eth.fireTriggerEvents2(2, MS2US(20)); + eth.fireTriggerEvents2(1, MS2US(20)); + + assertEqualsM("RPM#2", 3000, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); +// // this is needed to apply new fuel schedule, we can only do that once we have RPM +// engine->periodicFastCallback(PASS_ENGINE_PARAMETER_F); schedulingQueue.executeAll(99999999); // this is needed to clear 'isScheduled' flag engine->iHead = NULL; // let's drop whatever was scheduled just to start from a clean state @@ -619,25 +625,25 @@ void testFuelSchedulerBug299(void) { scheduling_s *ev = schedulingQueue.getForUnitText(0); assertREqualsM("Call@0", (void*)ev->callback, (void*)seTurnPinHigh); - assertEqualsM("ev 0", start + MS2US(24), ev->momentX); + assertEqualsM("ev 0", start + MS2US(27), ev->momentX); assertEqualsLM("in 0", (long)&enginePins.injectors[3], (long)ev->param); } { scheduling_s *ev = schedulingQueue.getForUnitText(1); assertREqualsM("Call@1", (void*)ev->callback, (void*)seTurnPinLow); - assertEqualsM("ev 1", start + MS2US(27), ev->momentX); + assertEqualsM("ev 1", start + MS2US(30), ev->momentX); assertEqualsLM("in 1", (long)&enginePins.injectors[3], (long)ev->param); } { scheduling_s *ev = schedulingQueue.getForUnitText(2); assertREqualsM("Call@2", (void*)ev->callback, (void*)seTurnPinHigh); - assertEqualsM("ev 2", start + MS2US(34), ev->momentX); + assertEqualsM("ev 2", start + MS2US(37), ev->momentX); assertEqualsLM("in 2", (long)&enginePins.injectors[1], (long)ev->param); } { scheduling_s *ev = schedulingQueue.getForUnitText(3); assertREqualsM("Call@3", (void*)ev->callback, (void*)seTurnPinLow); - assertEqualsM("ev 3", start + MS2US(37), ev->momentX); + assertEqualsM("ev 3", start + MS2US(40), ev->momentX); assertEqualsLM("in 3", (long)&enginePins.injectors[1], (long)ev->param); }