fremoclock  1_3A01
FREMO Clock - Software for UTG
Timer Management

Here are some notes about the usage of Timer.h and Timer.c.

This implementation of timers allows you to have as many timers as needed. Only one HW timer is used. As many SW-Timers as you need can be used. You need a local timer variable (uint32_t) to manage your timer. There is no interrupt or event driven behaviour as the timers are not managed centrally. You need to poll the timer status.

This implementation has the following limitations:

  • Timer resolution is 10 ms, nevertheless the parameter is given in 1 ms resolutions. Thus be prepared, that the resoultion might change sometimes from 10ms to e.g. 1ms.
  • The maximum timer value that you can set with this implementation is good for timeouts of ~50 days - plenty of time

Usage of the Timer module:

Following example shows the usage of the Timer module functions:

Example:

#include <Timer.h> // Get access to the interface
uint32_t myTimer; // Your local timer
void myFunctionInit(void)
{
SetTimer(&myTimer, 1000); // Sets my local timer to 1s (1000ms)
}
void myFunctionPolled(void) // Called frequently to check for timeouts
{
if (CheckTimer(&myTimer) == 0) // other return values: 1=timer busy,
{ // -1=timer inactive
// Timer elapsed, so we do whatever we wanted after 1000ms
...
}
}
void myFunctionException(void)
{
if ( .... ) // some condition, don't mind here
{
if (AddTimer(&myTimer, 1000) == -1) // add another 1000ms to the timer
{
// error handling, because timer couldn't be increased
// --> overflow condition
}
}
else
{
ResetTimer(&myTimer); // timer is inactive now
} // --> CheckTimer will return -1
}