View topic - Interrupt Handler

Page 1 of 1

Interrupt Handler

PostPosted: Sun Jun 07, 2015 4:48 pm
by umamahesh
Hi,
Any examples for Writing interrupts in RM

Re: Interrupt Handler

PostPosted: Thu Jun 11, 2015 5:16 pm
by maschoen
Were you looking for examples on the structural way to write an interrupt handler in QNX? The documentation is pretty good in this area. Or did you want to know the ins and outs (there's a pun there in case you didn't notice) it writing the code inside an interrupt handler. For this you would have to provide a little more info on your hardware.

Re: Interrupt Handler

PostPosted: Sat Jun 13, 2015 10:07 am
by umamahesh
Thanks for the reply. I am writing I2C master RM to communicate to SGTL5000 on i.mx51. I have initialized the handler as follows

SIGEV_INTR_INIT(&dev->intrevent);
dev->iid = InterruptAttachEvent(dev->intr, &dev->intrevent,_NTO_INTR_FLAGS_TRK_MSK);
if (dev->iid == -1) {
perror("InterruptAttachEvent");
goto fail;
}

but how to point my handler function, few examples in QNX they mentioned ablove code snippet in separate thread and instead of &dev->intrevent they replaced with handler function. Like to know how it works. Please suggest.

Re: Interrupt Handler

PostPosted: Mon Jun 22, 2015 1:14 am
by maschoen
umamahesh wrote:Thanks for the reply. I am writing I2C master RM to communicate to SGTL5000 on i.mx51. I have initialized the handler as follows

SIGEV_INTR_INIT(&dev->intrevent);
dev->iid = InterruptAttachEvent(dev->intr, &dev->intrevent,_NTO_INTR_FLAGS_TRK_MSK);
if (dev->iid == -1) {
perror("InterruptAttachEvent");
goto fail;
}

but how to point my handler function, few examples in QNX they mentioned ablove code snippet in separate thread and instead of &dev->intrevent they replaced with handler function. Like to know how it works. Please suggest.


There are two contexts that you might want to execute code after an interrupt, interrupt context or process context. If your interrupt handler doesn't need immediate attention, you can use InterruptAttachEvent() to attach an event to the interrupt which will wake up your process and allow you to handle the interrupt in process context. Typically you use the event SIGEV_PULSE if your program is receive blocked most of the time. You can also use the SIGEV_INTR event, typically in a thread that can wait.

The other context is the interrupt context. For this you need the interruptAttach() call to attach your handler. On a first pass I would suggest using interruptAttachEvent() with a thread waiting on SIGEV_INTR. Then you can put printf's in the code for debugging. Then move the code to an interrupt handler routine.