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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

The kernel knows that “thread1” was running, and the ISR didn’t tell it to do anything,<br />

so it can just go right ahead and let “thread1” continue after the interrupt.<br />

Just for reference, here’s what the InterruptAttachEvent() function call does (note that<br />

this isn’t the real source, because InterruptAttachEvent() actually binds a data<br />

structure to the kernel — it isn’t implemented as a discrete function that gets called!):<br />

// the "internal" handler<br />

static const struct sigevent *<br />

internalHandler (void *arg, int id)<br />

{<br />

struct sigevent *event = arg;<br />

}<br />

InterruptMask (intr, id);<br />

return (arg);<br />

int<br />

InterruptAttachEvent (int intr,<br />

const struct sigevent *event, unsigned flags)<br />

{<br />

static struct sigevent static_event;<br />

memcpy (&static_event, event, sizeof (static_event));<br />

}<br />

return (InterruptAttach (intr, internalHandler,<br />

&static_event, sizeof (*event), flags));<br />

The trade-offs<br />

So, which function should you use? For low-frequency interrupts, you can almost<br />

always get away <strong>with</strong> InterruptAttachEvent(). Since the interrupts occur infrequently,<br />

there won’t be a significant impact on overall system performance, even if you do<br />

schedule threads unnecessarily. The only time that this can come back to haunt you is<br />

if another device is chained off the same interrupt — in this case, because<br />

InterruptAttachEvent() masks the source of the interrupt, it’ll effectively disable<br />

interrupts from the other device until the interrupt source is unmasked. This is a<br />

concern only if the first device takes a long time to be serviced. In the bigger picture,<br />

this is a hardware system design issue — you shouldn’t chain slow-to-respond devices<br />

on the same line as high-speed devices.<br />

For higher-frequency interrupts, it’s a toss up, and there are many factors:<br />

• Unnecessary interrupts — if there will be a significant number of these, you’re<br />

better off using InterruptAttach() and filtering them out in the ISR. For example,<br />

consider the case of a serial device. A thread may issue a command saying “Get me<br />

64 bytes.” If the ISR is programmed <strong>with</strong> the knowledge that nothing useful will<br />

happen until 64 bytes are received from the hardware, the ISR has effectively<br />

filtered the interrupts. The ISR will then return an event only after 64 bytes have<br />

been accumulated.<br />

• Latency — if your hardware is sensitive to the amount of time that passes between<br />

asserting the interrupt request and the execution of the ISR, you should use<br />

April 30, 2009 Chapter 4 • Interrupts 185

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

Saved successfully!

Ooh no, something went wrong!