2021-11-18 11:27:21 -08:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-05 19:32:20 -07:00
|
|
|
// TriggerScheduler here is an intermediate tooth-based scheduler working on top of time-base scheduler
|
|
|
|
// *kludge*: individual event for *Trigger*Scheduler is called *Angle*BasedEvent. Shall we rename to ToothSchedule and ToothBasedEvent?
|
2021-11-18 11:27:21 -08:00
|
|
|
class TriggerScheduler : public EngineModule {
|
|
|
|
public:
|
2023-10-05 19:32:20 -07:00
|
|
|
// *kludge* we have three methods with *schedule* in the name meaning three different things
|
|
|
|
// this method just places event into the collection of tooth-based events
|
2023-10-05 19:58:18 -07:00
|
|
|
void schedule(const char *msg, AngleBasedEvent* event, angle_t angle, action_s action);
|
2022-09-20 02:28:23 -07:00
|
|
|
|
2023-10-05 19:32:20 -07:00
|
|
|
// 'schedule' means 'delegates to time-based scheduler' and 'queue' here matches the 'schedule' method above
|
2023-10-05 19:58:18 -07:00
|
|
|
bool scheduleOrQueue(const char *msg, AngleBasedEvent *event,
|
2021-11-18 11:27:21 -08:00
|
|
|
efitick_t edgeTimestamp,
|
|
|
|
angle_t angle,
|
2022-09-25 08:00:55 -07:00
|
|
|
action_s action,
|
|
|
|
float currentPhase, float nextPhase);
|
2021-11-18 11:27:21 -08:00
|
|
|
|
2023-10-05 19:32:20 -07:00
|
|
|
// scheduleForActualTimeBasedExecution using underlying time-base scheduler
|
2021-11-18 11:27:21 -08:00
|
|
|
void scheduleEventsUntilNextTriggerTooth(int rpm,
|
2022-09-20 02:28:23 -07:00
|
|
|
efitick_t edgeTimestamp,
|
|
|
|
float currentPhase, float nextPhase);
|
2021-11-18 11:27:21 -08:00
|
|
|
|
2023-10-05 19:03:41 -07:00
|
|
|
#if EFI_UNIT_TEST
|
2022-12-10 14:07:02 -08:00
|
|
|
AngleBasedEvent * getElementAtIndexForUnitTest(int index);
|
2023-10-05 19:03:41 -07:00
|
|
|
#endif // EFI_UNIT_TEST
|
2021-11-18 11:27:21 -08:00
|
|
|
|
|
|
|
private:
|
2023-10-05 19:58:18 -07:00
|
|
|
void schedule(const char *msg, AngleBasedEvent* event, action_s action);
|
2022-11-28 05:55:38 -08:00
|
|
|
|
2022-12-10 14:07:02 -08:00
|
|
|
bool assertNotInList(AngleBasedEvent *head, AngleBasedEvent *element);
|
2021-11-18 11:27:21 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* That's the linked list of pending events scheduled in relation to trigger
|
|
|
|
* At the moment we iterate over the whole list while looking for events for specific
|
|
|
|
* trigger index We can make it an array of lists per trigger index, but that would take
|
|
|
|
* some RAM and probably not needed yet.
|
|
|
|
*/
|
2022-12-10 14:07:02 -08:00
|
|
|
AngleBasedEvent *m_angleBasedEventsHead = nullptr;
|
2021-11-18 11:27:21 -08:00
|
|
|
};
|