Attaching and detaching interrupts
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. The interrupt is masked and will not be asserted again
// until InterruptWait() is called again with the UNMASK flag.
}
InterruptDetach(id);
return NULL;
}
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.