diff --git a/firmware/controllers/PwmTester.cpp b/firmware/controllers/PwmTester.cpp index 502b69062f..b62511f287 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 */ - scheduleTask("test", &ioTest, MS2US(2), testCallback, NULL); + 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 */ - scheduleTask("test", &ioTest, MS2US(2), testCallback, NULL); + scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); } #endif diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index d53dc95903..e20bbf73f7 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -60,7 +60,7 @@ Executor::Executor() { queue.setLateDelay(US2NT(100)); } -void Executor::scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, +void Executor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) { scheduleCounter++; // if (delayUs < 0) { @@ -149,7 +149,7 @@ void Executor::scheduleTimerCallback() { } /** - * @brief Schedule an event + * @brief Schedule an event at specific delay after now * * Invokes event callback after the specified amount of time. * @@ -157,12 +157,17 @@ 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(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { - instance.scheduleByTime(scheduling, getTimeNowUs() + delayUs, callback, param); +void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { + instance.scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); } -void scheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { - instance.scheduleByTime(scheduling, time, callback, param); +/** + * @brief Schedule an event at specified timestamp + * + * @param [in] timeUs absolute time of the event, since ECU boot + */ +void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { + instance.scheduleByTimestamp(scheduling, time, callback, param); } void initSignalExecutorImpl(void) { diff --git a/firmware/controllers/system/SingleTimerExecutor.h b/firmware/controllers/system/SingleTimerExecutor.h index ae2252e051..7e46b4d31c 100644 --- a/firmware/controllers/system/SingleTimerExecutor.h +++ b/firmware/controllers/system/SingleTimerExecutor.h @@ -14,7 +14,7 @@ class Executor { public: Executor(); - void scheduleByTime(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param); void onTimerCallback(); int timerCallbackCounter; int scheduleCounter; diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index c351717b4f..717f4b0007 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -294,7 +294,7 @@ bool OutputPin::isInitialized() { #endif /* EFI_GPIO_HARDWARE */ } -void OutputPin::oggle() { +void OutputPin::toggle() { setValue(!getLogicValue()); } diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index ed073f1a75..7467222ef5 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -171,7 +171,7 @@ static void timerCallback(PwmConfig *state) { efiAssertVoid(state->dbgNestingLevel < 25, "PWM nesting issue"); efitimeus_t switchTimeUs = state->togglePwmState(); - scheduleByTime(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state); + scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state); state->dbgNestingLevel--; } diff --git a/firmware/controllers/system/scheduler.h b/firmware/controllers/system/scheduler.h index 20bfd6a629..5f304ba49e 100644 --- a/firmware/controllers/system/scheduler.h +++ b/firmware/controllers/system/scheduler.h @@ -29,7 +29,7 @@ public: /** * see also scheduleByAngle */ -void scheduleTask(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); -void scheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param); +void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param); +void scheduleByTimestamp(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 1c4a0e8f98..f9970d5b0b 100644 --- a/firmware/controllers/system/signal_executor_sleep.cpp +++ b/firmware/controllers/system/signal_executor_sleep.cpp @@ -34,8 +34,8 @@ #if EFI_SIGNAL_EXECUTOR_SLEEP || defined(__DOXYGEN__) -void scheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { - scheduleTask(scheduling, time - getTimeNowUs(), callback, param); +void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { + scheduleForLater(scheduling, time - getTimeNowUs(), callback, param); } static void timerCallback(scheduling_s *scheduling) { @@ -52,7 +52,7 @@ static void timerCallback(scheduling_s *scheduling) { } -void scheduleTask(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { +void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { int delaySt = MY_US2ST(delayUs); if (delaySt <= 0) { /** diff --git a/firmware/controllers/tachometer.cpp b/firmware/controllers/tachometer.cpp index 9a426acb8f..9a5792d513 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; } - scheduleTask(&tachTurnSignalOff, (int)MS2US(durationMs), (schfunc_t) &turnTachPinLow, NULL); + 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 56151b47cf..a368f12fa1 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -195,7 +195,7 @@ void seTurnPinLow(InjectionSignalPair *pair) { ENGINE(injectionEvents.addFuelEventsForCylinder(pair->event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX)); } -static void seScheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionSignalPair *pair) { +static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionSignalPair *pair) { #if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__) InjectorOutputPin *param = pair->outputs[0]; // scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time); @@ -205,7 +205,7 @@ static void seScheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling); #endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */ - scheduleByTime(scheduling, time, callback, pair); + scheduleByTimestamp(scheduling, time, callback, pair); } static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, @@ -276,8 +276,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(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); - scheduleTask(sDown, (int) injectionStartDelayUs + durationUs, + scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); + scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs, (schfunc_t) &endSimultaniousInjection, event); } else { @@ -328,10 +328,10 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE printf("please cancel %s %d %d\r\n", output->name, (int)getTimeNowUs(), output->overlappingCounter); #endif /* EFI_UNIT_TEST || EFI_SIMULATOR */ } else { - seScheduleByTime(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, pair); + sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, pair); } efitimeus_t turnOffTime = nowUs + (int) (injectionStartDelayUs + durationUs); - seScheduleByTime(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair); + sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair); } } @@ -545,7 +545,7 @@ static void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (pulseLength > 0) { startSimultaniousInjection(engine); efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f); - scheduleTask(sDown, turnOffDelayUs, (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine); + scheduleForLater(sDown, turnOffDelayUs, (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine); } } // we'll reset it later when the engine starts diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 96efa3ea67..9091938974 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -318,7 +318,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(timer, (int) delayUs, callback, param); + scheduleForLater(timer, (int) delayUs, callback, param); } #endif diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 13af20a074..950b93f285 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -166,7 +166,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(sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent); + scheduleForLater(sUp, chargeDelayUs, (schfunc_t) &turnSparkPinHigh, iEvent); } /** * Spark event is often happening during a later trigger event timeframe @@ -192,7 +192,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 */ - scheduleTask(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent); + 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); @@ -340,7 +340,7 @@ void handleSpark(bool limitedSpark, uint32_t trgEventIndex, int rpm float timeTillIgnitionUs = ENGINE(rpmCalculator.oneDegreeUs) * current->sparkPosition.angleOffset; - scheduleTask(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current); + scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, current); } } diff --git a/unit_tests/test_signal_executor.cpp b/unit_tests/test_signal_executor.cpp index 5a3fae5756..04c599d387 100644 --- a/unit_tests/test_signal_executor.cpp +++ b/unit_tests/test_signal_executor.cpp @@ -18,15 +18,15 @@ EventQueue schedulingQueue; bool_t debugSignalExecutor = false; -void scheduleTask(scheduling_s *scheduling, int delayUs, +void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { if (debugSignalExecutor) { printf("scheduleTask %d\r\n", delayUs); } - scheduleByTime(scheduling, getTimeNowUs() + delayUs, callback, param); + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); } -void scheduleByTime(scheduling_s *scheduling, +void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, void *param) { if (debugSignalExecutor) { printf("scheduleByTime %d\r\n", time);