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.
12748 Discussions

Code blocked in the ISR routine...

Altera_Forum
Honored Contributor II
1,170 Views

Hi, 

 

I want to generate a simple Push Button ISR routine... 

But my code didn't work... 

The interrupt occurs but the program still in the ISR routine... 

 

Here the declaration of the init_button_pio() 

    static void init_button_pio()     {         /* Recast the edge_capture pointer to match the         alt_irq_register() function prototype. */         void* edge_capture_ptr = (void*) &edge_capture;         /* Disable button interrupts. */         IOWR_ALTERA_AVALON_PIO_IRQ_MASK(button_BASE, 0x0);         /* Reset the edge capture register. */         IOWR_ALTERA_AVALON_PIO_EDGE_CAP(button_BASE, 0x1);                  /* Register the ISR. */         alt_irq_register( button_IRQ, edge_capture_ptr, handle_button_interrupts );                /* Enable button interrupts. */         IOWR_ALTERA_AVALON_PIO_IRQ_MASK(button_BASE, 0x1);     } 

 

And, here the ISR routine : 

    static void handle_button_interrupts(void* context, alt_u32 id)     {         /* cast the context pointer to an integer pointer. */         volatile int* edge_capture_ptr = (volatile int*) context;         /*         * Read the edge capture register on the button PIO.         * Store value.         */         *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(button_BASE);                  /* Write to the edge capture register to reset it. */         IOWR_ALTERA_AVALON_PIO_EDGE_CAP(button_BASE, 0x0);         /* MY CODE*/         IOWR_ALTERA_AVALON_PIO_DATA(leds_BASE, ledCount ++);                           /* reset interrupt capability for the Button PIO. */         IOWR_ALTERA_AVALON_PIO_IRQ_MASK(button_BASE, 0x1);     } 

 

I don't understand why my code is staying in the ISR, I reset the edge capture register... 

 

Thank you for your help.
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
445 Views

Hi there, 

 

Is your button input de-bounced? If not it could generate a series of consecutive interrupt requests so that as soon as you leave the ISR it re-enters again. If you run your code, rather than step through it, what happens? I'd guess that it would change the state of your LEDs, but in a somewhat erratic fashion. 

 

If your button inputs are debounced to provide a single clean edge, there should be no problem. 

 

Cheers 

 

0 Kudos
Reply