4. Handling Multiple Interruption Sources

4.1. Latching the Interrupt Source

If your application is required to handle multiple event sources, the handler will need to be aware of the source of the interruption. This can be done by latching the interrupt source. To enable this feature, it has to be defined in either custom_config_qspi.h or custom_config_ram.h.

#define dg_configLATCH_WKUP_SOURCE              (1)

4.2. Configuring Additional Sources

For this example, we will configure the GPIO P1_7 as a source of event:

/* Configure button interrupts 2 */
hw_gpio_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_7, HW_GPIO_MODE_INPUT_PULLUP, HW_GPIO_FUNC_GPIO, 1);

Then we configure the Wake-up Timer block:

hw_wkup_configure_pin(HW_GPIO_PORT_1, HW_GPIO_PIN_7, 1, HW_WKUP_PIN_STATE_LOW);

4.3. Handling the Interruption

When an interruption occurs, it is now necessary to check the source of the interruption. This is done by calling hw_wkup_get_status(). It is also necessary, since the input is latched, to clear the source pin of the interrupt. The interruption handler registered will become:

void button_interrupt_cb(void)
{
        uint8_t status;

        /* Request the status */
        status = hw_wkup_get_status(HW_GPIO_PORT_1);

        /* Check the status of the source 1 */
        if (status & (1 << HW_GPIO_PIN_6)) {
                /* Notify the main task */
                OS_TASK_NOTIFY_FROM_ISR(task_h, 0x1, OS_NOTIFY_SET_BITS);
                /* Clear the interrupt */
                hw_wkup_clear_status(HW_GPIO_PORT_1, (1 << HW_GPIO_PIN_6));
        /* Check the status of the source 2 */
        } else if (status & (1 << HW_GPIO_PIN_7)) {
                /* Notify the main task */
                OS_TASK_NOTIFY_FROM_ISR(task_h, 0x2, OS_NOTIFY_SET_BITS);
                /* Clear the interrupt */
                hw_wkup_clear_status(HW_GPIO_PORT_1, (1 << HW_GPIO_PIN_7));
        }
}

Now the application can verify the different notification and act accordingly:

/* Check the notification is button 1 */
 if(ulNotifiedValue & 0x1){
         /* Send the character on the UART */
        printf("#");
        fflush(stdout);
/* Check the notification is button 2 */
} else if(ulNotifiedValue & 0x2) {
        /* Send the character on the UART */
       printf("$");
       fflush(stdout);

}

This example results in different characters being sent depending on the button pressed, as depicted in Fig. 5

_images/multiple_interrupt.png

Fig. 5 Multiple Interrupt Sources