C Language Development Kit/Functions/TimerCallback

From OptiWiki

Jump to: navigation, search
Description This function provides the operating system with a pointer to a user defined function. The user defined function will be called each time the heartbeat routine runs, i.e. every 20 ms.
void timercallback(void * userfunction);
void * userfunction
A pointer to a function userfunction(). The syntax of the user defined function userfunction() should be:
void userfunction(void)
Returns None
Remarks WARNING:

userfunction() must use very little time. The heartbeat is an interrupt routine that locks system resources. When the hearbeat routine calls userfunction(), system interrupts are blocked until userfunction() returns. The user is recommended to use this function with extreme care.

Note that the actual name of userfunction() is defined by the user. timercallback() only knows about the pointer, not about the name.

The heartbeat routine is an internal operating system function that is called every 20 ms due to an interrupt. The heartbeat routine performs all kinds of operating system tasks.

// This demo will make a beep every half a second.
// The operating system will call user_heartbeat_routine() every 20 ms.
// Note that the call to sound() takes a short time only. sound() sets some variables
// in the operating system and then returns.
// Switching the buzzer on and off is done internally by the operating system.
// Note also that userfunction() has gotten the name user_heartbeat_routine().
#include "lib.h"
#include <stdio.h>
unsigned int counter;
void user_heartbeat_routine( void )
    if( counter == 0 )
        counter = 25;
        sound( TSHORT, VSTANDARD, SMEDIUM, 0);
void main( void )
    printf("\fCallback demo\n");
    counter = 25;
    timercallback( user_heartbeat_routine );
    while( 1 )

Personal tools