Forum Discussion
Altera_Forum
Honored Contributor
21 years agoalt_alarm_start
I am trying to use alt_alarm_start() as a general purpose timer. My callback is not getting called at all. Status from my call is good. Could someone look at the following and give me some hints? ...
Altera_Forum
Honored Contributor
21 years agoexample program:
// ALARMS static alt_alarm alarm_100ms; alt_u32 alarm_100ms_callback (void* context); static volatile unsigned char alarmflags=0;# define ALARM_100MS 0x01 # define ALARMTICKS(x) ((alt_ticks_per_second()*(x))/1000) int main() { if (alt_alarm_start (&alarm_100ms,ALARMTICKS(100),alarm_100ms_callback,NULL) < 0) { printf("No system clock available\r\n"); } while(1) { if(alarmflags&ALARM_100MS) { alarmflags&=~ALARM_100MS; printf("Alarm arrived\r\n"); } } } //################################################################## // ALRM CALLBACK FUNCTIONS //################################################################## alt_u32 alarm_100ms_callback (void* context) { alarmflags|=ALARM_100MS; return ALARMTICKS(100); } there must be a return value in the alarm callback function to specify the next arrival of the alarm. if it is 0, the callback is called only once. also pay attention that the alarm callback is called in interrupt context, so to use printf in the alarmcallback is not a good idea. this is also why alarmflags is volatile