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
|
* 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) {
|
void initPwmTester(void) {
|
||||||
|
@ -97,7 +97,7 @@ void initPwmTester(void) {
|
||||||
/**
|
/**
|
||||||
* this would schedule a callback in 2ms from now
|
* 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
|
#endif
|
||||||
|
|
|
@ -62,6 +62,10 @@ SingleTimerExecutor::SingleTimerExecutor() {
|
||||||
queue.setLateDelay(US2NT(100));
|
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
|
* 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:
|
public:
|
||||||
SingleTimerExecutor();
|
SingleTimerExecutor();
|
||||||
void scheduleByTimestamp(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 scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
||||||
void onTimerCallback();
|
void onTimerCallback();
|
||||||
int timerCallbackCounter;
|
int timerCallbackCounter;
|
||||||
int scheduleCounter;
|
int scheduleCounter;
|
||||||
|
|
|
@ -36,6 +36,7 @@ void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t time, schfunc_t c
|
||||||
|
|
||||||
class ExecutorInterface {
|
class ExecutorInterface {
|
||||||
virtual void scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) = 0;
|
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_ */
|
#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) {
|
void initSignalExecutorImpl(void) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
class SleepExecutor : public ExecutorInterface {
|
class SleepExecutor : public ExecutorInterface {
|
||||||
public:
|
public:
|
||||||
void scheduleByTimestamp(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 scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SIGNAL_EXECUTOR_SLEEP_H_ */
|
#endif /* SIGNAL_EXECUTOR_SLEEP_H_ */
|
||||||
|
|
|
@ -34,7 +34,7 @@ static void tachSignalCallback(trigger_event_e ckpSignalType,
|
||||||
} else {
|
} else {
|
||||||
durationMs = engineConfiguration->tachPulseDuractionMs;
|
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) {
|
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);
|
printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling);
|
||||||
#endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */
|
#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,
|
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;
|
// todo: sequential need this logic as well, just do not forget to clear flag pair->isScheduled = true;
|
||||||
scheduling_s * sDown = &pair->signalTimerDown;
|
scheduling_s * sDown = &pair->signalTimerDown;
|
||||||
|
|
||||||
scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine);
|
engine->executor.scheduleForLater(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, engine);
|
||||||
scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs,
|
engine->executor.scheduleForLater(sDown, (int) injectionStartDelayUs + durationUs,
|
||||||
(schfunc_t) &endSimultaniousInjection, event);
|
(schfunc_t) &endSimultaniousInjection, event);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -579,7 +579,7 @@ void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
if (pulseLength > 0) {
|
if (pulseLength > 0) {
|
||||||
startSimultaniousInjection(engine);
|
startSimultaniousInjection(engine);
|
||||||
efitimeus_t turnOffDelayUs = (efitimeus_t)efiRound(MS2US(pulseLength), 1.0f);
|
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__)
|
#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
|
* This way we make sure that coil dwell started while spark was enabled would fire and not burn
|
||||||
* the coil.
|
* 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
|
* 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);
|
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 */
|
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||||
|
|
||||||
scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent);
|
engine->executor.scheduleForLater(sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnSparkPinLow, iEvent);
|
||||||
} else {
|
} else {
|
||||||
#if SPARK_EXTREME_LOGGING || defined(__DOXYGEN__)
|
#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);
|
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;
|
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;
|
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);
|
chThdSleepMilliseconds(19);
|
||||||
|
|
|
@ -22,19 +22,26 @@ void scheduleForLater(scheduling_s *scheduling, int delayUs,
|
||||||
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
|
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) {
|
void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) {
|
||||||
if (debugSignalExecutor) {
|
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,
|
void scheduleByTimestamp(scheduling_s *scheduling,
|
||||||
efitimeus_t time, schfunc_t callback, void *param) {
|
efitimeus_t timeUs, schfunc_t callback, void *param) {
|
||||||
if (debugSignalExecutor) {
|
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) {
|
void initSignalExecutorImpl(void) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
class TestExecutor : public ExecutorInterface {
|
class TestExecutor : public ExecutorInterface {
|
||||||
public:
|
public:
|
||||||
void scheduleByTimestamp(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 scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GLOBAL_EXECUTION_QUEUE_H_ */
|
#endif /* GLOBAL_EXECUTION_QUEUE_H_ */
|
||||||
|
|
Loading…
Reference in New Issue