Specifications

Button is pressed, generating an IRQ.
The ISR gains control.
With the IIC, the HAL general exception funnel gains control of the processor, and dispatches the
handle_button_interrupts() ISR.
With an EIC, the processor branches to the address in the vector table, which transfers control to
the handle_button_interrupts() ISR.
handle_button_interrupts() services the hardware interrupt and returns.
Normal program operation continues with an updated value of edge_capture.
Example 8-2: Example 8–2. Registering the Button PIO ISR with the HAL
#include "sys/alt_irq.h"
#include "system.h"
...
/* Declare a global variable to hold the edge capture value. */
volatile int edge_capture;
...
/* Initialize the 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;
/* 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 ISR. */
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID,
BUTTON_PIO_IRQ,
handle_button_interrupts,
edge_capture_ptr, 0x0);
#else
alt_irq_register( BUTTON_PIO_IRQ,
edge_capture_ptr,
handle_button_interrupts );
#endif
}
Note:
Additional software examples that demonstrate implementing ISRs, such as the
count_binary example project template, are installed with the Nios II Embedded
Design Suite (EDS).
Upgrading to the Enhanced HAL Interrupt API
If you have custom device drivers, Altera recommends that you upgrade them to use the enhanced HAL
interrupt API. The enhanced API maintains compatibility with the IIC, while supporting external
interrupt controllers. The legacy HAL interrupt API is deprecated.
If you plan to use an EIC, you must upgrade your custom driver to the enhanced HAL interrupt API.
Upgrading your device driver is very simple, requiring only minor changes to some function calls.
For more information and details of the API functions, refer to the "HAL API Reference" chapter.
8-16
Upgrading to the Enhanced HAL Interrupt API
NII5V2
2015.05.14
Altera Corporation
Exception Handling
Send Feedback