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
16 years agoHi all, I have copied 100% of the example and tried it. But I did not get any alarm activity. Can you point out the problem?
# include <stdlib.h># include "stdio.h"# include "alt_types.h"# include "altera_avalon_pio_regs.h"# include "altera_avalon_timer.h"# include "altera_avalon_timer_regs.h"# include "system.h"# include "sys/alt_alarm.h" 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; printf("In alarm\r\n"); return alt_ticks_per_second (); }