Altera_Forum
Honored Contributor
21 years agowhy cann't it recive interrupt
why cann't it recive interrupt,when the key is pressed, the led shows nothing
# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "D:\document\nios\low_cost\h\alt_irq.h"# include <stdio.h># include <unistd.h> volatile int edge_capture; static 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(BUTTON_PIO_BASE); IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); } static void init_button_pio() { void* edge_capture_ptr = (void*) &edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts ); } int main (void) { IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0); # ifdef BUTTON_PIO_BASE init_button_pio();# endif // while( 1 ) { if (edge_capture != 0) { IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf); } } return 0; }