Pass action_s instead of callback/param (#1084)

* change action

* consumers

* fix test

* didn't mean to add those

* simplify

* fix simulator

* fix sim for real

* oy

* maybe this time the simulator will actually be fixed, for real

* don't rely on undefined behavior
This commit is contained in:
Matthew Kennedy 2020-01-06 21:41:18 -08:00 committed by rusefi
parent d218b4e8e6
commit 6703705a33
25 changed files with 95 additions and 103 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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);

View File

@ -34,8 +34,7 @@ void plainPinTurnOn(AuxActor *current) {
scheduleOrQueue(&current->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(&current->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
);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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--;
}

View File

@ -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;
};

View File

@ -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 */

View File

@ -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_ */

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}

View File

@ -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();

View File

@ -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);