- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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? Thanx
# include <stdlib.h># include "stdio.h"# include "sys/alt_alarm.h"# include "alt_types.h"# include "system.h" alt_alarm debug_timerTEST ; alt_u32 DebugTESTISR(int context) { printf("running...\n"); } int main() { int status=0; alt_u32 clocks_per_uS = (DEBUG_TIMER_FREQ / 1000); // 1K uS per msec. alt_u32 debugclockspercall = clocks_per_uS * 200;//0;//00; //status = alt_sysclk_init(DEBUG_TIMER_FREQ); if (alt_alarm_start(&debug_timerTEST, debugclockspercall, DebugTESTISR, NULL) != 0) fprintf(stdout, "Error: failed to start DEBUG timer\n"); while(1) { printf("."); usleep(1000); } }Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
example 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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, that got me working...
What is the resolution of that alarm (how accurate)? Is it more accurate for me to define a timer in SOPC Builder and use that? thanx- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think,
the timer used for the alarms is the System clock timer, which is set in the System Library properties to a real timer in SOPC Builder. (normally sys_clk_timer with resolution 1ms). the resolution of the timer can be read by software with alt_ticks_per_second().- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi 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 (); }
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page