The IRQ module provides a mechanism to enable/disable IRQs, and register interrupt handlers. Registering of interrup handler, currently applies only to GCC \+ ARM architecture. The registering of interrupt handlers is handled using a separate mechanism in SDCC \+ 8051 architecture.
The IRQ functions are declared in irq.h
. The IRQ lines are indicated
using microcontroller specific macros. The macros for each
microcontroller is listed in the following table.
Microcontroller | IRQ Macro | Purpose |
---|---|---|
P89V664 |
IRQ_EXT0
| External Interrupt 0 |
- |
IRQ_TIMER0
| Timer 0 |
- |
IRQ_EXT1
| External Interrupt 1 |
- |
IRQ_TIMER1
| Timer 1 |
- |
IRQ_UART
| UART |
- |
IRQ_I2C0
| Primary I²C Bus |
- |
IRQ_PCA
| PCA |
- |
IRQ_TIMER2
| Timer 2 |
- |
IRQ_I2C1
| Secondary I²C Bus |
- |
IRQ_SPI
| SPI |
P89V51RD2 |
IRQ_EXT0
| External Interrupt 0 |
- |
IRQ_TIMER0
| Timer 0 |
- |
IRQ_EXT1
| External Interrupt 1 |
- |
IRQ_TIMER1
| Timer 1 |
- |
IRQ_PCA
| PCA |
- |
IRQ_UART
| UART / SPI |
- |
IRQ_TIMER2
| Timer 2 |
LPC1343 |
IRQ_NMI
| NMI |
- |
IRQ_HARD_FAULT
| Hard Fault |
- |
IRQ_MEM_FAULT
| Memory Fault |
- |
IRQ_BUS_FAULT
| Bus Fault |
- |
IRQ_USAGE_FAULT
| Usage Fault |
- |
IRQ_SVCALL
| SuperVisor Call |
- |
IRQ_PENDSV
| PendSV |
- |
IRQ_SYSTICK
| Systick |
- |
IRQ_I2C
| I²C |
- |
IRQ_CT16B0
| Match 0-2, Capture 0 |
- |
IRQ_CT16B1
| Match 0-1, Capture 0 |
- |
IRQ_CT32B0
| Match 0-3, Capture 0 |
- |
IRQ_CT32B1
| Match 0-3, Capture 0 |
- |
IRQ_SSP0
| SSP |
- |
IRQ_UART
| UART |
- |
IRQ_USB
| USB Low Priority |
- |
IRQ_USB_FIQ
| USB High Priority |
- |
IRQ_ADC
| ADC |
- |
IRQ_WDT
| Watchdog |
- |
IRQ_BOD
| Brown out |
- |
IRQ_PIO3
| GPIO Port 3 |
- |
IRQ_PIO2
| GPIO Port 2 |
- |
IRQ_PIO1
| GPIO Port 1 |
- |
IRQ_PIO0
| GPIO Port 0 |
The following example counts the no. of interrupt occuring on GPIO port 1, pin 11.
Listing 4.1. GPIO Interrupt Count
#include <stdint.h>
#include <board.h>
#include <gpio.h>
#include <irq.h>
#include <systick.h>
#include <lpc13xx/gpio.h>
volatile uint32_t * gpio_ie = (uint32_t *) GPIO1_IE;
volatile uint32_t * gpio_ic = (uint32_t *) GPIO1_IC;
volatile uint8_t count = 0;
void gpio_handler(void)
{
/* Acknowledge the interrupt, by clearing it. */
*gpio_ic = 1 << 11;
count++;
}
int main()
{
int prev = 0;
board_init();
board_stdout(LCD_STDOUT);
lcd_init();
gpio_init();
gpio_enable_pin(GPIO1_11);
gpio_direction_input(GPIO1_11);
/*
* Enable interrupts for pin 11 in the GPIO controller.
*
* By default, interrupts are generated when there is 1 to 0
* transition on the GPIO pin.
*/
*gpio_ie = 1 << 11;
irq_setcb(IRQ_PIO1, gpio_handler);
while (1) {
if (i != prev) {
printf("Interrupt %d\n", i);
prev = i;
}
}
}