C Example
Example 8–1 illustrates an ISR that services a hardware interrupt from a button
parallel I/O (PIO) component. This example is based on a Nios II system with a 4-bit PIO peripheral connected to push buttons. An IRQ is generated any time a button is pushed. The ISR code reads the PIO peripheral’s edge capture register and stores the value to a global variable. The address of the global variable is passed to the ISR in the context pointer.
宏ALT_ENHANCED_INTERRUPT_API_PRESENT
被定义时,启用此版本的中断注册API函数
// Example 8–1. An ISR to Service a Button PIO Interrupt
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
static void handle_button_interrupts(void* context)
#else
static void handle_button_interrupts(void* context, alt_u32 id)
#endif
{
/* Cast context to edge_capture's type.