Nios® V Processor Software Developer Handbook

ID 743810
Date 5/26/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

8.3.5.2. Registering the Software ISR with the HAL

Based on the code in the example, the following execution flow is possible:
  • The software IRQ is generated.
  • The software ISR gains control.
    • The HAL general exception funnel gains control of the processor, and dispatches the sw_isr() ISR.
  • sw_isr() services the software interrupt, and returns to the normal program operation.
  • Normal program operation continues with an updated value of sw_isr_cnt.

Registering the Software ISR with the HAL

#include "system.h"

#include "sys/msw_interrupt.h"

#include "alt_types.h"

...
/* Declare a global variable to hold the incrementing value. */
volatile alt_u32 sw_isr_cnt = 0;
...
int main() {
  /* Register the ISR. */
  alt_niosv_register_msw_interrupt_handler(sw_isr);
  /* Enable software interrupt. */
  alt_niosv_enable_msw_interrupt();
  /* Generate the software interrupt. */
  alt_niosv_trigger_msw_interrupt();
}