diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index cab1a1de13..edfcad0096 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -155,7 +155,7 @@ void Executor::scheduleTimerCallback() { * @param [in] delayUs the number of microseconds before the output signal immediate output if delay is zero. * @param [in] dwell the number of ticks of output duration. */ -void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { +void scheduleTask(const bool monitorReuse, const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { // scheduling->name = prefix; instance.scheduleByTime(scheduling, getTimeNowUs() + delayUs, callback, param); } diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 1dd3b477f6..07176f2968 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -26,7 +26,7 @@ public: bool isScheduled; }; -void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); +void scheduleTask(const bool monitorReuse, const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); void scheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param); #endif /* SCHEDULER_H_ */ diff --git a/firmware/controllers/system/signal_executor_sleep.cpp b/firmware/controllers/system/signal_executor_sleep.cpp index 7d11d67154..4e861afa52 100644 --- a/firmware/controllers/system/signal_executor_sleep.cpp +++ b/firmware/controllers/system/signal_executor_sleep.cpp @@ -35,7 +35,7 @@ #if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__) void scheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { - scheduleTask(prefix, scheduling, time - getTimeNowUs(), callback, param); + scheduleTask(true, prefix, scheduling, time - getTimeNowUs(), callback, param); } static void timerCallback(scheduling_s *scheduling) { @@ -52,7 +52,7 @@ static void timerCallback(scheduling_s *scheduling) { } -void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { +void scheduleTask(const bool monitorReuse, const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { int delaySt = MY_US2ST(delayUs); if (delaySt <= 0) { /** @@ -66,9 +66,10 @@ void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, sch scheduling->callback = callback; scheduling->param = param; int isArmed = chVTIsArmedI(&scheduling->timer); - if (isArmed) { + if (isArmed && monitorReuse) { #if EFI_SIMULATOR || defined(__DOXYGEN__) - printf("isArmed? why? sch=%d cb=%d p=%d\r\n", (int) scheduling, (int)callback, (int)param); + printf("%s: isArmed? why? sch=%d cb=%d p=%d\r\n", prefix, (int) scheduling, (int)callback, (int)param); +// firmwareError("armored"); #endif /* EFI_SIMULATOR */ chVTResetI(&scheduling->timer); } diff --git a/firmware/controllers/tachometer.cpp b/firmware/controllers/tachometer.cpp index 6a1a2fd61f..632500b385 100644 --- a/firmware/controllers/tachometer.cpp +++ b/firmware/controllers/tachometer.cpp @@ -27,7 +27,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType, return; } turnPinHigh(&enginePins.tachOut); - scheduleTask("tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL); + scheduleTask(false, "tach off", &tachTurnSignalOff, (int)MS2US(engineConfiguration->tachPulseDuractionMs), (schfunc_t) &turnTachPinLow, NULL); } void initTachometer(void) { diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 70b9da8920..aa55c8f8f1 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -289,8 +289,8 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE // todo: sequential need this logic as well, just do not forget to clear flag pair->isScheduled = true; scheduling_s * sDown = &pair->signalTimerDown; - scheduleTask("out up", sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); - scheduleTask("out down", sDown, (int) injectionStartDelayUs + MS2US(injectionDuration), + scheduleTask(true, "out up", sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); + scheduleTask(true, "out down", sDown, (int) injectionStartDelayUs + MS2US(injectionDuration), (schfunc_t) &endSimultaniousInjection, engine); } else { diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index dccc3e976a..83fbfd78c0 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -319,7 +319,7 @@ void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, efiAssertVoid(isValidRpm(rpm), "RPM check expected"); float delayUs = calc->oneDegreeUs * angle; efiAssertVoid(!cisnan(delayUs), "NaN delay?"); - scheduleTask("by angle", timer, (int) delayUs, callback, param); + scheduleTask(false, "by angle", timer, (int) delayUs, callback, param); } #endif diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index a80b075e3d..44964b89cb 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -86,7 +86,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI * This way we make sure that coil dwell started while spark was enabled would fire and not burn * the coil. */ - scheduleTask("spark up", sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent->output); + scheduleTask(true, "spark up", sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent->output); } /** * Spark event is often happening during a later trigger event timeframe @@ -104,7 +104,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI printf("spark delay=%f angle=%f\r\n", timeTillIgnitionUs, iEvent->sparkPosition.angleOffset); #endif - scheduleTask("spark1 down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent->output); + scheduleTask(true, "spark1 down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent->output); } else { /** * Spark should be scheduled in relation to some future trigger event, this way we get better firing precision @@ -179,7 +179,7 @@ void handleSpark(int revolutionIndex, bool limitedSpark, uint32_t trgEventIndex, scheduling_s * sDown = ¤t->signalTimerDown; float timeTillIgnitionUs = ENGINE(rpmCalculator.oneDegreeUs) * current->sparkPosition.angleOffset; - scheduleTask("spark 2down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current->output); + scheduleTask(true, "spark 2down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current->output); } } diff --git a/unit_tests/test_signal_executor.cpp b/unit_tests/test_signal_executor.cpp index 4bac1fbc07..5910f7da30 100644 --- a/unit_tests/test_signal_executor.cpp +++ b/unit_tests/test_signal_executor.cpp @@ -18,7 +18,7 @@ EventQueue schedulingQueue; bool_t debugSignalExecutor = false; -void scheduleTask(const char *msg, scheduling_s *scheduling, int delayUs, +void scheduleTask(const bool monitorReuse, const char *msg, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { if (debugSignalExecutor) { printf("scheduleTask %d\r\n", delayUs);