diff --git a/firmware/controllers/PwmTester.cpp b/firmware/controllers/PwmTester.cpp index 87db9d1505..20ebc0ff56 100644 --- a/firmware/controllers/PwmTester.cpp +++ b/firmware/controllers/PwmTester.cpp @@ -73,7 +73,7 @@ static void testCallback(void *arg) { /** * this would re-schedule another callback in 2ms from now */ - scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); + engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); } void initPwmTester(void) { @@ -97,7 +97,7 @@ void initPwmTester(void) { /** * this would schedule a callback in 2ms from now */ - scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); + engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); } #endif diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index 89a106de00..5e17fc46f4 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -62,6 +62,10 @@ SingleTimerExecutor::SingleTimerExecutor() { queue.setLateDelay(US2NT(100)); } +void SingleTimerExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); +} + /** * callback would be executed either on ISR thread or current thread if we would need to execute right away */ diff --git a/firmware/controllers/system/SingleTimerExecutor.h b/firmware/controllers/system/SingleTimerExecutor.h index b1d0d71c54..5867aefd0b 100644 --- a/firmware/controllers/system/SingleTimerExecutor.h +++ b/firmware/controllers/system/SingleTimerExecutor.h @@ -15,6 +15,7 @@ class SingleTimerExecutor : public ExecutorInterface { public: SingleTimerExecutor(); void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); + void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); void onTimerCallback(); int timerCallbackCounter; int scheduleCounter; diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 085f952498..fc2efb1fc2 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -36,6 +36,7 @@ void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t c class ExecutorInterface { virtual void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) = 0; + virtual void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) = 0; }; #endif /* SCHEDULER_H_ */ diff --git a/firmware/controllers/system/signal_executor_sleep.cpp b/firmware/controllers/system/signal_executor_sleep.cpp index a2df2f116a..d2958b744b 100644 --- a/firmware/controllers/system/signal_executor_sleep.cpp +++ b/firmware/controllers/system/signal_executor_sleep.cpp @@ -91,6 +91,10 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, } } +void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { + ::scheduleForLater(scheduling, delayUs, callback, param); +} + void initSignalExecutorImpl(void) { } diff --git a/firmware/controllers/system/signal_executor_sleep.h b/firmware/controllers/system/signal_executor_sleep.h index 50585ee08b..6f8b996fa2 100644 --- a/firmware/controllers/system/signal_executor_sleep.h +++ b/firmware/controllers/system/signal_executor_sleep.h @@ -13,6 +13,7 @@ class SleepExecutor : public ExecutorInterface { public: void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); + void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); }; #endif /* SIGNAL_EXECUTOR_SLEEP_H_ */ diff --git a/firmware/controllers/tachometer.cpp b/firmware/controllers/tachometer.cpp index 9a5792d513..c787b1d41f 100644 --- a/firmware/controllers/tachometer.cpp +++ b/firmware/controllers/tachometer.cpp @@ -34,7 +34,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType, } else { durationMs = engineConfiguration->tachPulseDuractionMs; } - scheduleForLater(&tachTurnSignalOff, (int)MS2US(durationMs), (schfunc_t) &turnTachPinLow, NULL); + engine->executor.scheduleForLater(&tachTurnSignalOff, (int)MS2US(durationMs), (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 9be947a441..e72822932b 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -208,7 +208,7 @@ static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, sc printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling); #endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */ - scheduleByTimestamp(scheduling, time, callback, pair); + engine->executor.scheduleByTimestamp(scheduling, time, callback, pair); } static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, @@ -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; - scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); - scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs, + engine->executor.scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); + engine->executor.scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs, (schfunc_t) &endSimultaniousInjection, event); } else { @@ -579,7 +579,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (pulseLength > 0) { startSimultaniousInjection(engine); efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f); - scheduleForLater(sDown, turnOffDelayUs, (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine); + engine->executor.scheduleForLater(sDown, turnOffDelayUs, (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine); } } #if EFI_PROD_CODE || defined(__DOXYGEN__) diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 8550f8c7f7..3df5db90d0 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -224,7 +224,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. */ - scheduleForLater(sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent); + engine->executor.scheduleForLater(sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent); } /** * Spark event is often happening during a later trigger event timeframe @@ -264,7 +264,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI scheduleMsg(logger, "scheduling sparkDown ind=%d %d %s now=%d %d later id=%d", trgEventIndex, getRevolutionCounter(), iEvent->getOutputForLoggins()->name, (int)getTimeNowUs(), (int)timeTillIgnitionUs, iEvent->sparkId); #endif /* FUEL_MATH_EXTREME_LOGGING */ - scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent); + engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent); } else { #if SPARK_EXTREME_LOGGING || defined(__DOXYGEN__) scheduleMsg(logger, "to queue sparkDown ind=%d %d %s %d for %d", trgEventIndex, getRevolutionCounter(), iEvent->getOutputForLoggins()->name, (int)getTimeNowUs(), iEvent->sparkPosition.eventIndex); @@ -368,7 +368,7 @@ void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm float timeTillIgnitionUs = ENGINE(rpmCalculator.oneDegreeUs) * current->sparkPosition.angleOffset; - scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current); + engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current); } } diff --git a/firmware/hw_layer/servo.cpp b/firmware/hw_layer/servo.cpp index c7d324a0dc..8bad285edc 100644 --- a/firmware/hw_layer/servo.cpp +++ b/firmware/hw_layer/servo.cpp @@ -63,7 +63,7 @@ static msg_t seThread(void *arg) { float durationMs = 0 + position * 0.02f; - scheduleForLater(&servoTurnSignalOff, (int)MS2US(durationMs), (schfunc_t) &servoTachPinLow, pin); + engine->executor.scheduleForLater(&servoTurnSignalOff, (int)MS2US(durationMs), (schfunc_t) &servoTachPinLow, pin); chThdSleepMilliseconds(19); diff --git a/unit_tests/global_execution_queue.cpp b/unit_tests/global_execution_queue.cpp index e11c9fb086..c3486cef0b 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -22,19 +22,26 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs, scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); } +void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { + if (debugSignalExecutor) { + printf("scheduleTask %d\r\n", delayUs); + } + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); +} + void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) { if (debugSignalExecutor) { - printf("scheduleByTime %d\r\n", time); + printf("scheduleByTime %d\r\n", timeUs); } - schedulingQueue.insertTask(scheduling, time, callback, param); + schedulingQueue.insertTask(scheduling, timeUs, callback, param); } void scheduleByTimestamp(scheduling_s *scheduling, - efitimeus_t time, schfunc_t callback, void *param) { + efitimeus_t timeUs, schfunc_t callback, void *param) { if (debugSignalExecutor) { - printf("scheduleByTime %d\r\n", time); + printf("scheduleByTime %d\r\n", timeUs); } - schedulingQueue.insertTask(scheduling, time, callback, param); + schedulingQueue.insertTask(scheduling, timeUs, callback, param); } void initSignalExecutorImpl(void) { diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index 132f5808ef..71f099d406 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -13,6 +13,7 @@ class TestExecutor : public ExecutorInterface { public: void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); + void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); }; #endif /* GLOBAL_EXECUTION_QUEUE_H_ */