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.

TIME<br />

TIME<br />

Writing interrupt handlers<br />

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

That’s not such a great idea, because you may not need to wake up for every interrupt<br />

that the hardware generates! Go back and look at the source example above — it<br />

returned an event only when the modem status register on the serial port changed state,<br />

not when a character arrived, not when a line status register changed, and not when the<br />

transmit holding buffer was empty.<br />

In that case, especially if the serial port was receiving characters (that you wanted to<br />

ignore), you’d be wasting a lot of time rescheduling your thread to run, only to have it<br />

look at the serial port and decide that it didn’t want to do anything about it anyway. In<br />

that case, things would look like this:<br />

Interrupt<br />

thread 1<br />

kernel<br />

(resched)<br />

thread 2<br />

kernel<br />

(resched)<br />

thread 1<br />

Control flow <strong>with</strong> InterruptAttachEvent() and unnecessary rescheduling.<br />

All that happens is that you incur a thread-to-thread context switch to get into<br />

“thread2” which looks at the hardware and decides that it doesn’t need to do anything<br />

about it, costing you another thread-to-thread context switch to get back to “thread1.”<br />

Here’s how things would look if you used InterruptAttach() but didn’t want to<br />

schedule a different thread (i.e., you returned):<br />

Interrupt<br />

thread 1<br />

kernel<br />

ISR<br />

kernel<br />

(no resched)<br />

thread 1<br />

Control flow <strong>with</strong> InterruptAttach() <strong>with</strong> no thread rescheduling.<br />

184 Chapter 4 • Interrupts April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!