The Big Refactoring of 2019: scheduler should not be global #655

This commit is contained in:
rusefi 2019-01-09 10:17:35 -05:00
parent 3a52b14502
commit 7989763ee9
5 changed files with 17 additions and 23 deletions

View File

@ -156,15 +156,6 @@ void SingleTimerExecutor::scheduleTimerCallback() {
hwSetTimerDuration = GET_TIMESTAMP() - beforeHwSetTimer;
}
/**
* @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) {
_engine.executor.scheduleByTimestamp(scheduling, time, callback, param);
}
void initSignalExecutorImpl(void) {
globalTimerCallback = executorCallback;
initMicrosecondTimer();

View File

@ -223,10 +223,10 @@ static void timerCallback(PwmConfig *state) {
efiAssertVoid(CUSTOM_ERR_6581, state->dbgNestingLevel < 25, "PWM nesting issue");
efitimeus_t switchTimeUs = state->togglePwmState();
// if (state->executor == NULL) {
// firmwareError(CUSTOM_ERR_6695, "exec on %s", state->name);
// return;
// }
if (state->executor == NULL) {
firmwareError(CUSTOM_ERR_6695, "exec on %s", state->name);
return;
}
state->executor->scheduleByTimestamp(&state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state);
state->dbgNestingLevel--;

View File

@ -14,6 +14,10 @@ EventQueue schedulingQueue;
bool_t debugSignalExecutor = false;
TestExecutor::TestExecutor() {
}
void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleTask %d\r\n", delayUs);
@ -21,6 +25,11 @@ void TestExecutor::scheduleForLater(scheduling_s *scheduling, int delayUs, schfu
scheduleByTimestamp(scheduling, getTimeNowUs() + delayUs, callback, param);
}
void TestExecutor::clear() {
schedulingQueue.clear();
}
void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t timeUs, schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleByTime %d\r\n", timeUs);
@ -28,14 +37,6 @@ void TestExecutor::scheduleByTimestamp(scheduling_s *scheduling, efitimeus_t tim
schedulingQueue.insertTask(scheduling, timeUs, callback, param);
}
void scheduleByTimestamp(scheduling_s *scheduling,
efitimeus_t timeUs, schfunc_t callback, void *param) {
if (debugSignalExecutor) {
printf("scheduleByTime %d\r\n", timeUs);
}
schedulingQueue.insertTask(scheduling, timeUs, callback, param);
}
void initSignalExecutorImpl(void) {
}

View File

@ -12,8 +12,10 @@
class TestExecutor : public ExecutorInterface {
public:
TestExecutor();
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 clear();
};
#endif /* GLOBAL_EXECUTION_QUEUE_H_ */

View File

@ -381,7 +381,7 @@ void testRpmCalculator(void) {
}
schedulingQueue.clear();
engine->executor.clear();
eth.fireFall(5);
eth.fireRise(5);
@ -391,7 +391,7 @@ void testRpmCalculator(void) {
assertEqualsM("ev 3", start + 13333 - 1515, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM2("ev 5", start + 14277, schedulingQueue.getForUnitText(1)->momentX, 2);
assertEqualsM("3/3", start + 14777, schedulingQueue.getForUnitText(2)->momentX);
schedulingQueue.clear();
engine->executor.clear();
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[240]));
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[241]));