Forum Discussion
Altera_Forum
Honored Contributor
12 years agoThank you Daixiwen !!
So, I have added the PIO in my .qsys and re-genereted the system. Then I've updated the .bdf schematic and set the pin used as PIO. Now, I've added this code to my .c file before the main() function:#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void handle_my_interrupt(void * context)
# else
static void handle_my_interrupt(void * context, uint32_t id)
# endif
{
volatile int * edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr=IORD_ALTERA_AVALON_PIO_EDGE_CAP(MY_PIO_BASE);
/*
*
* some code here
*/
}
volatile int edge_capture; Then I have created the routine that initialize the PIO and register the interrupt and I call it in my main function: static void init_pio(){
void * edge_capture_ptr=(void *) &edge_capture;
IOWR_ALTERA_AVALON_PIOIRQ_MASK(MY_PIO_BASE, 0x01);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(MY_PIO_BASE,0x0);
# ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
alt_ic_isr_register(MY_PIO_IRQ_INTERRUPT_CONTROLLER_ID, MY_PIO_IRQ, handle_my_interrupt, edge_capture_ptr, 0x0);
# else
alt_irq_register(MY_PIO_IRQ, edge_capture_ptr, handle_my_interrupt);
} Now, I can't test it directly beacause I need some extra hardware. But from what I've understood I have to put the code i want to be executed after an interrupt event in the handle_my_interrupt routine. It's right ? Do I have to put any 'reset' conditions of the interrupt in handle_my_interrupt ? Thank you !!!