ISR for USB.

Dear Guru…

please help in Interrupt Service routine pgm.

Task: My pgm has to raise an interrupt whenever USB is plugged in.

so i have written the routine like this.

void *int_thread (void *arg);
const struct sigevent *isr_handler (void *arg, int id);
#define IRQ3 3
int intrAttach = 0;

void main()
{
pthread_create (NULL, NULL, int_thread, NULL);

.
.
.
.
.
}

void* int_thread (void *arg)
{
// enables the IO privilages
ThreadCtl (_NTO_TCTL_IO, NULL);

             "io-usb -d ohci .... "and
             "devb-umass cam....." are also run.
// Attach interuupt.
intrAttach = InterruptAttach (IRQ3, isr_handler, NULL, 0, 0);

while (1)
          {
	int iIntrWaitError = 0;
           [b] interruptWait (NULL, NULL);[/b]                 
            //Have to do processing but could not get interrupt
           InterruptUnmask(IRQ3, intrAttach);
          }

}

const struct sigevent* isr_handler (void *arg, int id)
{
InterruptMask(IRQ3, intrAttach);
return (&event);

}

This is my code.

I don’t know why the interrupt is not being raised, when i plug in the USB.
When i debug the control is blocking at interruptWait (NULL, NULL); instruction, but when i connect the USB no response.

please help me gurus…

Thank you.
-HideAndSeek

return (&event) - what you return?

maybe somthing like:
SIGEV_INTR_INIT(&some_p->intr_event);
intrAttach = InterruptAttach (IRQ3, isr_handler, &some_pointer, sizeof(some_pointer), 0);


const struct sigevent* isr_handler (void arg, int id)
{
some_p = (SOME_POINTER_t
)arg;

InterruptMask(IRQ3, intrAttach);
return (&some_p->intr_event);

}

HideAndSeek,

Make sure you don’t have ‘io-usb’ running.

That’s the usb stack under QNX and it normally does the device insertion/detection work for you. It may be capturing the event instead of your interrupt.

I am not sure what you want to accomplish by capturing this event. But there are other ways besides attaching to interrupts to have your code receive a callback when a USB device is inserted (download the USB DDK for some code examples).

Tim

Very very bad idea, Interrupt on the USB device will not be for insertion only but for most the data exchange as well. Plus nothing prevent other devices from using the same interrupt has the USB controler.

Follow Tim’s suggestion and check out the USB DDK.

Thank you guys…

  i could not understand why the interrupt is not working on Qnx.  I had a sample code from momentics help. But that could not be of any helpfull now.  

Any how guys thank you for your comments and replies…

-HideAndSeek