rusEFI
The most advanced open source ECU
|
Base class for a controller that needs to run periodically to perform work. More...
#include <periodic_thread_controller.h>
Public Member Functions | |
PeriodicController (const char *name, tprio_t priority, float frequencyHz) | |
PeriodicController (const char *name) | |
void | setPeriod (int periodMs) |
![]() | |
ThreadController (const char *name, tprio_t priority) | |
void | start () |
Start the thread. | |
void | stop () |
Request thread termination and waits for termination. | |
Protected Member Functions | |
virtual void | OnStarted () |
Called before running the periodic task. Optionally override this method to set up. | |
virtual void | PeriodicTask (efitick_t nowNt)=0 |
Called periodically. Override this method to do work for your controller. | |
![]() | |
void | main () override |
Private Member Functions | |
void | ThreadTask () override final |
Private Attributes | |
systime_t | m_period |
Additional Inherited Members | |
![]() | |
const char *const | m_name |
Base class for a controller that needs to run periodically to perform work.
For example, if we have some PID loop that needs to run at a specified frequency, inherit this class, and perform your period update in PeriodicTask. Any one-time setup work can be performed in OnStarted().
Each instance has one underlying thread meaning that task could be blocking/synchronous. This class effectively implements this functionality:
void thread() { OnStarted();
while(true) { PeriodicTask(getTimeNowNt()); sleep(); } }
Definition at line 36 of file periodic_thread_controller.h.
|
inline |
Definition at line 82 of file periodic_thread_controller.h.
|
inline |
Definition at line 89 of file periodic_thread_controller.h.
|
inlineprotectedvirtual |
Called before running the periodic task. Optionally override this method to set up.
Definition at line 47 of file periodic_thread_controller.h.
Referenced by PeriodicController< TStackSize >::ThreadTask().
|
protectedpure virtual |
Called periodically. Override this method to do work for your controller.
Implemented in CanWrite, and MainLoop.
Referenced by PeriodicController< TStackSize >::ThreadTask().
|
inline |
sets milliseconds period
Definition at line 95 of file periodic_thread_controller.h.
|
inlinefinaloverrideprivatevirtual |
Implements ThreadController< TStackSize >.
Definition at line 55 of file periodic_thread_controller.h.
|
private |
Definition at line 40 of file periodic_thread_controller.h.
Referenced by PeriodicController< TStackSize >::ThreadTask().