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.

Writing interrupt handlers<br />

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

The flags parameter<br />

The last parameter, flags, controls all kinds of things:<br />

_NTO_INTR_FLAGS_END<br />

Indicates that this handler should go after other handlers that may be attached to<br />

the same interrupt source.<br />

_NTO_INTR_FLAGS_PROCESS<br />

Indicates that this handler is associated <strong>with</strong> the process rather than the thread.<br />

What this boils down to is that if you specify this flag, the interrupt handler will<br />

be automatically dissociated from the interrupt source when the process exits. If<br />

you don’t specify this flag, the interrupt handler will be dissociated from the<br />

interrupt source when the thread that created the association in the first place<br />

exits.<br />

_NTO_INTR_FLAGS_TRK_MSK<br />

The interrupt service routine<br />

Using InterruptAttach()<br />

Indicates that the kernel should track the number of times the interrupt has been<br />

masked. This causes a little more work for the kernel, but is required to ensure<br />

an orderly unmasking of the interrupt source should the process or thread exit.<br />

Let’s look at the ISR itself. In the first example, we’ll look at using the<br />

InterruptAttach() function. Then, we’ll see the exact same thing, except <strong>with</strong><br />

InterruptAttachEvent().<br />

Continuing our example, here’s the ISR intHandler(). It looks at the 8250 serial port<br />

chip that we assume is attached to HW_SERIAL_IRQ:<br />

/*<br />

* int1.c<br />

*/<br />

#include <br />

#include <br />

#define REG_RX 0<br />

#define REG_II 2<br />

#define REG_LS 5<br />

#define REG_MS 6<br />

#define IIR_MASK<br />

0x07<br />

#define IIR_MSR<br />

0x00<br />

#define IIR_THE<br />

0x02<br />

#define IIR_RX<br />

0x04<br />

#define IIR_LSR<br />

0x06<br />

#define IIR_MASK<br />

0x07<br />

volatile int serial_msr; // saved contents of Modem Status Reg<br />

volatile int serial_rx; // saved contents of RX register<br />

volatile int serial_lsr; // saved contents of Line Status Reg<br />

static int base_reg = 0x2f8;<br />

178 Chapter 4 • Interrupts April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!