Maintaining ZCL Time
The simplest case of keeping time on a ZigBee PRO device is to maintain ‘ZCL time’ only (without using the Time cluster). In this case, the ZCL time on a device can be initialized by the application using the function vZCL_SetUTCTime().
The ZCL time is subsequently incremented from a local one-second timer, as follows. On expiration of the timer, an event is generated (from the hardware/software timer that drives the one-second timer), which causes a ZCL user task to be activated. The event is initially handled by this task as described in Section 3.2, resulting in an E_ZCL_CBET_TIMER event being passed to the ZCL via the function vZCL_EventHandler(). The following actions should then be performed:
The ZCL automatically increments the ZCL time and may run cluster-specific schedulers.
The user task resumes the one-second timer.
Updating ZCL Time Following Sleep
In the case of a device that sleeps, on waking from sleep, the application should update the ZCL time using the function **vZCL_SetUTCTime()**according to the duration for which the device was asleep. This requires the sleep duration to be timed.
While sleeping, the device normally uses its RC oscillator for timing purposes, which may not maintain the required accuracy. It is therefore recommended that a more accurate external crystal is used to time the sleep periods.
The vZCL_SetUTCTime() function does not cause timer events to be executed. If the device is awake for less than one second, the application should generate a E_ZCL_CBET_TIMER event to prompt the ZCL to run any timer-related functions. Note that when passed into vZCL_EventHandler(), this event will increment the ZCL time by one second.
Parent topic:Maintaining ZCL Time
ZCL Time Synchronization
The local ZCL time on a device can be synchronized with the time in a time-related cluster, such as Time, Price, or Messaging. The ZCL time is considered to be synchronized following a call to vZCL_SetUTCTime(). The NXP implementation of the ZCL also provides the following functions relating to ZCL time synchronization:
u32ZCL_GetUTCTime() obtains the ZCL time (held locally).
bZCL_GetTimeHasBeenSynchronised() determines whether the ZCL time on the device has been synchronized - that is, whether vZCL_SetUTCTime() has been called.
vZCL_ClearTimeHasBeenSynchronised() can be used to specify that the device can no longer be considered to be synchronized (for example, if there has been a problem in accessing the Time cluster server over a long period).
Parent topic:Maintaining ZCL Time
Parent topic:Time Cluster and ZCL Time