libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | List of all members
Scheduler Class Reference

A pollable timer to help schedule events. More...

#include <scheduler.h>

Public Member Functions

 Scheduler (const int deci_hz)
 Create a schedule keeper that returns true with the specified frequency. More...
 
bool Run (void)
 Check to see if the time period has passed yet. More...
 

Static Public Member Functions

static unsigned int GetTicksPerPeriod (const int deci_hz)
 Calculates how many clock cycles are in each period. More...
 

Detailed Description

A pollable timer to help schedule events.

Warning
: This class does not guarentee a minimum seperation between true Run() calls. Instead, it guarentees that, on average, a true Run() will happen with the specified frequency. Depending on how often Run() is called, there may be some jitter (if it is not called frequently enough).
Author
SRLM

Constructor & Destructor Documentation

Scheduler::Scheduler ( const int  deci_hz)
inline

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.

Warning
deci_hz must be 1 or more! Setting it less will result in a runtime error.
Parameters
deci_hzThe frequency (in 10x true return values per second).

Here is the call graph for this function:

Member Function Documentation

static unsigned int Scheduler::GetTicksPerPeriod ( const int  deci_hz)
inlinestatic

Calculates how many clock cycles are in each period.

For testing only!

Parameters
deci_hzThe frequency is deci-hz (hz * 10)
Returns
The number of clock cycles (ticks) per period.
bool Scheduler::Run ( void  )
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).

Returns
true if the time period has passed, false otherwise.

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