one step towards https://github.com/rusefi/rusefi/pull/4841/files#diff-63e5fe040b8a611e8897c2f4d455c248e6e4c6ee377f04ef30ada43e1dad3c61
This commit is contained in:
parent
c20e59cea7
commit
d678c49a13
|
@ -32,6 +32,12 @@ bool printSchedulerDebug = true;
|
||||||
|
|
||||||
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
||||||
|
|
||||||
|
struct CallbackContext
|
||||||
|
{
|
||||||
|
scheduling_s* scheduling = nullptr;
|
||||||
|
bool shouldFree = false;
|
||||||
|
};
|
||||||
|
|
||||||
void SleepExecutor::scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) {
|
void SleepExecutor::scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) {
|
||||||
scheduleForLater(msg, scheduling, timeUs - getTimeNowUs(), action);
|
scheduleForLater(msg, scheduling, timeUs - getTimeNowUs(), action);
|
||||||
}
|
}
|
||||||
|
@ -40,18 +46,30 @@ void SleepExecutor::scheduleByTimestampNt(const char *msg, scheduling_s* schedul
|
||||||
scheduleByTimestamp(msg, scheduling, NT2US(timeNt), action);
|
scheduleByTimestamp(msg, scheduling, NT2US(timeNt), action);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void timerCallback(scheduling_s *scheduling) {
|
static void timerCallback(CallbackContext* ctx) {
|
||||||
#if EFI_PRINTF_FUEL_DETAILS
|
#if EFI_PRINTF_FUEL_DETAILS
|
||||||
if (printSchedulerDebug) {
|
if (printSchedulerDebug) {
|
||||||
if (scheduling->action.getCallback() == (schfunc_t)&turnInjectionPinLow) {
|
if (ctx->scheduling->action.getCallback() == (schfunc_t)&turnInjectionPinLow) {
|
||||||
printf("executing cb=turnInjectionPinLow p=%d sch=%d now=%d\r\n", (int)scheduling->action.getArgument(), (int)scheduling,
|
printf("executing cb=turnInjectionPinLow p=%d sch=%d now=%d\r\n", (int)ctx->scheduling->action.getArgument(), (int)scheduling,
|
||||||
(int)getTimeNowUs());
|
(int)getTimeNowUs());
|
||||||
} else {
|
} else {
|
||||||
// printf("exec cb=%d p=%d\r\n", (int)scheduling->callback, (int)scheduling->param);
|
// printf("exec cb=%d p=%d\r\n", (int)scheduling->callback, (int)scheduling->param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // EFI_PRINTF_FUEL_DETAILS
|
#endif // EFI_PRINTF_FUEL_DETAILS
|
||||||
scheduling->action.execute();
|
|
||||||
|
// Grab the action but clear it in the event so we can reschedule from the action's execution
|
||||||
|
action_s action = ctx->scheduling->action;
|
||||||
|
ctx->scheduling->action = {};
|
||||||
|
|
||||||
|
// Clean up any memory we allocated
|
||||||
|
if (ctx->shouldFree) {
|
||||||
|
delete ctx->scheduling;
|
||||||
|
}
|
||||||
|
delete ctx;
|
||||||
|
|
||||||
|
// Lastly, actually execute the action
|
||||||
|
action.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) {
|
static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s action) {
|
||||||
|
@ -66,6 +84,16 @@ static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s a
|
||||||
|
|
||||||
chibios_rt::CriticalSectionLocker csl;
|
chibios_rt::CriticalSectionLocker csl;
|
||||||
|
|
||||||
|
// ECU firmware does not use heap. this sleep-based executor is used only by simulator
|
||||||
|
// todo: probably move this executor to 'simulator' folder to make it official?
|
||||||
|
auto ctx = new CallbackContext;
|
||||||
|
if (!scheduling) {
|
||||||
|
scheduling = new scheduling_s;
|
||||||
|
chVTObjectInit(&scheduling->timer);
|
||||||
|
ctx->shouldFree = true;
|
||||||
|
}
|
||||||
|
ctx->scheduling = scheduling;
|
||||||
|
|
||||||
scheduling->action = action;
|
scheduling->action = action;
|
||||||
int isArmed = chVTIsArmedI(&scheduling->timer);
|
int isArmed = chVTIsArmedI(&scheduling->timer);
|
||||||
if (isArmed) {
|
if (isArmed) {
|
||||||
|
@ -83,7 +111,7 @@ static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s a
|
||||||
// }
|
// }
|
||||||
#endif /* EFI_SIMULATOR */
|
#endif /* EFI_SIMULATOR */
|
||||||
|
|
||||||
chVTSetI(&scheduling->timer, delaySt, (vtfunc_t)timerCallback, scheduling);
|
chVTSetI(&scheduling->timer, delaySt, (vtfunc_t)timerCallback, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SleepExecutor::scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) {
|
void SleepExecutor::scheduleForLater(const char *msg, scheduling_s *scheduling, int delayUs, action_s action) {
|
||||||
|
|
Loading…
Reference in New Issue