The Big Refactoring of 2019: scheduler should not be global #655
This commit is contained in:
parent
dbac37c59d
commit
5ffcc396eb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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__)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Loading…
Reference in New Issue