auto-sync
This commit is contained in:
parent
88e4a07234
commit
dd5d1462e3
|
@ -43,26 +43,31 @@ void Executor::unlock(void) {
|
|||
unlockAnyContext();
|
||||
}
|
||||
|
||||
void Executor::schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param) {
|
||||
if (delayUs < 0) {
|
||||
firmwareError("Negative delayUs %s: %d", prefix, delayUs);
|
||||
return;
|
||||
}
|
||||
if (delayUs == 0) {
|
||||
callback(param);
|
||||
return;
|
||||
}
|
||||
void Executor::schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param) {
|
||||
// if (delayUs < 0) {
|
||||
// firmwareError("Negative delayUs %s: %d", prefix, delayUs);
|
||||
// return;
|
||||
// }
|
||||
// if (delayUs == 0) {
|
||||
// callback(param);
|
||||
// return;
|
||||
// }
|
||||
if (!reentrantLock) {
|
||||
// this would guard the queue and disable interrupts
|
||||
lock();
|
||||
}
|
||||
queue.insertTask(scheduling, nowUs + delayUs, callback, param);
|
||||
queue.insertTask(scheduling, timeUs, callback, param);
|
||||
if (!reentrantLock) {
|
||||
doExecute(nowUs);
|
||||
doExecute(getTimeNowUs());
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Executor::schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param) {
|
||||
schedule2(prefix, scheduling, nowUs + delayUs, callback, param);
|
||||
}
|
||||
|
||||
void Executor::execute(uint64_t nowUs) {
|
||||
lock();
|
||||
doExecute(nowUs);
|
||||
|
@ -108,6 +113,11 @@ void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, sch
|
|||
instance.schedule(prefix, scheduling, getTimeNowUs(), delayUs, callback, param);
|
||||
}
|
||||
|
||||
void scheduleTask2(const char *prefix, scheduling_s *scheduling, uint64_t time, schfunc_t callback, void *param) {
|
||||
instance.schedule2(prefix, scheduling, time, callback, param);
|
||||
}
|
||||
|
||||
|
||||
void initSignalExecutorImpl(void) {
|
||||
globalTimerCallback = executorCallback;
|
||||
#if EFI_PROD_CODE
|
||||
|
|
|
@ -15,6 +15,7 @@ class Executor {
|
|||
public:
|
||||
Executor();
|
||||
void schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param);
|
||||
void schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param);
|
||||
void execute(uint64_t nowUs);
|
||||
private:
|
||||
EventQueue queue;
|
||||
|
|
|
@ -114,34 +114,34 @@ static uint64_t togglePwmState(PwmConfig *state) {
|
|||
scheduleMsg(&logger, "%s: nextSwitchTime %d", state->name, nextSwitchTime);
|
||||
#endif
|
||||
// signed value is needed here
|
||||
int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs();
|
||||
if (timeToSwitch < 1) {
|
||||
/**
|
||||
* We are here if we are late for a state transition.
|
||||
* At 12000RPM=200Hz with a 60 toothed wheel we need to change state every
|
||||
* 1000000 / 200 / 120 = ~41 uS. We are kind of OK.
|
||||
*
|
||||
* We are also here after a flash write. Flash write freezes the whole chip for a couple of seconds,
|
||||
* so PWM generation and trigger simulation generation would have to recover from this time lag.
|
||||
*/
|
||||
//todo: introduce error and test this error handling warning(OBD_PCM_Processor_Fault, "PWM: negative switch time");
|
||||
timeToSwitch = 10;
|
||||
}
|
||||
// int64_t timeToSwitch = nextSwitchTimeUs - getTimeNowUs();
|
||||
// if (timeToSwitch < 1) {
|
||||
// /**
|
||||
// * We are here if we are late for a state transition.
|
||||
// * At 12000RPM=200Hz with a 60 toothed wheel we need to change state every
|
||||
// * 1000000 / 200 / 120 = ~41 uS. We are kind of OK.
|
||||
// *
|
||||
// * We are also here after a flash write. Flash write freezes the whole chip for a couple of seconds,
|
||||
// * so PWM generation and trigger simulation generation would have to recover from this time lag.
|
||||
// */
|
||||
// //todo: introduce error and test this error handling warning(OBD_PCM_Processor_Fault, "PWM: negative switch time");
|
||||
// timeToSwitch = 10;
|
||||
// }
|
||||
|
||||
state->safe.phaseIndex++;
|
||||
if (state->safe.phaseIndex == state->phaseCount) {
|
||||
state->safe.phaseIndex = 0; // restart
|
||||
state->safe.iteration++;
|
||||
}
|
||||
return timeToSwitch;
|
||||
return nextSwitchTimeUs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main PWM loop: toggle pin & schedule next invocation
|
||||
*/
|
||||
static void timerCallback(PwmConfig *state) {
|
||||
time_t timeToSleepUs = togglePwmState(state);
|
||||
scheduleTask("pwm", &state->scheduling, timeToSleepUs, (schfunc_t) timerCallback, state);
|
||||
uint64_t switchTimeUs = togglePwmState(state);
|
||||
scheduleTask2("pwm", &state->scheduling, switchTimeUs, (schfunc_t) timerCallback, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,7 @@ extern "C"
|
|||
#endif /* __cplusplus */
|
||||
|
||||
void scheduleTask(const char *prefix, scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param);
|
||||
void scheduleTask2(const char *prefix, scheduling_s *scheduling, uint64_t time, schfunc_t callback, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue