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. <strong>Neutrino</strong> and interrupts<br />

What if the handler needs to do a significant amount of work? Here are a couple of<br />

possibilities:<br />

• The amount of time required to clear the source of the interrupt is short, but the<br />

amount of work required to talk to the hardware is long (the customer asked us a<br />

short question that takes a long time to answer).<br />

• The amount of time required to clear the source of the interrupt is long (the<br />

customer’s description of the problem is long and involved).<br />

In the first case, we’d like to clear the source of the interrupt as fast as possible and<br />

then tell the kernel to have a thread do the actual work of talking to the slow hardware.<br />

The advantage here is that the ISR spends just a tiny amount of time at the super-high<br />

priority, and then the rest of the work is done based on regular thread priorities. This is<br />

similar to your answering the phone (the super-high priority), and delegating the real<br />

work to one of your assistants. We’ll look at how the ISR tells the kernel to schedule<br />

someone else later in this chapter.<br />

In the second case, things get ugly. If an ISR doesn’t clear the source of the interrupt<br />

when it exits, the kernel will immediately be re-interrupted by the Programmable<br />

Interrupt Controller (PIC — on the x86, this is the 8259 or equivalent) chip.<br />

For PIC fans: we’ll talk about edge-sensitive and level-sensitive interrupts shortly.<br />

Telling a thread to do something<br />

We’ll continuously be running the ISR, <strong>with</strong>out ever getting a chance to run the<br />

thread-level code we need to properly handle the interrupt.<br />

What kind of brain-damaged hardware requires a long time to clear the source of the<br />

interrupt? Your basic PC floppy disk controller keeps the interrupt asserted until<br />

you’ve read a number of status register values. Unfortunately, the data in the registers<br />

isn’t available immediately, and you have to poll for this status data. This could take<br />

milliseconds (a long time in computer terms)!<br />

The solution to this is to temporarily mask interrupts — literally tell the PIC to ignore<br />

interrupts from this particular source until you tell it otherwise. In this case, even<br />

though the interrupt line is asserted from the hardware, the PIC ignores it and doesn’t<br />

tell the processor about it. This lets your ISR schedule a thread to handle this hardware<br />

outside the ISR. When your thread is finished transferring data from the hardware, it<br />

can tell the PIC to unmask that interrupt. This lets interrupts from that piece of<br />

hardware be recognized again. In our analogy, this is like transferring the VIC’s call to<br />

your assistant.<br />

How does an ISR tell the kernel that it should now schedule a thread to do some work?<br />

(And conversely, how does it tell the kernel that it shouldn’t do that?)<br />

Here’s some pseudo-code for a typical ISR:<br />

FUNCTION ISR BEGIN<br />

determine source of interrupt<br />

April 30, 2009 Chapter 4 • Interrupts 171

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

Saved successfully!

Ooh no, something went wrong!