Fast Timer
[Core]

The FastTimer subsystem provides a high resolution timer in a microsecond context. More...


Functions

int FastTimer_SetActive (bool active)
 Controls the active state of the Fast Timer system.
int FastTimer_GetActive ()
 Returns whether the timer subsystem is active or not.
void FastTimer_InitializeEntry (FastTimerEntry *fastTimerEntry, void(*timerCallback)(int id), int id, int timeUs, bool repeat)
 Initializes a fast timer entry structure.
void FastTimer_SetTime (FastTimerEntry *fastTimerEntry, int timeUs)
 Change the requeted time of an entry.
int FastTimer_Set (FastTimerEntry *fastTimerEntry)
 Sets the requested entry to run.
int FastTimer_Cancel (FastTimerEntry *fastTimerEntry)
 Stops the requested fast timer entry from running.

Detailed Description

The FastTimer subsystem provides a high resolution timer in a microsecond context.

If you don't need such high resolution timing, check the Timer

The Fast Timer subsystem is based on a collection of FastTimerEntries. To start a new timer, create a new FastTimerEntry structure, initialize it with FastTimer_InitializeEntry( ), and start it with FastTimer_Set( ).

There are currently one main limitation to the Fast Timer system:

Todo:
Allow the fast timer callbacks to cooperate with the RTOS

Function Documentation

int FastTimer_Cancel ( FastTimerEntry *  fastTimerEntry  ) 

Stops the requested fast timer entry from running.

Parameters:
fastTimerEntry pointer to the FastTimerEntry to be cancelled.

Definition at line 229 of file fasttimer.c.

int FastTimer_GetActive ( void   ) 

Returns whether the timer subsystem is active or not.

Returns:
active.
See also:
FastTimer_Set, FastTimer_Cancel

Definition at line 94 of file fasttimer.c.

void FastTimer_InitializeEntry ( FastTimerEntry *  fastTimerEntry,
void(*)(int id)  timerCallback,
int  id,
int  timeUs,
bool  repeat 
)

Initializes a fast timer entry structure.

The event is signified by a callback to the function provided, after the interval specified. The specified ID is passed back to the function to permit one function to work for many events. Pass repeat = true to make the event continue to create callbacks until it is canceled. Note that the timer entry structure needs to be created and managed by the caller. The longest period for a fast timer entry is 2^32 / 1000000 = 4294s.

Parameters:
fastTimerEntry pointer to the FastTimerEntry to be intialized.
timerCallback pointer to the callback function. The function must be of the form
void callback( int id ) 
id An integer specifying the ID the callback function is to be provided with.
timeUs The time in microseconds desired for the callback.
repeat Set whether the timer repeats or is a one-time event.
See also:
FastTimer_Cancel
Example
  TimerEntry myTimer; // our TimerEntry
  FastTimer_InitializeEntry( &myTimer, myCallback, 0, 250, true );
  FastTimer_Set( &myTimer ); // start our timer

  void myCallback( int id ) // our code that will get called by the timer every 250 microseconds.
  {
    // do something here
  }

Definition at line 126 of file fasttimer.c.

int FastTimer_Set ( FastTimerEntry *  fastTimerEntry  ) 

Sets the requested entry to run.

This routine adds the entry to the running queue and then decides if it needs to start the timer (if it's not running) or alter the timer's clock for a shorter period.

Parameters:
fastTimerEntry A pointer to the FastTimerEntry to be run.

Definition at line 160 of file fasttimer.c.

int FastTimer_SetActive ( bool  active  ) 

Controls the active state of the Fast Timer system.

Parameters:
active whether the FastTimer subsystem is active or not
Returns:
Zero on success.
See also:
FastTimer_Set, FastTimer_Cancel

Definition at line 65 of file fasttimer.c.

void FastTimer_SetTime ( FastTimerEntry *  fastTimerEntry,
int  timeUs 
)

Change the requeted time of an entry.

This must only be called within a callback caused by the Entry specified or when the entry is not being used. If you need to change the duration of a timer, you need to cancel it and re-add it, or alter the time inside a callback.

Parameters:
fastTimerEntry A pointer to the FastTimerEntry to be intialized.
timeUs The time in microseconds desired for the callback.

Definition at line 147 of file fasttimer.c.