Forum Discussion
Altera_Forum
Honored Contributor
20 years agoHow to use interrupt?
Hello. I want to use interrupt from USER_PIO, but I don't know how to use. I tried this sample code , but it seems that ISR is not executed. (I modified two point. *definition of...
Altera_Forum
Honored Contributor
20 years agoI use the interrupt with the button pio like that:
# include <cyg/hal/io.h> // for IOWR and IORD unsigned char ledpio; cyg_interrupt int_pio; cyg_handle_t int_pio_handle; cyg_uint32 isr_pio( cyg_vector_t vector, cyg_addrword_t data){ ledpio = ledpio|1; // IOWR (LED_PIO_BASE , 0, ledpio); cyg_interrupt_mask(vector); cyg_interrupt_acknowledge(vector); IOWR(BUTTON_PIO_BASE , 3, 0x00); // Reset the edgecapture register ledpio = ledpio&~1; // IOWR (LED_PIO_BASE , 0, ledpio); return(CYG_ISR_HANDLED | CYG_ISR_CALL_DSR); } void dsr_pio( cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data){ ledpio = ledpio|2; // IOWR (LED_PIO_BASE , 0, ledpio); cyg_interrupt_unmask(vector); ledpio = ledpio&~2; // IOWR (LED_PIO_BASE , 0, ledpio); } void cyg_user_start(void) { cyg_thread_create(..); cyg_thread_resume(..); cyg_interrupt_create( BUTTON_PIO_IRQ, // in /include/cyg/hal/system.h 99, 55, &isr_pio, &dsr_pio, &int_pio_handle, &int_pio); cyg_interrupt_attach(int_pio_handle); cyg_interrupt_unmask( BUTTON_PIO_IRQ); IOWR(BUTTON_PIO_BASE , 1, 0x00);// PIO in input IOWR(BUTTON_PIO_BASE , 3, 0x00);// Reset the edgecapture register IOWR(BUTTON_PIO_BASE , 2, 0x01);// unmask bit0 all other masked } I use the Altera demo board Cyclone EP1C20F400 with the pio core descriped in Chapter 7 of the Nios II Processor Reference Handbook