Nios® V Processor Software Developer Handbook

ID 743810
Date 4/01/2024
Public
Document Table of Contents

8.2.5.2. Registering the Button PIO ISR with the HAL

Based on the code in the example, the following execution flow is possible:
  • 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.
  • handle_button_interrupts() services the hardware interrupt and returns.
  • Normal program operation continues with an updated value of edge_capture.

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. */
    alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID,
      BUTTON_PIO_IRQ,
      handle_button_interrupts,
      edge_capture_ptr, 0x0);
}