PropWare
2.1.2
C++ objects and CMake build system for Parallax Propeller
|
Click here for docs on the
develop
branch.
#include <scheduler.h>
Public Member Functions | |
Scheduler (const int deci_hz) | |
__attribute__ ((always_inline)) bool Run(void) | |
Static Public Member Functions | |
static unsigned int | GetTicksPerPeriod (const int deci_hz) |
A pollable timer to help schedule events.
Definition at line 27 of file scheduler.h.
libpropeller::Scheduler::Scheduler | ( | const int | deci_hz | ) |
Create a schedule keeper that returns true with the specified frequency.
The frequency is specified in units of 0.1Hz. So, to create a scheduler with a frequency of 150Hz you pass in 1500. To make a scheduler with a frequency of 0.5Hz (once every two seconds), you pass in 5 (0.1Hz * 5 = 0.5Hz). A scheduler with a frequency of 1Hz takes a parameter of 10.
deci_hz | The frequency (in 10x true return values per second). |
Definition at line 41 of file scheduler.h.
libpropeller::Scheduler::__attribute__ | ( | (always_inline) | ) |
Check to see if the time period has passed yet.
This function is not blocking. This class keeps an internal state that watches the system counter, and if the next "period" has begun returns true the next time that this function is called. It then returns false for the rest of the current period.
This function is useful for scheduling reseting watchdog timers, determining when to poll external sensors, and so on.
The function returns true for each time period, so if it is not called for multiple time periods it returns true for each (up to hz times).
This function is set to always inline. Although it does increase code size by a few bytes (roughly 20 bytes per call location), it made some test code run 2x as fast.
Definition at line 66 of file scheduler.h.
|
static |
Calculates how many clock cycles are in each period.
For testing only!
deci_hz | The frequency is deci-hz (hz * 10) |
Definition at line 82 of file scheduler.h.