Software timers

The ZigBee 3.0 SDK provides resources that allow an application to implement and interact with software timers on the local node. Multiple software timers can be used concurrently and they are all derived from the same source counter, which is the ZigBee Tick Timer.

Note: To allow the device to enter sleep mode, no software timers should be active. Any running software timers must first be stopped and all timers must be closed.

Setting up timers

To set up software timers in your application code, you must:

  • Declare an array of ZTIMER_tsTimer structures (see Section 10.2.2.1), where each element/structure contains information on one timer

  • Call the function ZTIMER_vTask() in the while loop of your application - this allows the stack software to automatically update the structure for each timer as the timer runs

For each timer, a user-defined callback function must be provided, which is referenced from the timer’s structure. This callback function, ZTIMER_tpfCallback(), is called when the timer expires (reaches its timed period) in order to perform any operations that the application requires as a result of the timer expiration.

Before any of the software timers can be used, they must be collectively initialized by calling the function ZTIMER_eInit(). This function takes the array of timer structures as an input.

Before an individual timer can be used, it must be opened using the function ZTIMER_eOpen(). Similarly, when the timer is no longer required, it should be closed using the function ZTIMER_eClose(). A timer is specified in these functions by means of its index in the array of timer structures.

Parent topic:Software timers

Operating timers

Once an individual software timer has been opened, it can be run one or more times before it is closed. A timer can be run by calling the function ZTIMER_eStart(). The timed period must be specified in milliseconds. On expiration of the timer, the user-defined callback function ZTIMER_tpfCallback() is called to perform any operations required by the application.

A running timer can be stopped before it expires by calling the function ZTIMER_eStop(). The status of an individual timer can be obtained at any time using the function ZTIMER_eGetState(). The possible reported states are Running, Stopped, Expired and Closed.

Parent topic:Software timers

Parent topic:Using support software features