|
ADVANCED: CALLBACK |
|
|
CALLBACK is used in relation to the declaration and usage of callback functions. Using a program architecture utilizing the callback functionality supports an event-driven design that can prove to take fewer resources, be more responsive, and yield a better code structure. The address-of operator @ is used to get the address of a callback function.
INCLUDE rtcu.inc
The above function uses an inbuilt timer functionality to install three timers that each calls the callback at a given frequency. The first timer is called every 2 seconds, the second timer every 5 seconds, and the last timer every 10 seconds. The output when running the program are as follows:
10:42:43 -> Timer#0,arg=2 10:42:45 -> Timer#0,arg=2 10:42:47 -> Timer#0,arg=2 10:42:47 -> Timer#1,arg=5 10:42:49 -> Timer#0,arg=2 10:42:51 -> Timer#0,arg=2 10:42:52 -> Timer#1,arg=5 10:42:52 -> Timer#2,arg=10 10:42:53 -> Timer#0,arg=2 10:42:55 -> Timer#0,arg=2 10:42:57 -> Timer#0,arg=2 10:42:57 -> Timer#1,arg=5 10:42:59 -> Timer#0,arg=2 10:43:01 -> Timer#0,arg=2 10:43:02 -> Timer#1,arg=5 10:43:02 -> Timer#2,arg=10 10:43:03 -> Timer#0,arg=2 10:43:05 -> Timer#0,arg=2 10:43:07 -> Timer#0,arg=2 10:43:07 -> Timer#1,arg=5 10:43:09 -> Timer#0,arg=2 10:43:11 -> Timer#0,arg=2 10:43:12 -> Timer#1,arg=5 10:43:12 -> Timer#2,arg=10
For more detailed information on the implementation of callback functions, please refer to the RTCU M2M Platform SDK.
|