26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Writing interrupt handlers<br />

When the Ethernet ISR finished clearing the source of the interrupt (step 5), the<br />

interrupt line is still asserted, thanks to the SCSI hardware device. However, the PIC,<br />

being programmed in edge-sensitive mode, is looking for an inactive-to-active<br />

transition (on the composite line) before recognizing another interrupt. That isn’t<br />

going to happen because the kernel has already called both interrupt service routines<br />

and is now waiting for another interrupt from the PIC.<br />

In this case, a level-sensitive solution would be appropriate because when the Ethernet<br />

ISR finishes and the kernel issues the EOI to the PIC, the PIC would pick up the fact<br />

that an interrupt is still active on the bus and re-interrupt the kernel. The kernel would<br />

then run through the chain of ISRs, and this time the SCSI driver would get a chance<br />

to run and clear the source of the interrupt.<br />

The selection of edge-sensitive versus level-sensitive is something that will depend on<br />

the hardware and the startup code. Some hardware will support only one or the other;<br />

hardware that supports either mode will be programmed by the startup code to one or<br />

the other. You’ll have to consult the BSP (Board Support Package) documentation that<br />

came <strong>with</strong> your system to get a definitive answer.<br />

Writing interrupt handlers<br />

Attaching an interrupt handler<br />

Let’s see how to set up interrupt handlers — the calls, the characteristics, and some<br />

strategies.<br />

To attach to an interrupt source, you’d use either InterruptAttach() or<br />

InterruptAttachEvent().<br />

#include <br />

int<br />

InterruptAttachEvent (int intr,<br />

const struct sigevent *event,<br />

unsigned flags);<br />

int<br />

InterruptAttach (int intr,<br />

const struct sigevent *<br />

(*handler) (void *area, int id),<br />

const void *area,<br />

int size,<br />

unsigned flags);<br />

The intr argument specifies which interrupt you wish to attach the specified handler to.<br />

The values passed are defined by the startup code that initialized the PIC (amongst<br />

other things) just before <strong>Neutrino</strong> was started. (There’s more information on the<br />

startup code in your <strong>Neutrino</strong> documentation; look in the Utilities Reference, under<br />

startup-*; e.g., startup-p5064.)<br />

At this point, the two functions InterruptAttach() and InterruptAttachEvent() differ.<br />

Let’s look at InterruptAttachEvent() as it’s simpler, first. Then we’ll come back to<br />

InterruptAttach().<br />

April 30, 2009 Chapter 4 • Interrupts 175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!