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.

Summary<br />

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

There’s an additional cost over the “old” functions to perform the check on an<br />

SMP system, but in a single processor system it’s negligible, which is why I’m<br />

recommending that you always use InterruptLock() and InterruptUnlock().<br />

InterruptDisable() and InterruptEnable()<br />

These functions shouldn’t be used in new designs. Historically, they were used<br />

to invoke the x86 processor instructions cli and sti when <strong>Neutrino</strong> was<br />

x86-only. They’ve since been upgraded to handle all supported processors, but<br />

you should use InterruptLock() and InterruptUnlock() (to keep SMP systems<br />

happy).<br />

The one thing that bears repeating is that on an SMP system, it is possible to have both<br />

the interrupt service routine and another thread running at the same time.<br />

Summary<br />

Keep the following things in mind when dealing <strong>with</strong> interrupts:<br />

• Don’t take too long in an ISR — perform the minimum amount of work you can<br />

get away <strong>with</strong>. This helps minimize interrupt latency and debugging.<br />

• Use InterruptAttach() when you need to access the hardware as soon as the<br />

interrupt occurs; otherwise, avoid it.<br />

• Use InterruptAttachEvent() at all other times. The kernel will schedule a thread<br />

(based on the event that you passed) to handle the interrupt.<br />

• Protect variables used by both the interrupt service routine (if using<br />

InterruptAttach()) and threads by calling InterruptLock() and InterruptUnlock().<br />

• Declare variables that are going to be used between the thread and the ISR as<br />

volatile so that the compiler isn’t caching “stale” values that have been changed<br />

by the ISR.<br />

188 Chapter 4 • Interrupts April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!