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.

<strong>Neutrino</strong> and interrupts<br />

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

Interrupt service routine<br />

Clearing the interrupt source<br />

In our analogy, telling the kernel that the interrupt was handled would be like telling<br />

the customer the answer — we can return back to whatever we were doing, knowing<br />

that the customer has had their question answered.<br />

Telling the kernel that some action needs to be performed is like telling the customer<br />

that you’ll get back to them — the telephone has been hung up, but it could ring again.<br />

The ISR is a piece of code that’s responsible for clearing the source of the interrupt.<br />

This is a key point, especially in conjunction <strong>with</strong> this fact: the interrupt runs at a<br />

priority higher than any software priority. This means that the amount of time spent in<br />

the ISR can have a serious impact on thread scheduling. You should spend as little<br />

time as possible in the ISR. Let’s examine this in a little more depth.<br />

The hardware device that generated the interrupt will keep the interrupt line asserted<br />

until it’s sure the software handled the interrupt. Since the hardware can’t read minds,<br />

the software must tell it when it has responded to the cause of the interrupt. Generally,<br />

this is done by reading a status register from a specific hardware port or a block of data<br />

from a specific memory location.<br />

In any event, there’s usually some form of positive acknowledgment between the<br />

hardware and the software to “de-assert” the interrupt line. (Sometimes there isn’t an<br />

acknowledgment; for example, a piece of hardware may generate an interrupt and<br />

assume that the software will handle it.)<br />

Because the interrupt runs at a higher priority than any software thread, we should<br />

spend as little time as possible in the ISR itself to minimize the impact on scheduling.<br />

If we clear the source of the interrupt simply by reading a register, and perhaps stuffing<br />

that value into a global variable, then our job is simple.<br />

This is the kind of processing done by the ISR for the serial port. The serial port<br />

hardware generates an interrupt when a character has arrived. The ISR handler reads a<br />

status register containing the character, and stuffs that character into a circular buffer.<br />

Done. Total processing time: a few microseconds. And, it must be fast. Consider what<br />

would happen if you were receiving characters at 115 Kbaud (a character about every<br />

100 μs); if you spent anywhere near 100 μs handling the interrupt, you wouldn’t have<br />

time to do anything else!<br />

Don’t let me mislead you though — the serial port’s interrupt service routine could<br />

take longer to complete. This is because there’s a tail-end poll that looks to see if more<br />

characters are waiting in the device.<br />

Clearly, minimizing the amount of time spent in the interrupt can be perceived as<br />

“Good customer service” in our analogy — by keeping the amount of time that we’re<br />

on the phone to a minimum, we avoid giving other customers a busy signal.<br />

170 Chapter 4 • Interrupts April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!