8259 PIC: Difference between revisions

Jump to navigation Jump to search
Added IRQ Mask function, Is it ok to use ternary logic?
[unchecked revision][unchecked revision]
m (Interwiki)
(Added IRQ Mask function, Is it ok to use ternary logic?)
Line 162:
</source>
 
== Masking ==
The PIC has an internal register called the IMR, or the Interrupt Mask Register. It is 8 bits wide. This register is a bitmap of the request lines going into the PIC. When a bit is set, the PIC ignores the request and continues normal operation. Note that setting the mask on a higher request line will not affect a lower line. Here is an example of how to do this:
<source lang="C">
/*
arguments:
IRQline - The number of the IRQ to disable
mask - If 1, set the mask, if 0, clear it
*/
void IRQmask(unsigned char IRQline, unsigned char mask)
{
unsigned char a1, a2;
int set = 0;
a1 = inb(PIC1_DATA); // Save masks
a2 = inb(PIC2_DATA);
 
// We check to see if we are setting a mask or if we are clearing it:
mask ? set++ : mask = ~mask - 1;
// Now we shift the mask into place.
mask = mask << IRQline;
 
// Now here we shift the mask into the correct bit:
(IRQline > 7) ? a2 = (set ? a2 | mask : a2 & mask) : a1 = (set ? a1 | mask : a1 & mask);
 
outb(PIC1_DATA, a1); // restore saved masks.
outb(PIC2_DATA, a2);
}
</source>
== See Also ==
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu