Attaching and detaching interrupts

QNX SDP8.0Programmer's GuideDeveloper

In order to handle interrupts, the software must tell the OS that it wants to associate a thread or an event with a particular source of interrrupts, a hardware interrupt request (IRQ).

The actual interrupts request number depends on the hardware configuration supplied by the board's manufacturer. For the interrupt assignments for specific boards, see the buildfile in that board's BSP.

In any case, a thread specifies which interrupt source it wants to associate with using the InterruptAttachThread() or InterruptAttachEvent() function calls; when the software wishes to dissociate the IST from the interrupt source, it can call InterruptDetach().

#define IRQ_NUM 76

void *
hardware_ist(void *unused)
{
    // Attach this thread to the interrupt source.
    int const id = InterruptAttachThread(IRQ_NUM, _NTO_INTR_FLAGS_NO_UNMASK);
    if (id == -1) {
        // Handle errors.
    }

    while (!done) {
        // Wait for the interrupt to assert.
        // The FAST flag is more efficient, but cannot handle timeouts.
        int const rc = InterruptWait(_NTO_INTR_WAIT_FLAGS_UNMASK |
                                     _NTO_INTR_WAIT_FLAGS_FAST, NULL);
        if (rc == -1) {
            // Handle errors.
        }

        // Handle the interrupt.
        // Note that the interrupt is masked and will not be asserted again
        // until InterruptWait() is called again with the UNMASK flag.
    }
    InterruptDetach(id);
    return NULL;
}
Note: The startup code is responsible for making sure that all interrupt sources are masked during system initialization. When the first call to InterruptAttachThread() or InterruptAttachEvent() is done for an interrupt vector, the kernel unmasks it. Similarly, when the last InterruptDetach() is done for an interrupt vector, the kernel remasks the level.

Because interrupts can potentially impose a significant load on the machine, we don't let just anybody associate a thread with an interrupt. The process must have the PROCMGR_AID_INTERRUPT ability enabled. For more information, see Abilities in the security manual.

Page updated: