Timer#
The hardware abstraction layer provides functions for managing callbacks based on
timer expiry. These timers should be run from the main loop but also from
systemProcessEvents when called within the WP43 code.
Functions#
Defines
-
MAX_TIMER_ID#
Typedefs
-
typedef void (*timerCallback_t)(uint16_t param)#
Enums
Functions
-
uint32_t timerRun(void)#
-
void timerReset(void)#
Cancel all running timers.
Timers need to be restarted after this call, and should also be configured with timerConfig.
-
void timerConfig(timerId_t nr, timerCallback_t func)#
Configure the callback function for a given timer.
This function will only be called once when the timer has expired. If it should be called repeatedly then the callback function should call timerStart again. timerConfig must be called before timerStart is called.
- Parameters
nr – [in] timer ID
func – [in] callback function called when a timer expires
-
void timerStart(timerId_t nr, uint16_t param, uint32_t time)#
Set an expiry on a given timer.
The callback function configured in timerConfig will be called when the specified time has elapsed. It will only be called once, not repeatedly. If it is required to repeat then the callback function configured by timerConfig should call timerStart again.
- Parameters
nr – [in] timer ID
param – [in] parameter that is passed to the callback function
time – [in] time is milliseconds until the timer expires
-
void timerStop(timerId_t nr)#
Stop a timer.
This will stop a running timer causing it to not fire. It is safe to call on a stopped timer, but will have no effect. The timer must be configured with timerConfig before timerStop is called though.
- Parameters
nr – [in] timer ID
-
bool timerIsRunning(timerId_t nr)#
Query whether a timer is running.
Returns whether the given timer is running, that is that it has been started with timerStart, not stopped with timerStop, and it has not yet reached the expiry time.
- Parameters
nr – [in] timer ID
- Returns
true if the timer is still running
Example#
The configuration of the timers should be done early on in initialisation after
first calling timerReset:
timerReset();
timerConfig(tidAutoRepeat, cbAutoRepeat);
timerConfig(tidShowNop, cbShowNop);
where cbShowNop is the callback function for when the tidShowNop timer
expires.
When the timer expires the timer callback function will be called once (not repeatedly). If the timer should be called repeatedly then the callback can start the timer again.
void cbShowNop(uint16_t param) {
// ...
// Restart timer to get callback in another 200 milliseconds
timerStart(tidShowNop, param, 200);
}
void myFunction(void) {
timerStart(tidShowNop, 0, 200);
}