rusEFI
The most advanced open source ECU
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
SingleTimerExecutor Class Referencefinal

#include <single_timer_executor.h>

Inheritance diagram for SingleTimerExecutor:
Inheritance graph
[legend]
Collaboration diagram for SingleTimerExecutor:
Collaboration graph
[legend]

Public Member Functions

 SingleTimerExecutor ()
 
void scheduleByTimestamp (const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override
 Schedule an event at specific delay after now. More...
 
void scheduleByTimestampNt (const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) override
 
void scheduleForLater (const char *msg, scheduling_s *scheduling, int delayUs, action_s action) override
 
void cancel (scheduling_s *scheduling) override
 
void onTimerCallback ()
 

Data Fields

int timerCallbackCounter = 0
 
int scheduleCounter = 0
 
int maxExecuteCounter = 0
 
int executeCounter
 
int executeAllPendingActionsInvocationCounter = 0
 

Private Member Functions

void executeAllPendingActions ()
 
void scheduleTimerCallback ()
 

Private Attributes

EventQueue queue
 
bool reentrantFlag = false
 

Detailed Description

Definition at line 13 of file single_timer_executor.h.

Constructor & Destructor Documentation

◆ SingleTimerExecutor()

SingleTimerExecutor::SingleTimerExecutor ( )

Definition at line 42 of file single_timer_executor.cpp.

44  : queue(US2NT(8))
45 {
46 }

Member Function Documentation

◆ cancel()

void SingleTimerExecutor::cancel ( scheduling_s scheduling)
overridevirtual

Implements ExecutorInterface.

Definition at line 94 of file single_timer_executor.cpp.

94  {
95  // Lock for queue removal - we may already be locked, but that's ok
96  chibios_rt::CriticalSectionLocker csl;
97 
98  queue.remove(scheduling);
99 }
void remove(scheduling_s *scheduling)

Referenced by TriggerScheduler::scheduleEventsUntilNextTriggerTooth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeAllPendingActions()

void SingleTimerExecutor::executeAllPendingActions ( )
private

Let's execute actions we should execute at this point. reentrantFlag takes care of the use case where the actions we are executing are scheduling further invocations

in real life it could be that while we executing listeners time passes and it's already time to execute next listeners. TODO: add a counter & figure out a limit of iterations?

Definition at line 113 of file single_timer_executor.cpp.

113  {
115 
117  /**
118  * Let's execute actions we should execute at this point.
119  * reentrantFlag takes care of the use case where the actions we are executing are scheduling
120  * further invocations
121  */
122  reentrantFlag = true;
123 
124  /**
125  * in real life it could be that while we executing listeners time passes and it's already time to execute
126  * next listeners.
127  * TODO: add a counter & figure out a limit of iterations?
128  */
129 
130  // starts at -1 because do..while will run a minimum of once
131  executeCounter = -1;
132 
133  bool didExecute;
134  do {
135  efitick_t nowNt = getTimeNowNt();
136  didExecute = queue.executeOne(nowNt);
137 
138  // if we're stuck in a loop executing lots of events, panic!
139  if (executeCounter++ == 500) {
140  firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Maximum scheduling run length exceeded - CPU load too high");
141  }
142 
143  } while (didExecute);
144 
146 
147  if (!isLocked()) {
148  firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock");
149  return;
150  }
151  reentrantFlag = false;
152 }
bool executeOne(efitick_t now)
efitick_t getTimeNowNt()
Definition: efitime.cpp:19
void firmwareError(ObdCode code, const char *fmt,...)
static bool isLocked
Definition: flash_int.cpp:22
@ CUSTOM_ERR_LOCK_ISSUE
@ SingleTimerExecutorDoExecute

Referenced by onTimerCallback(), and scheduleByTimestampNt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onTimerCallback()

void SingleTimerExecutor::onTimerCallback ( )

Definition at line 101 of file single_timer_executor.cpp.

101  {
103 
104  chibios_rt::CriticalSectionLocker csl;
105 
108 }

Referenced by globalTimerCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleByTimestamp()

void SingleTimerExecutor::scheduleByTimestamp ( const char *  msg,
scheduling_s scheduling,
efitimeus_t  timeUs,
action_s  action 
)
overridevirtual

Schedule an event at specific delay after now.

Invokes event callback after the specified amount of time. callback would be executed either on ISR thread or current thread if we would need to execute right away

Parameters
[in,out]schedulingData structure to keep this event in the collection.
[in]delayUsthe number of microseconds before the output signal immediate output if delay is zero.
[in]dwellthe number of ticks of output duration.

Implements ExecutorInterface.

Definition at line 62 of file single_timer_executor.cpp.

62  {
63  scheduleByTimestampNt(msg, scheduling, US2NT(timeUs), action);
64 }
void scheduleByTimestampNt(const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s action) override

Referenced by scheduleForLater(), and toggleTestAndScheduleNext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleByTimestampNt()

void SingleTimerExecutor::scheduleByTimestampNt ( const char *  msg,
scheduling_s scheduling,
efitick_t  timeNt,
action_s  action 
)
overridevirtual

Implements ExecutorInterface.

Definition at line 66 of file single_timer_executor.cpp.

66  {
68 
69 #if EFI_ENABLE_ASSERTS
70  efidur_t deltaTimeNt = nt - getTimeNowNt();
71 
72  if (deltaTimeNt >= TOO_FAR_INTO_FUTURE_NT) {
73  // we are trying to set callback for too far into the future. This does not look right at all
74  int32_t intDeltaTimeNt = (int32_t)deltaTimeNt;
75  firmwareError(ObdCode::CUSTOM_ERR_TASK_TIMER_OVERFLOW, "scheduleByTimestampNt() too far: %d %s", intDeltaTimeNt, msg);
76  return;
77  }
78 #endif
79 
81 
82  // Lock for queue insertion - we may already be locked, but that's ok
83  chibios_rt::CriticalSectionLocker csl;
84 
85  bool needToResetTimer = queue.insertTask(scheduling, nt, action);
86  if (!reentrantFlag) {
88  if (needToResetTimer) {
90  }
91  }
92 }
bool insertTask(scheduling_s *scheduling, efitick_t timeX, action_s action)
Definition: event_queue.cpp:66
@ CUSTOM_ERR_TASK_TIMER_OVERFLOW
@ SingleTimerExecutorScheduleByTimestamp
efitick_t efidur_t
Definition: rusefi_types.h:45

Referenced by fireSparkAndPrepareNextSchedule(), runBench(), scheduleByAngle(), scheduleByTimestamp(), and triggerScopeGetBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleForLater()

void SingleTimerExecutor::scheduleForLater ( const char *  msg,
scheduling_s scheduling,
int  delayUs,
action_s  action 
)
overridevirtual

Implements ExecutorInterface.

Definition at line 48 of file single_timer_executor.cpp.

48  {
49  scheduleByTimestamp(msg, scheduling, getTimeNowUs() + delayUs, action);
50 }
void scheduleByTimestamp(const char *msg, scheduling_s *scheduling, efitimeus_t timeUs, action_s action) override
Schedule an event at specific delay after now.
efitimeus_t getTimeNowUs()
Definition: efitime.cpp:26

Referenced by initPwmTester(), testCallback(), validateHardwareTimer(), and watchDogBuddyCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleTimerCallback()

void SingleTimerExecutor::scheduleTimerCallback ( )
private

This method is always invoked under a lock

Let's grab fresh time value

Definition at line 157 of file single_timer_executor.cpp.

157  {
159 
160  /**
161  * Let's grab fresh time value
162  */
163  efitick_t nowNt = getTimeNowNt();
164  expected<efitick_t> nextEventTimeNt = queue.getNextEventTime(nowNt);
165 
166  if (!nextEventTimeNt) {
167  return; // no pending events in the queue
168  }
169 
170  efiAssertVoid(ObdCode::CUSTOM_ERR_6625, nextEventTimeNt.Value > nowNt, "setTimer constraint");
171 
172  setHardwareSchedulerTimer(nowNt, nextEventTimeNt.Value);
173 }
expected< efitick_t > getNextEventTime(efitick_t nowUs) const
void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt)
@ CUSTOM_ERR_6625
@ SingleTimerExecutorScheduleTimerCallback

Referenced by onTimerCallback(), and scheduleByTimestampNt().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ executeAllPendingActionsInvocationCounter

int SingleTimerExecutor::executeAllPendingActionsInvocationCounter = 0

Definition at line 26 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ executeCounter

int SingleTimerExecutor::executeCounter

Definition at line 25 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ maxExecuteCounter

int SingleTimerExecutor::maxExecuteCounter = 0

Definition at line 24 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ queue

EventQueue SingleTimerExecutor::queue
private

◆ reentrantFlag

bool SingleTimerExecutor::reentrantFlag = false
private

Definition at line 29 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and scheduleByTimestampNt().

◆ scheduleCounter

int SingleTimerExecutor::scheduleCounter = 0

Definition at line 23 of file single_timer_executor.h.

Referenced by executorStatistics(), and scheduleByTimestampNt().

◆ timerCallbackCounter

int SingleTimerExecutor::timerCallbackCounter = 0

Definition at line 22 of file single_timer_executor.h.

Referenced by executorStatistics(), and onTimerCallback().


The documentation for this class was generated from the following files: