Altera_Forum
Honored Contributor
9 years agoBasic interrupt example not working due to Nios crash during startup code.
Hello Everybody,
I am trying to get a very basic interrupt demo program to work but Nios crashed during its boot code. It very difficult to find a solution since for me this problem is system related and very difficult to debug. The program:#include <stdio.h># include <stdio.h># include <unistd.h># include "system.h"# include "altera_avalon_pio_regs.h"# include "sys/alt_irq.h"
volatile int n=0;
volatile int edge_capture;
extern int alt_irq_register (alt_u32 id,
void* context,
alt_isr_func handler);
void handle_button_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(PIO_0_BASE);
n++;
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_0_BASE, 0);
}
void init_pio()
{
void* edge_capture_ptr = (void*) &edge_capture;
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PIO_0_BASE, 0xf);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PIO_0_BASE, 0x0);
alt_irq_register( PIO_0_IRQ, edge_capture_ptr,(alt_isr_func*) handle_button_interrupts );
}
int main()
{
init_pio();
while (1)
{
printf("Hello from Nios II interrupt count = %d !\n",n);
usleep(10000000);
}
return 0;
}
The place where Nios crashes is (exception thrown):
void alt_io_redirect(const char* stdout_dev,
const char* stdin_dev,
const char* stderr_dev)
{
/* Redirect the channels */
alt_open_fd (&alt_fd_list, stdout_dev, O_WRONLY, 0777); // here
alt_open_fd (&alt_fd_list, stdin_dev, O_RDONLY, 0777);
alt_open_fd (&alt_fd_list, stderr_dev, O_WRONLY, 0777);
}
The code is called from the NIOS startup routine that is before my main() program code is activated. Therefore i cannot assume my code is the culprit. JTAG_UART is connected to CPU using interrupt id 0 PIO is connected to CPU using interrupt id 1 Quartus project in attachement for those really interested Board used: DE2-115 Question: Any ideas regarding the culprit in this case? I am using legacy approach to interrupt handling, could it be that there are additional things to take into account ? Has anybody a simple working DE2 project to share? Best Regards, Johi.