Availability | All terminals |
Description | With InstallHeartbeatHandler, you can install callback functions that will be called every 20ms by the operating system. |
Syntax |
typedef void(*heartbeat_function)(void); int InstallHeartbeatHandler( heartbeat_function userfunction ); |
Arguments |
heartbeat_function userfunction
The name of the function that is to be installed.
|
Returns | OK, in case the handler is successfully installed, or the handler was already installed. ERROR, in case there are too many handlers installed. |
Remarks |
WARNING:Make sure that userfunction() only uses very little time. The heartbeat is a interrupt routine that locks system resources, so when it calls userfunction(), other interrupts are blocked until userfunction() returns.In any case, the userfunction call must return within 2.5 seconds, or the system will do a restart. So it is recommended to use this function with great care. |
Example |
// The code fragment below installs a callback function // that is executed by the operating system every 20ms. // The callback makes sure that the red LED is switched // on for a short time every 2 seconds. // (Press function key to uninstall) #include <stdio.h> #include "lib.h" int Callback(void) { static int counter=100; if (--counter == 0) { GoodReadLed(RED,10); counter = 100; return TRUE; // Return TRUE to indicate device needs to wake-up } return TRUE; // Return FALSE to indicate can stay asleep (return DISABLED if the device may power off) } void main( void ) { printf("\nTimer callback"); InstallHeartbeatHandler(Callback); while(1) { if (getchar() == CLR_KEY) RemoveHeartbeatHandler(Callback); } Idle(); } |