Search code examples
interruptinterrupt-handlingqnxqnx-neutrinoblackberry-qnx

InterruptAttach fails on am3352x irq number 97 for bank 0B


I am trying to attach an IRQ handler to a gpio bank 0 i.e 0B irq no 97.

At the present moment, my implementation returns with -1. What am I doing wrong? It would be a very simple issue to implement.

#include <stdio.h>                                                              
#include <unistd.h>                                                             
#include "gpio.h"
#include <sys/neutrino.h>                                                       
#include "interrupt.h"                                                          
volatile unsigned int gpio0_irq_count;                                          

static const struct sigevent * gpio0_irq_handler (void *gpio, int id){      
    gpio0_irq_count++;
    return NULL;
}

int main(){
    int ret;
    unsigned long count=0;
    ret = InterruptAttach(97, gpio0_irq_handler, NULL,0,_NTO_INTR_FLAGS_TRK_MSK);
    printf("%s: Registering handler for irq %d result = %d\n",__func__ , 97, ret);
    if (ret)
        return -1;
    while(1){
        printf("%s:[%lu] : gpio0_irq_count = %d\n", __func__, count++, gpio0_irq_count);
        sleep(2);
    }
}

The erroneous output is:

main: Registering handler for irq 97 result = -1

Solution

  • After much back and forth with QNX, it turns out that a process requesting InterruptAttach() or InterruptAttach_r() needs elevated permissions acquired through

    ThreadCtl( _NTO_TCTL_IO, 0 );
    

    Once that is executed the API's work. However, one must still configure the gpio registers to actually fire the interrupt.

    GPIO_OE
    GPIO_STATUS
    GPIO_STATUS_SET
    GPIO_CTRL
    GPIO_RISINGDETECT