Attach an event to an interrupt source
#include <sys/neutrino.h> int InterruptAttachEvent( int intr, const struct sigevent* event, unsigned flags ); int InterruptAttachEvent_r( int intr, const struct sigevent* event, unsigned flags );
For more information, see "Flags," below.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The InterruptAttachEvent() and InterruptAttachEvent_r() kernel calls attach the given event to the hardware interrupt specified by intr. They automatically enable (i.e., unmask) the interrupt level.
The InterruptAttachEvent() and InterruptAttachEvent_r() functions are identical except in the way they indicate errors. See the Returns section for details.
Before calling either of these functions, the thread must:
ThreadCtl( _NTO_TCTL_IO, 0 );
If the thread doesn't have the appropriate abilities, the call to InterruptAttachEvent() fails with an error of EPERM; if the thread doesn't successfully call ThreadCtl(), it might SIGSEGV when it calls InterruptAttachEvent() or InterruptAttachEvent_r().
To prevent infinite interrupt recursion, the kernel automatically does an InterruptMask() for intr when delivering the event. After the interrupt-handling thread has dealt with the event, it must call InterruptUnmask() to reenable the interrupt.
Consider the following when choosing an event type:
On a multicore system, the thread that receives the event set up by InterruptAttachEvent() runs on any CPU, limited only by the scheduler and the runmask.
Flags
The flags argument is a bitwise OR of zero or more of the following values:
The interrupt structure allows hardware interrupts to be shared. For example if two processes call InterruptAttachEvent() for the same physical interrupt, both events are sent consecutively. When an event attaches, it's placed in front of any existing events for that interrupt and is delivered first. You can change this behavior by setting _NTO_INTR_FLAGS_END.
Normally, InterruptAttach() and InterruptAttachEvent() automatically unmask an interrupt the first time something is attached to it. If you specify _NTO_INTR_FLAGS_NO_UNMASK, the kernel leaves the interrupt masked, and you must specificially call InterruptUnmask() to enable it.
The _NTO_INTR_FLAGS_TRK_MSK flag and the id argument to InterruptMask() and InterruptUnmask() let the kernel track the number of times a particular interrupt handler or event has been masked. Then, when an application detaches from the interrupt, the kernel can perform the proper number of unmasks to ensure that the interrupt functions normally. This is important for shared interrupt levels.
Advantages & disadvantages
InterruptAttachEvent() has several advantages over InterruptAttach():
There are also some disadvantages:
You can freely mix calls to InterruptAttach() and InterruptAttachEvent() for a particular interrupt.
Blocking states
These calls don't block.
An interrupt function ID. If an error occurs:
Use the ID with InterruptDetach() to detach this interrupt event.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |