Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

alt_alarm_start doesnt work

Altera_Forum
Honored Contributor II
1,852 Views

Here is my code: 

# include <stdio.h># include <stdlib.h># include <stddef.h># include "system.h"# include "IO.h"# include "sys/alt_alarm.h"# include "alt_types.h" 

 

/*Prototypes*/ 

alt_u32 timer_interrupt(void* context); 

int alt_alarm_start(alt_alarm* alarm, alt_u32 nticks, alt_u32 (*callback) (void* context), void* context); 

 

/*Global Variables*/ 

static alt_alarm alarm; 

 

 

 

void main(){ 

printf("alt_sysclk_init: %d\n",alt_sysclk_init(TIMER_0_TICKS_PER_SEC)); //This is an edit. looks like I need that. With that alt_alarm_start works. Just dont get an interrupt. 

if(alt_alarm_start(&alarm,1000,timer_interrupt,NULL) < 0) 

alt_printf("No system clock available\r\n"); 

 

 

 

 

alt_u32 timer_interrupt(void* context) 

printf("tick\n"); 

return 1; 

 

Where is the bug? I am running with "hello_world_small"(Must save memory). Looks like the alt_alarm_start fucntion return nothing(Null) -> get the "No system clock available" message. 

 

EDIT: I am running with the timer and not just with CPU-ticks, or?
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
865 Views

Did you define the system timer in the system library properties?

0 Kudos
Altera_Forum
Honored Contributor II
865 Views

No. 

 

But somehow if I activate the timer, the system do nothing after flashing 

btw. I dont use an operating system 

 

System: Stratix III Board. Timerout period is 1µs and the timer is full featured
0 Kudos
Altera_Forum
Honored Contributor II
865 Views

Ok, well. Dont know where is the bug. But anyway. I just use now directly the timer interrupt and I am configuring the registers directly as well. This is working pretty good. This solution fits perfectly for me.  

So thx for help! 

 

void main(){ 

IOWR(0x00000020,1,(1<<3) | (1 << 0) );//Stop Timer, IRQ enable, counter stops when getting 0 

IOWR(0x20,0,0); // Clear TO Bit(Reaching 0) 

IOWR(0x20,2,(alt_u16)(100000000-1)); // Clear TO Bit(Reaching 0);(100000000-1)=1s(100Mhz) 

IOWR(0x20,3,(alt_u16)( (100000000-1) >> 16 )); // Clear TO Bit(Reaching 0) 

alt_irq_register(TIMER_0_IRQ, NULL, timer_interrupt); 

IOWR(0x00000020,1,(1<<2) | (1 << 0) );//Start Timer, IRQ enable, counter stops when getting 0} 

return 0; 

 

 

alt_u32 timer_interrupt(void* context) 

{  

IOWR(0x20,0,0); //Clear TO(timeout) bit) 

IOWR(0x00000020,1,(1<<2) | (1 << 0) );//Start Timer, IRQ enable, counter stops when getting 0 

printf("tick\n");  

return 1;  

}
Reply