Search code examples
armcortex-m

ARM Cortex-M3 example for interrupt pending


With an ARM Cortex-M3, such as an NXP LPC1788, why would someone use the Interrupt Set-Pending Register(s) or Interrupt Clear-Pending Registers?

Can someone provide a simple, canonical example of using these registers?


Solution

  • The only use case I can think of is the triggering of a low-priority software excaption form a high priority IRQHandler - like the GPIO interrupt handler.

    Normally you would use PendSV for that, but when you have more than one task or priority level you can use any unused peripherial exception vector. Could be useful in programs that use the Sleep-on-Exit feature - where the µC will only run in exception handlers.

    // Example for LPC17xx
    void   ETHERNET_Handler (void)
    {
        // toggle LED on P0.4
        LPC_GPIO0->FIODIR0 ^= (1<<4);
    }
    
    void main(void) 
    {
        // set Ethernet IRQ to loewst Priority
        NVIC_SetPriority(ENET_IRQn,31);
        NVIC_EnableIRQ(ENET_IRQn);
        NVIC_SetPendingIRQ(ENET_IRQn); // trigger Ethernet IRQ Handler
        // ...
        while (1);
    
    }