diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 4b69451a8e..72b7645f7d 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -39,11 +39,11 @@ static int test557[] = {5, 5, 10, 10, 20, 20, 50, 50, 100, 100, 200, 200, 500, 5 efitimeus_t testTime; -static void toggleTestAndScheduleNext() { +static void toggleTestAndScheduleNext(void *) { testPin.toggle(); periodIndex = (periodIndex + 1) % TEST_LEN; testTime += test557[periodIndex]; - engine->executor.scheduleByTimestamp(&scheduling, testTime, (schfunc_t) &toggleTestAndScheduleNext, NULL); + engine->executor.scheduleByTimestamp(&scheduling, testTime, &toggleTestAndScheduleNext); } @@ -58,8 +58,7 @@ void runSchedulingPrecisionTestIfNeeded(void) { testPin.initPin("test", engineConfiguration->test557pin); testPin.setValue(0); testTime = getTimeNowUs(); - toggleTestAndScheduleNext(); - + toggleTestAndScheduleNext(/*unused*/ nullptr); } #endif /* EFI_PROD_CODE */ diff --git a/firmware/controllers/actuators/pwm_tester.cpp b/firmware/controllers/actuators/pwm_tester.cpp index f6d1277c62..0d18cd1808 100644 --- a/firmware/controllers/actuators/pwm_tester.cpp +++ b/firmware/controllers/actuators/pwm_tester.cpp @@ -73,7 +73,7 @@ static void testCallback(void *arg) { /** * this would re-schedule another callback in 2ms from now */ - engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); + engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback); } void initPwmTester(void) { @@ -97,7 +97,7 @@ void initPwmTester(void) { /** * this would schedule a callback in 2ms from now */ - engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL); + engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback); } #endif diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 195c130209..fe12ff128b 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -414,11 +414,6 @@ void doScheduleStopEngine(DECLARE_ENGINE_PARAMETER_SIGNATURE) { enginePins.stopPins(); } -void action_s::setAction(schfunc_t callback, void *param) { - this->callback = callback; - this->param = param; -} - void action_s::execute() { efiAssertVoid(CUSTOM_ERR_ASSERT, callback != NULL, "callback==null1"); callback(param); diff --git a/firmware/controllers/engine_cycle/aux_valves.cpp b/firmware/controllers/engine_cycle/aux_valves.cpp index 9634e341e3..868cb8b029 100644 --- a/firmware/controllers/engine_cycle/aux_valves.cpp +++ b/firmware/controllers/engine_cycle/aux_valves.cpp @@ -34,8 +34,7 @@ void plainPinTurnOn(AuxActor *current) { scheduleOrQueue(¤t->open, TRIGGER_EVENT_UNDEFINED, current->extra + engine->engineState.auxValveStart, - (schfunc_t)plainPinTurnOn, - current + { (schfunc_t)plainPinTurnOn, current } PASS_ENGINE_PARAMETER_SUFFIX ); @@ -46,8 +45,7 @@ void plainPinTurnOn(AuxActor *current) { scheduleOrQueue(¤t->close, TRIGGER_EVENT_UNDEFINED, current->extra + engine->engineState.auxValveEnd, - (schfunc_t)plainPinTurnOff, - output + { (schfunc_t)plainPinTurnOff, output } PASS_ENGINE_PARAMETER_SUFFIX ); } @@ -151,8 +149,7 @@ void initAuxValves(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { scheduleOrQueue(&actor->open, TRIGGER_EVENT_UNDEFINED, actor->extra + engine->engineState.auxValveStart, - (schfunc_t)plainPinTurnOn, - actor + { (schfunc_t)plainPinTurnOn, actor } PASS_ENGINE_PARAMETER_SUFFIX ); } diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 35ee53e240..f77849d5c7 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -186,7 +186,7 @@ void seTurnPinLow(InjectionEvent *event) { ENGINE(injectionEvents.addFuelEventsForCylinder(event->ownIndex PASS_ENGINE_PARAMETER_SUFFIX)); } -static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, InjectionEvent *event DECLARE_ENGINE_PARAMETER_SUFFIX) { +static void sescheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, action_s action DECLARE_ENGINE_PARAMETER_SUFFIX) { #if FUEL_MATH_EXTREME_LOGGING InjectorOutputPin *param = event->outputs[0]; // scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time); @@ -196,7 +196,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 */ - engine->executor.scheduleByTimestamp(scheduling, time, callback, event); + engine->executor.scheduleByTimestamp(scheduling, time, action); } static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event, @@ -278,9 +278,9 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE // todo: sequential need this logic as well, just do not forget to clear flag event->isScheduled = true; scheduling_s * sDown = &event->endOfInjectionEvent; - engine->executor.scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine); + engine->executor.scheduleForLater(sUp, (int) injectionStartDelayUs, { (schfunc_t) &startSimultaniousInjection, engine }); engine->executor.scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs, - (schfunc_t) &endSimultaniousInjection, event); + { (schfunc_t) &endSimultaniousInjection, event }); } else { #if EFI_UNIT_TEST @@ -327,10 +327,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 { - sescheduleByTimestamp(sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, event PASS_ENGINE_PARAMETER_SUFFIX); + sescheduleByTimestamp(sUp, turnOnTime, { (schfunc_t) &seTurnPinHigh, event } PASS_ENGINE_PARAMETER_SUFFIX); } efitimeus_t turnOffTime = nowUs + (int) (injectionStartDelayUs + durationUs); - sescheduleByTimestamp(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, event PASS_ENGINE_PARAMETER_SUFFIX); + sescheduleByTimestamp(sDown, turnOffTime, { (schfunc_t) &seTurnPinLow, event } PASS_ENGINE_PARAMETER_SUFFIX); } } @@ -561,7 +561,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (pulseLength > 0) { startSimultaniousInjection(engine); efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f); - engine->executor.scheduleForLater(sDown, turnOffDelayUs, (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine); + engine->executor.scheduleForLater(sDown, turnOffDelayUs, { (schfunc_t) &endSimultaniousInjectionOnlyTogglePins, engine }); } } #if EFI_PROD_CODE diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 6e7b354b35..72183c3121 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -314,9 +314,9 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, // we are loosing precision in case of changing RPM - the further away is the event the worse is precision // todo: schedule this based on closest trigger event, same as ignition works scheduleByAngle(&startTimer[i][structIndex], samplingStart, - startAveraging, NULL PASS_ENGINE_PARAMETER_SUFFIX); + startAveraging PASS_ENGINE_PARAMETER_SUFFIX); scheduleByAngle(&endTimer[i][structIndex], samplingEnd, - endAveraging, NULL PASS_ENGINE_PARAMETER_SUFFIX); + endAveraging PASS_ENGINE_PARAMETER_SUFFIX); engine->m.mapAveragingCbTime = getTimeNowLowerNt() - engine->m.beforeMapAveragingCb; } diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 1709ea55fb..f43e266cd6 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -323,7 +323,7 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType, // todo: use tooth event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { scheduleByAngle(&tdcScheduler[revIndex2], tdcPosition(), - (schfunc_t) onTdcCallback, engine PASS_ENGINE_PARAMETER_SUFFIX); + { (schfunc_t) onTdcCallback, engine } PASS_ENGINE_PARAMETER_SUFFIX); } } } @@ -362,9 +362,9 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { * it takes the crankshaft to rotate to the specified angle. */ void scheduleByAngle(scheduling_s *timer, angle_t angle, - schfunc_t callback, void *param DECLARE_ENGINE_PARAMETER_SUFFIX) { + action_s action DECLARE_ENGINE_PARAMETER_SUFFIX) { float delayUs = ENGINE(rpmCalculator.oneDegreeUs) * angle; - ENGINE(executor.scheduleForLater(timer, (int) delayUs, callback, param)); + ENGINE(executor.scheduleForLater(timer, (int) delayUs, action)); } #else diff --git a/firmware/controllers/engine_cycle/rpm_calculator.h b/firmware/controllers/engine_cycle/rpm_calculator.h index 551ec8b72f..ddad763866 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.h +++ b/firmware/controllers/engine_cycle/rpm_calculator.h @@ -165,5 +165,5 @@ float getCrankshaftAngleNt(efitick_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX); #define addEngineSnifferEvent(n, msg) {} #endif /* EFI_ENGINE_SNIFFER */ -void scheduleByAngle(scheduling_s *timer, angle_t angle, schfunc_t callback, void *param DECLARE_ENGINE_PARAMETER_SUFFIX); +void scheduleByAngle(scheduling_s *timer, angle_t angle, action_s action DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index e28543373d..5437ac8cfc 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -227,8 +227,8 @@ static bool assertNotInIgnitionList(AngleBasedEvent *head, AngleBasedEvent *elem bool scheduleOrQueue(AngleBasedEvent *event, uint32_t trgEventIndex, angle_t angle, - schfunc_t callback, - void *param DECLARE_ENGINE_PARAMETER_SUFFIX) { + action_s action + DECLARE_ENGINE_PARAMETER_SUFFIX) { event->position.setAngle(angle PASS_ENGINE_PARAMETER_SUFFIX); /** @@ -253,10 +253,10 @@ bool scheduleOrQueue(AngleBasedEvent *event, scheduling_s * sDown = &event->scheduling; - engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, callback, param); + engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, action); return true; } else { - event->action.setAction(callback, param); + event->action = action; /** * Spark should be scheduled in relation to some future trigger event, this way we get better firing precision */ @@ -321,7 +321,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. */ - engine->executor.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 @@ -332,7 +332,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI assertAngleRange(sparkAngle, "findAngle#a5", CUSTOM_ERR_6549); - bool scheduled = scheduleOrQueue(&iEvent->sparkEvent, trgEventIndex, sparkAngle, (schfunc_t)fireSparkAndPrepareNextSchedule, iEvent PASS_ENGINE_PARAMETER_SUFFIX); + bool scheduled = scheduleOrQueue(&iEvent->sparkEvent, trgEventIndex, sparkAngle, { (schfunc_t)fireSparkAndPrepareNextSchedule, iEvent } PASS_ENGINE_PARAMETER_SUFFIX); if (scheduled) { #if SPARK_EXTREME_LOGGING @@ -425,7 +425,7 @@ static void scheduleAllSparkEventsUntilNextTriggerTooth(uint32_t trgEventIndex D float timeTillIgnitionUs = ENGINE(rpmCalculator.oneDegreeUs) * current->position.angleOffsetFromTriggerEvent; - engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) current->action.getCallback(), current->action.getArgument()); + engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, current->action); } } } diff --git a/firmware/controllers/engine_cycle/spark_logic.h b/firmware/controllers/engine_cycle/spark_logic.h index 0a740c2a30..84af812885 100644 --- a/firmware/controllers/engine_cycle/spark_logic.h +++ b/firmware/controllers/engine_cycle/spark_logic.h @@ -24,5 +24,5 @@ int isIgnitionTimingError(void); bool scheduleOrQueue(AngleBasedEvent *event, uint32_t trgEventIndex, angle_t angle, - schfunc_t callback, - void *param DECLARE_ENGINE_PARAMETER_SUFFIX); + action_s action + DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/gauges/tachometer.cpp b/firmware/controllers/gauges/tachometer.cpp index 4dbdd6c29f..f4edb49aec 100644 --- a/firmware/controllers/gauges/tachometer.cpp +++ b/firmware/controllers/gauges/tachometer.cpp @@ -19,7 +19,7 @@ EXTERN_ENGINE; static scheduling_s tachTurnSignalOff; -static void turnTachPinLow(void) { +static void turnTachPinLow(void *) { enginePins.tachOut.setLow(); } @@ -37,7 +37,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType, } else { durationMs = engineConfiguration->tachPulseDuractionMs; } - engine->executor.scheduleForLater(&tachTurnSignalOff, (int)MS2US(durationMs), (schfunc_t) &turnTachPinLow, NULL); + engine->executor.scheduleForLater(&tachTurnSignalOff, (int)MS2US(durationMs), &turnTachPinLow); } void initTachometer(void) { diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index 994afa9f60..56154a51ee 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -36,13 +36,13 @@ bool EventQueue::checkIfPending(scheduling_s *scheduling) { /** * @return true if inserted into the head of the list */ -bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, schfunc_t callback, void *param) { +bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action) { ScopePerf perf(PE::EventQueueInsertTask); #if EFI_UNIT_TEST assertListIsSorted(); #endif /* EFI_UNIT_TEST */ - efiAssert(CUSTOM_ERR_ASSERT, callback != NULL, "NULL callback", false); + efiAssert(CUSTOM_ERR_ASSERT, action.getCallback() != NULL, "NULL callback", false); // please note that simulator does not use this code at all - simulator uses signal_executor_sleep @@ -57,7 +57,7 @@ bool EventQueue::insertTask(scheduling_s *scheduling, efitime_t timeX, schfunc_t } scheduling->momentX = timeX; - scheduling->action.setAction(callback, param); + scheduling->action = action; scheduling->isScheduled = true; if (head == NULL || timeX < head->momentX) { diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index d1789feb0a..7978f33630 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -51,7 +51,7 @@ public: /** * O(size) - linear search in sorted linked list */ - bool insertTask(scheduling_s *scheduling, efitime_t timeX, schfunc_t callback, void *param); + bool insertTask(scheduling_s *scheduling, efitime_t timeX, action_s action); int executeAll(efitime_t now); diff --git a/firmware/controllers/system/timer/pwm_generator_logic.cpp b/firmware/controllers/system/timer/pwm_generator_logic.cpp index 2a30ac0d7a..7397697ea7 100644 --- a/firmware/controllers/system/timer/pwm_generator_logic.cpp +++ b/firmware/controllers/system/timer/pwm_generator_logic.cpp @@ -262,7 +262,7 @@ static void timerCallback(PwmConfig *state) { return; } - state->executor->scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state); + state->executor->scheduleByTimestamp(&state->scheduling, switchTimeUs, { (schfunc_t) timerCallback, state }); state->dbgNestingLevel--; } diff --git a/firmware/controllers/system/timer/scheduler.h b/firmware/controllers/system/timer/scheduler.h index 17935acf9e..f9ba4b1837 100644 --- a/firmware/controllers/system/timer/scheduler.h +++ b/firmware/controllers/system/timer/scheduler.h @@ -12,7 +12,12 @@ typedef void (*schfunc_t)(void *); class action_s { public: - void setAction(schfunc_t callback, void *param); + action_s() = default; + + // Allow implicit conversion from schfunc_t to action_s + action_s(schfunc_t callback) : action_s(callback, nullptr) { } + action_s(schfunc_t callback, void *param) : callback(callback), param(param) { } + void execute(); schfunc_t getCallback() const; void * getArgument() const; @@ -25,8 +30,7 @@ private: /** * This structure holds information about an event scheduled in the future: when to execute what callback with what parameters */ -class scheduling_s { -public: +struct scheduling_s { #if EFI_SIGNAL_EXECUTOR_SLEEP virtual_timer_t timer; #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ @@ -45,11 +49,10 @@ public: action_s action; }; -class ExecutorInterface { -public: +struct ExecutorInterface { /** * see also scheduleByAngle */ - 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; + virtual void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) = 0; + virtual void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) = 0; }; diff --git a/firmware/controllers/system/timer/signal_executor_sleep.cpp b/firmware/controllers/system/timer/signal_executor_sleep.cpp index f08d30a608..3e80d7c6e2 100644 --- a/firmware/controllers/system/timer/signal_executor_sleep.cpp +++ b/firmware/controllers/system/timer/signal_executor_sleep.cpp @@ -33,8 +33,8 @@ #if EFI_SIGNAL_EXECUTOR_SLEEP -void SleepExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) { - scheduleForLater(scheduling, timeUs - getTimeNowUs(), callback, param); +void SleepExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) { + scheduleForLater(scheduling, timeUs - getTimeNowUs(), action); } static void timerCallback(scheduling_s *scheduling) { @@ -50,18 +50,18 @@ static void timerCallback(scheduling_s *scheduling) { scheduling->action.execute(); } -static void doScheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { +static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { int delaySt = MY_US2ST(delayUs); if (delaySt <= 0) { /** * in case of zero delay, we should invoke the callback */ - callback(param); + action.execute(); return; } bool alreadyLocked = lockAnyContext(); - scheduling->action.setAction(callback, param); + scheduling->action = action; int isArmed = chVTIsArmedI(&scheduling->timer); if (isArmed) { /** @@ -71,8 +71,8 @@ static void doScheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t } #if EFI_SIMULATOR - if (callback == (schfunc_t)&seTurnPinLow) { - printf("setTime cb=seTurnPinLow p=%d\r\n", (int)param); + if (action.getCallback() == (schfunc_t)&seTurnPinLow) { + printf("setTime cb=seTurnPinLow p=%d\r\n", (int)action.getArgument()); } else { // printf("setTime cb=%d p=%d\r\n", (int)callback, (int)param); } @@ -84,8 +84,8 @@ static void doScheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t } } -void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { - doScheduleForLater(scheduling, delayUs, callback, param); +void SleepExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { + doScheduleForLater(scheduling, delayUs, action); } #endif /* EFI_SIGNAL_EXECUTOR_SLEEP */ diff --git a/firmware/controllers/system/timer/signal_executor_sleep.h b/firmware/controllers/system/timer/signal_executor_sleep.h index cd23158e3a..2a48c902fe 100644 --- a/firmware/controllers/system/timer/signal_executor_sleep.h +++ b/firmware/controllers/system/timer/signal_executor_sleep.h @@ -12,8 +12,8 @@ class SleepExecutor : public ExecutorInterface { public: - void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) override; - void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) override; + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; + void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override; }; #endif /* SIGNAL_EXECUTOR_SLEEP_H_ */ diff --git a/firmware/controllers/system/timer/single_timer_executor.cpp b/firmware/controllers/system/timer/single_timer_executor.cpp index 0bebb2a226..b4553cad1e 100644 --- a/firmware/controllers/system/timer/single_timer_executor.cpp +++ b/firmware/controllers/system/timer/single_timer_executor.cpp @@ -66,8 +66,8 @@ 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); +void SingleTimerExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, action); } /** @@ -80,8 +80,7 @@ void SingleTimerExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs * @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 SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, - void *param) { +void SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) { ScopePerf perf(PE::SingleTimerExecutorScheduleByTimestamp); scheduleCounter++; @@ -90,7 +89,7 @@ void SingleTimerExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeu // this would guard the queue and disable interrupts alreadyLocked = lockAnyContext(); } - bool needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), callback, param); + bool needToResetTimer = queue.insertTask(scheduling, US2NT(timeUs), action); if (!reentrantFlag) { doExecute(); if (needToResetTimer) { diff --git a/firmware/controllers/system/timer/single_timer_executor.h b/firmware/controllers/system/timer/single_timer_executor.h index cb844c3d76..2f19283785 100644 --- a/firmware/controllers/system/timer/single_timer_executor.h +++ b/firmware/controllers/system/timer/single_timer_executor.h @@ -14,8 +14,8 @@ class SingleTimerExecutor : public ExecutorInterface { public: SingleTimerExecutor(); - void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) override; - void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) override; + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; + void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override; void onTimerCallback(); int timerCallbackCounter; int scheduleCounter; diff --git a/firmware/hw_layer/hip9011.cpp b/firmware/hw_layer/hip9011.cpp index 516ca72997..6479e109e8 100644 --- a/firmware/hw_layer/hip9011.cpp +++ b/firmware/hw_layer/hip9011.cpp @@ -223,7 +223,7 @@ void setHip9011FrankensoPinout(void) { } } -static void startIntegration(void) { +static void startIntegration(void *) { if (instance.state == READY_TO_INTEGRATE) { /** * SPI communication is only allowed while not integrating, so we postpone the exchange @@ -234,7 +234,7 @@ static void startIntegration(void) { } } -static void endIntegration(void) { +static void endIntegration(void *) { /** * isIntegrating could be 'false' if an SPI command was pending thus we did not integrate during this * engine cycle @@ -262,13 +262,12 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE int structIndex = getRevolutionCounter() % 2; // todo: schedule this based on closest trigger event, same as ignition works scheduleByAngle(&startTimer[structIndex], engineConfiguration->knockDetectionWindowStart, - (schfunc_t) &startIntegration, NULL); + &startIntegration); #if EFI_PROD_CODE hipLastExecutionCount = lastExecutionCount; #endif /* EFI_PROD_CODE */ scheduleByAngle(&endTimer[structIndex], engineConfiguration->knockDetectionWindowEnd, - (schfunc_t) &endIntegration, - NULL); + &endIntegration); engine->m.hipCbTime = getTimeNowLowerNt() - engine->m.beforeHipCb; } diff --git a/firmware/hw_layer/microsecond_timer.cpp b/firmware/hw_layer/microsecond_timer.cpp index 9887834c28..2d2ed5082c 100644 --- a/firmware/hw_layer/microsecond_timer.cpp +++ b/firmware/hw_layer/microsecond_timer.cpp @@ -167,7 +167,7 @@ static void watchDogBuddyCallback(void *arg) { * watchdog happy by ensuring that we have scheduler activity even in case of very broken configuration * without any PWM or input pins */ - engine->executor.scheduleForLater(&watchDogBuddy, MS2US(1000), watchDogBuddyCallback, NULL); + engine->executor.scheduleForLater(&watchDogBuddy, MS2US(1000), watchDogBuddyCallback); } static volatile bool testSchedulingHappened = false; @@ -195,7 +195,7 @@ static void validateHardwareTimer() { testSchedulingStart = currentTimeMillis(); // to save RAM let's use 'watchDogBuddy' here once before we enable watchdog - engine->executor.scheduleForLater(&watchDogBuddy, MS2US(TEST_CALLBACK_DELAY), timerValidationCallback, NULL); + engine->executor.scheduleForLater(&watchDogBuddy, MS2US(TEST_CALLBACK_DELAY), timerValidationCallback); chThdSleepMilliseconds(2 * TEST_CALLBACK_DELAY); if (!testSchedulingHappened) { diff --git a/firmware/hw_layer/servo.cpp b/firmware/hw_layer/servo.cpp index 0a398eb3f3..d9bc04edfb 100644 --- a/firmware/hw_layer/servo.cpp +++ b/firmware/hw_layer/servo.cpp @@ -61,7 +61,7 @@ static msg_t seThread(void *arg) { float durationMs = 0 + position * 0.02f; - engine->executor.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 7002988abc..859ee3fbe2 100644 --- a/unit_tests/global_execution_queue.cpp +++ b/unit_tests/global_execution_queue.cpp @@ -10,11 +10,11 @@ bool_t debugSignalExecutor = false; extern bool verboseMode; -void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) { +void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) { if (debugSignalExecutor) { printf("scheduleTask %d\r\n", delayUs); } - scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param); + scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, action); } int TestExecutor::executeAll(efitime_t now) { @@ -33,9 +33,9 @@ scheduling_s* TestExecutor::getForUnitTest(int index) { return schedulingQueue.getElementAtIndexForUnitText(index); } -void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) { +void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) { if (debugSignalExecutor) { printf("scheduleByTime %d\r\n", timeUs); } - schedulingQueue.insertTask(scheduling, timeUs, callback, param); + schedulingQueue.insertTask(scheduling, timeUs, action); } diff --git a/unit_tests/global_execution_queue.h b/unit_tests/global_execution_queue.h index c8a605c021..27753880bf 100644 --- a/unit_tests/global_execution_queue.h +++ b/unit_tests/global_execution_queue.h @@ -13,8 +13,8 @@ class TestExecutor : public ExecutorInterface { public: - void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) override; - void scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) override; + void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override; + void scheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) override; void clear(); int executeAll(efitime_t now); int size(); diff --git a/unit_tests/tests/test_signal_executor.cpp b/unit_tests/tests/test_signal_executor.cpp index 3c35b17759..9415e44449 100644 --- a/unit_tests/tests/test_signal_executor.cpp +++ b/unit_tests/tests/test_signal_executor.cpp @@ -34,7 +34,7 @@ static void complexCallback(TestPwm *testPwm) { callbackCounter++; eq.insertTask(&testPwm->s, complexTestNow + testPwm->period, - (schfunc_t) complexCallback, testPwm); + { (schfunc_t) complexCallback, testPwm }); } static void testSignalExecutor2(void) { @@ -47,8 +47,8 @@ static void testSignalExecutor2(void) { complexTestNow = 0; callbackCounter = 0; - eq.insertTask(&p1.s, 0, (schfunc_t) complexCallback, &p1); - eq.insertTask(&p2.s, 0, (schfunc_t) complexCallback, &p2); + eq.insertTask(&p1.s, 0, { (schfunc_t) complexCallback, &p1 }); + eq.insertTask(&p2.s, 0, { (schfunc_t) complexCallback, &p2 }); eq.executeAll(complexTestNow); ASSERT_EQ( 2, callbackCounter) << "callbackCounter #1"; ASSERT_EQ(2, eq.size()); @@ -83,9 +83,9 @@ static void testSignalExecutor3(void) { scheduling_s s2; scheduling_s s3; - eq.insertTask(&s1, 10, orderCallback, (void*)1); - eq.insertTask(&s2, 11, orderCallback, (void*)2); - eq.insertTask(&s3, 12, orderCallback, (void*)3); + eq.insertTask(&s1, 10, { orderCallback, (void*)1 }); + eq.insertTask(&s2, 11, { orderCallback, (void*)2 }); + eq.insertTask(&s3, 12, { orderCallback, (void*)3 }); eq.executeAll(100); } @@ -101,10 +101,10 @@ TEST(misc, testSignalExecutor) { scheduling_s s3; scheduling_s s4; - eq.insertTask(&s1, 10, callback, NULL); - eq.insertTask(&s4, 10, callback, NULL); - eq.insertTask(&s3, 12, callback, NULL); - eq.insertTask(&s2, 11, callback, NULL); + eq.insertTask(&s1, 10, callback); + eq.insertTask(&s4, 10, callback); + eq.insertTask(&s3, 12, callback); + eq.insertTask(&s2, 11, callback); ASSERT_EQ(4, eq.size()); ASSERT_EQ(10, eq.getHead()->momentX); @@ -121,9 +121,9 @@ TEST(misc, testSignalExecutor) { eq.executeAll(100); ASSERT_EQ(0, eq.size()); - eq.insertTask(&s1, 12, callback, NULL); - eq.insertTask(&s2, 11, callback, NULL); - eq.insertTask(&s3, 10, callback, NULL); + eq.insertTask(&s1, 12, callback); + eq.insertTask(&s2, 11, callback); + eq.insertTask(&s3, 10, callback); callbackCounter = 0; eq.executeAll(10); ASSERT_EQ( 1, callbackCounter) << "callbackCounter/1#2"; @@ -134,7 +134,7 @@ TEST(misc, testSignalExecutor) { ASSERT_EQ(0, eq.size()); callbackCounter = 0; - eq.insertTask(&s1, 10, callback, NULL); + eq.insertTask(&s1, 10, callback); ASSERT_EQ(10, eq.getNextEventTime(0)); eq.executeAll(1); @@ -145,8 +145,8 @@ TEST(misc, testSignalExecutor) { ASSERT_EQ(EMPTY_QUEUE, eq.getNextEventTime(0)); - eq.insertTask(&s1, 10, callback, NULL); - eq.insertTask(&s2, 13, callback, NULL); + eq.insertTask(&s1, 10, callback); + eq.insertTask(&s2, 13, callback); ASSERT_EQ(10, eq.getNextEventTime(0)); eq.executeAll(1); @@ -156,8 +156,8 @@ TEST(misc, testSignalExecutor) { ASSERT_EQ(0, eq.size()); callbackCounter = 0; // both events are scheduled for the same time - eq.insertTask(&s1, 10, callback, NULL); - eq.insertTask(&s2, 10, callback, NULL); + eq.insertTask(&s1, 10, callback); + eq.insertTask(&s2, 10, callback); eq.executeAll(11);