Khaled A. Al-Utaibi [email protected]. Interrupts in Microcomputer Systems Programmable...

66
The 8259A Programmable Interrupt Controller (PIC) Khaled A. Al-Utaibi [email protected]

Transcript of Khaled A. Al-Utaibi [email protected]. Interrupts in Microcomputer Systems Programmable...

Page 1: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The 8259A Programmable Interrupt Controller (PIC)Khaled A. [email protected]

Page 2: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Agenda

Interrupts in Microcomputer Systems Programmable Interrupt Controllers General Description of the 8259A Pin Configuration of the 8259A Block Diagram of the 8259A Interrupt Sequence Interfacing the 8259A to the 8086 Processor Programming the 8259A Reading the Status of the 8259A

Page 3: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Microcomputer system design requires that IO devices such as keyboards, displays, sensors and other components receive servicing in a an efficient manner so that so that the processor can concentrate on internal tasks.

The most common method of servicing such devices is the polled approach.

This is where the processor must test each device in sequence and “ask” each one if it needs servicing.

It is easy to see that a large portion of the main program is looping through this continuous polling cycle and that such a method would have a serious detrimental effect on system throughput.

This will limit the tasks that could be accomplished by the microcomputer.

Interrupts in Microcomputer Systems

Page 4: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 1: Polled method.

Page 5: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Microcomputer system design requires that IO devices such as keyboards, displays, sensors and other components receive servicing in a an efficient manner so that so that the processor can concentrate on internal tasks.

The most common method of servicing such devices is the polled approach (See Figure 1).

This is where the processor must test each device in sequence and “ask” each one if it needs servicing.

It is easy to see that a large portion of the main program is looping through this continuous polling cycle and that such a method would have a serious detrimental effect on system throughput.

This will limit the tasks that could be accomplished by the microcomputer.

Interrupts in Microcomputer Systems

Page 6: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

A more desirable method would be one that would allow the microprocessor to be executing its main program and only stop to service peripheral devices when it is told to do so by the device itself.

In effect, the method would provide an external asynchronous input that would inform the processor that it should complete whatever instruction that is currently being executed and fetch a new routine that will service the requesting device.

Once this servicing is complete, the processor would resume exactly where it left off.

This method is called interrupt (See Figure 2). It is easy to see that system throughput would dramatically

increase, and thus more tasks could be accomplished by the microcomputer.

Interrupts in Microcomputer Systems

Page 7: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 2: Interrupt method.

Page 8: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

A Programmable Interrupt Controller (PIC) functions as an overall manager in an interrupt-driven system environment. −It accepts requests from the peripheral equipment, −determines which of the incoming requests is of the

highest importance (priority), −ascertains whether the incoming request has a higher

priority value than the level currently being serviced, and

−issues an interrupt to the CPU based on this determination.

Programmable Interrupt Controllers

Page 9: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Each peripheral device or structure usually has a special program or “routine” that is associated with its specific functional or operational requirements.

This is referred to as a “service routine”. The PIC, after issuing an Interrupt to the CPU, must

somehow input information into the CPU that can “point” the Program Counter to the service routine associated with the requesting device.

This “pointer” is an address in a vectoring table and will often be referred to, in this document, as vectoring data.

Programmable Interrupt Controllers

Page 10: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The 8259A is a device specifically designed for use in real time, interrupt driven microcomputer systems.

It manages eight levels or requests and has built-in features for expandability to other 8259A's (up to 64 levels).

It is programmed by the system's software as an I/O peripheral. A selection of priority modes is available to the programmer so

that the manner in which the requests are processed by the 8259A can be configured to match his system requirements.

The priority modes can be changed or reconfigured dynamically at any time during the main program.

This means that the complete interrupt structure can be defined as required, based on the total system environment.

General Description of the 8259A

Page 11: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The pin configuration of the 8259 is shown in Figure 3. CS’ (Chip Select):

−A low on this pin enables RD and WR communication between the CPU and the 8259A.

−INTA functions are independent of CS’. WR’ (Write):

−A low on this pin when CS’ is low enables the 8259A to accept command words from the CPU.

RD’ (Read): −A low on this pin when CS is low enables the 8259A to release

status onto the data bus for the CPU. D7-D0 (I/O Bidirectional Data Bus):

−Control, status and interrupt-vector information is transferred via this bus.

Pin Configuration of the 8259A

Page 12: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

CAS0-CAS2 (I/O Cascade Lines): −CAS lines are used when several PICs are wired together

in cascade mode.−The CAS lines form a private 8259A bus to control a

multiple 8259A structure. −These pins are outputs for a master 8259A and inputs for

a slave 8259A. SP’/EN’ (I/O Slave Program/Enable Buffer):

−This is a dual function pin.−When in the Buffered Mode it can be used as an output

to control buffer transceivers (EN). −When not in the buffered mode it is used as an input to

designate a master (SP'/EN' = 1) or slave (SP'/EN' = 0).

Pin Configuration of the 8259A

Page 13: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

INT (Interrupt): −This pin goes high whenever a valid interrupt request is

asserted. −It is used to interrupt the CPU, thus it is connected to the

CPU's interrupt pin (INTR). IR0-IR7 (Interrupt Request):

−Asynchronous inputs.−Allow eight separate interrupt requests to be input and

controlled by the PIC. −An interrupt request is executed by raising an IR input

(low to high), and holding it high until it is acknowledged (Edge Triggered Mode), or just by a high level on an IR input (Level Triggered Mode).

Pin Configuration of the 8259A

Page 14: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

INTA’ (Interrupt Acknowledge): −This pin is used to enable 8259A interrupt-vector data

onto the data bus by a sequence of interrupt acknowledge pulses issued by the CPU.

A0 (Address Line): −This pin acts in conjunction with the CS’, WR’, and RD’

pins. −It is used by the 8259A to decipher various Command

Words the CPU writes and status the CPU wishes to read.

−It is typically connected to the CPU A0 address line (A1 for 8086, 8088).

Pin Configuration of the 8259A

Page 15: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 3: Pin configuration of the 8259.

Page 16: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The block diagram of the 8259 is shown in Figure 4. Interrupt Request Register (IRR) and In-Service

Register(ISR):−The interrupts at the IR input lines are handled by two

registers in cascade, the Interrupt Request Register (IRR) and the In-Service (ISR).

−The IRR is used to store all the interrupt levels which are requesting service; and the ISR is used to store all the interrupt levels which are being serviced.

Priority Resolver:−This logic block determines the priorities of the bits set in the

IRR. −The highest priority is selected and strobed into the

corresponding bit of the ISR during INTA’ pulse.

Block Diagram of the 8259A

Page 17: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Interrupt Mask Register (IMR):−The IMR stores the bits which mask the interrupt lines to be

masked. −The IMR operates on the IRR.−Masking of a higher priority input will not affect the interrupt

request lines of lower quality.−If the corresponding mask bit is a zero, the request is routed to

the priority resolver, otherwise it is blocked (masked). Control Logic:

−This block manages the interrupt and the interrupt acknowledge signals to be sent to the CPU for serving one of the 8 interrupt requests.

−This also accepts the INTA' signal form the CPU that causes the 8295A to release interrupt number on the data bus.

Block Diagram of the 8259A

Page 18: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Data Bus Buffer:−This 3-state, bidirectional 8-bit buffer is used to interface

the 8259A to the system Data Bus. −Control words and status information are transferred

through the Data Bus Buffer. Read/Write Control Logic:

−The function of this block is to accept OUT instructions from the CPU.

−It contains the Initialization Command Word (ICW) registers and Operation Command Word (OCW) registers which store the various control formats for device operation.

−This function block also allows the status of the 8259A to be transferred onto the Data Bus.

Block Diagram of the 8259A

Page 19: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The Cascade Buffer/Comparator:−This function block stores and compares the IDs of all

8259A's used in the system. −The associated three I/O pins (CAS0-CAS2) are outputs

when the 8259A is used as a master and are inputs when the 8259A is used as a slave.

−As a master, the 8259A sends the ID of the interrupting slave device onto the CAS0-CAS2 lines.

−The slave thus selected will send its preprogrammed subroutine address onto the Data Bus during the next one or two consecutive INTA pulses.

Block Diagram of the 8259A

Page 20: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 4: Block diagram of the 8259.

Page 21: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Before the 8259A can be used, it must be initialized as follows:−(1) The interrupt type numbers must be programmed,−(2) The operating mode must be selected, and −(3) The priority scheme must be selected.

Once initialized, the 8259A responds to interrupt requests on IR0 through IR7 according to an interrupt sequence which depends on the type of CPU being used.

In these slides we discuss interrupt sequence for the 8086 microprocessor.

Interrupt Sequence

Page 22: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The interrupt sequence in an 8086 system is given as follows:−(1) One or more of the interrupt request lines (IR7-0) are

raised high, setting the corresponding IRR bit(s).−(2) The priority resolver in the 8259A evaluates these

requests, and sends an INT to the CPU, if any of the raised requests is of a higher priority than that currently being serviced (if any).

−(3) The CPU finishes the current instruction (if IF=1) and responds by outputting the first of two INTA' pulses.

−(4) Upon receiving the first INTA' from the CPU, the following occurs: a- All interrupt requests within the 8259A are stored in the IRR. b- The highest priority ISR bit is set c- The corresponding IRR bit is reset.

Interrupt Sequence

Page 23: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

−(5) During the second INTA' pulse, the 8259A releases an 8-bit a type number corresponding to the active IR input onto the data bus where it is read by the CPU.

−(6) Upon reading the type number, the CPU performs following: (a) Multiply the type number by four to locate the address of the

interrupt service routine then use it as a pointer into the interrupt vector table located at address 00000 through 003FFH.

(b) Push the CS, IP, and the flag register onto the stack. (c) Execute the interrupt service routine. (d) Issue a special end-of-interrupt (EOI) command to the 8259A. (e) Execute the IRET instruction which retrieves the CS, IP, and the

flags, and transfers control back to the interrupted program −(7) This completes the interrupt cycle. In the AEOI mode the ISR

bit is reset at the end of the second INTA' pulse. Otherwise, the ISR bit remains set until an appropriate EOI command is issued at the end of the interrupt subroutine.

Interrupt Sequence

Page 24: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Example 1: Show how to interface the 8259A to the low byte (D0-D7) of the 8086 processor such that the 8259A is mapped to the two I/O port addresses 0 and 2.

Step (1): determine address decodingA15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1

A00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0Address decoding (CS’) Port Even

Select ByteStep (2): determine required control signals RD’ = IOR’, WR’ = IOW’

Interfacing the 8259 to the 8086 Processor

Page 25: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

A0

A1

A2 Figure 5: Circuit design of Example 1.

Page 26: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Example 2: Show how to interface two 8259A chips to the low byte (D0-D7) of the 8086 processor such that the master 8259A is mapped to the two I/O port addresses 0 and 2, while the slave 8259A is mapped to the two I/O port addresses 4 and 6.

Step (1): Determine address decodingA15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 1 00 0 0 0 0 0 0 0 0 0 0 0 0 1 0 00 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0Step (2): Address decoding (CS’) Port Even

Select Byte

Interfacing the 8259 to the 8086 Processor

Page 27: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

A1

A1

Figure 6: Circuit design of Example 2.

Page 28: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The 8259A accepts two types of command words generated by the CPU:

(1) Initialization Command Words (ICWs): − Before normal operation can begin, each 8259A in the system must be

brought to a starting point by a sequence of 2 to 4 bytes timed by WR’ pulses.− There are 4 initialization command words: ICW1, ICW2, ICW3, and ICW4.− Initialization command words ICW3 and ICW4 are optional.− The initialization command words are programmed according to the sequence

shown in Figure 7. (2) Operation Command Words (OCWs):

− These are the command words which command the 8259A to operate in various interrupt modes.

− These modes are: a. Fully nested mode b. Rotating priority mode c. Special mask mode d. Polled mode

− The OCWs can be written into the 8259A anytime after initialization.

Programming the 8259

Page 29: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 7: The sequence of initialization commands of the 8259.

Page 30: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

There are four initialization command words (ICWs) for the 8259A that are selected when the A0=1 , except for ICW1, which is selected when A0=0.

When the 8259A is first powered up, it must be sent ICW1, ICW2, and ICW4.

If the 8259A is programmed in cascade mode by ICW1, then we also must program ICW3.

So if a single 8259A is used in a system, ICW1, ICW2, and ICW4 must be programmed.

If cascade mode is used in a system, then all four ICWs must be programmed.

Programming the 8259Initialization Command Words (ICWs)

Page 31: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

ICW1 Programs the basic operation of the 8259A (See Figure 8).

The IC4 bit is used to program the 8259A for 80x86 operation (IC4=1) using the additional ICW4.

The A7-A5 bits must be 0’s for 80x86 operation and only apply to the 8259A when used with an 8-bit 8085 microprocessor (not covered in this course).

The SNGL bit selects a single (SNGL=1) or cascade (SNGL = 0) operation (single/multiple 8259A chips). If cascade operation is selected, we must also program ICW3.

The LTIM bit determines whether the interrupt request inputs are positive edge-triggered (LTIM=0) or level-triggered (LTIM=1).

Programming the 8259 Initialization Command Word 1 (ICW1)

Page 32: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Edge Triggered Mode (LTIM=0):−In this mode an interrupt request will be recognized by

a low to high transition on an IR input. −The IR input can remain high without generating

another interrupt. Level Triggered Mode (LTIM=1):

−In his mode, an interrupt request will be recognized by a high level on IR Input, and there is no need for an edge detection.

−The interrupt request must be removed before the End-Of-Interrupt (EOI) command is issued or the CPU interrupts is enabled to prevent a second interrupt from occurring.

Programming the 8259 Initialization Command Word 1 (ICW1)

Page 33: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 8: Format of the ICW1.

Page 34: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; initialize ICW1:

; ICW4 needed, ; cascading,; 4 byte interrupt vectors,; edge triggered modemov al, 00010101b

; master 8259 (port 0)out 0, al

; slave 8259 (port 4)out 4, al

Page 35: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

This ICW selects the vector numbers (8 vector numbers) used with the interrupt request inputs (see Figure 9).

Only the vector number of the first interrupt request input is specified.

For example, if we decide to program the 8259A so it functions at vector numbers 08H–0FH, we place 08H into this command word (A15-A8 = 0000 1000).

Likewise, if we decide to program the 8259A for vectors 70H–77H, we place 70H in this ICW (A15-A8 = 0111 0000).

The A10-A8 bits will be 0’s for 80x86 operation.

Programming the 8259 Initialization Command Word 2 (ICW2)

Page 36: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 9: Format of the ICW2.

Page 37: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; initialize ICW2: ; master 8259 (port 2); base interrupt vector 0x88mov al, 10001000bout 2, al

; slave 8259 (port 6); base interrupt vector 0x90mov al, 10010000bout 6, al

Page 38: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Only used when ICW1 indicates that the system is operated in cascade mode.

This ICW indicates where the slave is connected to the master (see Figure 10).

The ICW3 for a master 8259A indicates where a slave j is connected to the master by setting bit Sj=1.

The ICW3 for a slave 8259A specifies the ID of the slave (0-7) using the least significant bits ID3-ID0; the remaining bits are set to 0’s.

Programming the 8259 Initialization Command Word 3 (ICW3)

Page 39: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 10: Format of the ICW3.

Page 40: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; initialize ICW3:; master 8259 (port 2)mov al, 00000100bout 2, al; slave 8259 (port 6)mov al, 00000010bout 6, al

Page 41: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The ICW4 is used only when ICW1 indicates that the it is needed by setting bit IC4 = 1 (see Figure 11).

The uPC bit must be a Logic 1 to select operation with the 80x86 microprocessors.

The SFNM bit selects the special fully nested mode (SFNM = 1) or non-special fully nested mode (SFNM = 0) of operation for the 8259A.

The BUF and M/S bits are used together to select buffered operation or non-buffered operation for the 8259A as a master or a slave.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 42: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The AEOI bit selects automatic (AEOI=1)or normal (AEOI=0) end of interrupt.−The EOI commands of OCW2 are used only if the AEOI

mode is not selected by ICW4. −If AEOI is selected, the interrupt automatically resets

the interrupt request bit and does not modify priority. −This is the preferred mode of operation for the 8259A

and reduces the length of the interrupt service procedure.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 43: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Fully Nested Mode (Non-Special):−This mode is entered after initialization unless another mode is

programmed. −The interrupt requests are ordered in priority from 0 through 7 (0

highest).−When an interrupt is acknowledged the highest priority request is

determined and its vector placed on the bus. −Additionally, a bit of the Interrupt Service register (IS0-7) is set. −This bit remains set until the microprocessor issues an End of

Interrupt (EOI) command immediately before returning from the service routine, or if AEOI (Automatic End of Interrupt) bit is set, until the trailing edge of the last INTA.

−While the IS bit is set, all further interrupts of the same or lower priority are inhibited, while higher levels will generate an interrupt.

−After the initialization sequence, IR0 has the highest priority and IR7 the lowest.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 44: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The Special Fully Nest Mode:−This mode will be used in the case of a big system where cascading is

used, and the priority has to be conserved within each slave. − In this case the fully nested mode will be programmed to the master

(using ICW4). −This mode is similar to the normal nested mode with the following

exceptions: (a) When an interrupt request from a certain slave is in service this slave is

not locked out from the master's priority logic and further interrupt requests from higher priority IR's within the slave will be recognized by the master and will initiate interrupts to the processor. (In the normal nested mode a slave is masked out when its request is in service and no higher requests from the same slave can be serviced.)

(b) When exiting the Interrupt Service routine the software has to check whether the interrupt serviced was the only one from that slave. This is done by sending a non-specific End of Interrupt (EOI) command to the slave and then reading its In-Service register and checking for zero. If it is empty, a non-specific EOI can be sent to the master too. If not, no EOI should be sent.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 45: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Buffered Mode:−When the 8259A is used in a large system where bus

driving buffers are required on the data bus and the cascading mode is used, there exists the problem of enabling buffers.

−The buffered mode will structure the 8259A to send an enable signal on SP/EN to enable the buffers.

−In this mode, whenever the 8259A's data bus outputs are enabled, the SP/EN output becomes active.

−This modification forces the use of software programming to determine whether the 8259A is a master or a slave.

−Bit 3 in ICW4 programs the buffered mode, and bit 2 in ICW4 determines whether it is a master or a slave.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 46: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

End of Interrupt (EOI):−The In Service (IS) bit can be reset either automatically

following the trailing edge of the last in sequence INTA pulse (when AEOI bit in ICW1 is set) or by a command word that must be issued to the 8259A before returning from a service routine (EOI command).

−An EOI command must be issued twice if in the Cascade mode, once for the master and once for the corresponding slave.

−There are two forms of EOI command: (a) Specific: When the 8259A is operated in modes which preserve

the fully nested structure, it can determine which IS bit to reset on EOI.

(b) Non-Specific: When a Non- Specific EOI command is issued the 8259A will automatically reset the highest IS bit of those that are set, since in the fully nested mode the highest IS level was necessarily the last level acknowledged and serviced.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 47: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Automatic End of Interrupt (AEOI) Mode:−If AEOI=1 in ICW4, then the 8259A will operate in AEOI

mode continuously until reprogrammed by ICW4. −In this mode, the 8259A will automatically perform a

non-specific EOI operation at the trailing edge of the last interrupt acknowledge pulse

−Note that from a system standpoint, this mode should be used only when a nested multilevel interrupt structure is not required within a single 8259A.

−The AEOI mode can only be used in a master 8259A and not a slave. 8259As with a copyright date of 1985 or later will operate in the AEOI mode as a master or a slave.

Programming the 8259 Initialization Command Word 4 (ICW4)

Page 48: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 11: Format of the ICW4.

Page 49: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; initialize ICW4:; 80x86 mode,; automatic EOI,; non-buffered mode,; not special fully nestedmov al, 00000011b; master 8259 (port 2)out 2, al; slave 8259 (port 6)out 6, al

Page 50: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Once 8259A is initialized using the previously discussed initialization command words (ICW), it is ready for its normal function, i.e. for accepting the interrupts

The 8259A has its own way of handling the received interrupts called as modes of operation.

These modes of operations can be selected by programming, i.e. writing three internal registers called as operation command words (OCW).

There are three OCW, namely OCW1, OCW2, and OCW3.

The OCWs are selected when the A0=0, except for OCW1, which is selected when A0=1.

Programming the 8259 Operation Command Words (OCWs)

Page 51: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Used to set and read the Interrupt Mask Register (IMR).

When a mask bit is set, it will turn off (mask) the corresponding interrupt input.

The IMR is read when OCW1 is read. Because the state of the mask bits is unknown when

the 8259A is first initialized, OCW1 must be programmed after programming the ICW upon initialization.

The formats of the OCW1 is shown in Figure 12. The M7-M0 bits represent the eight mask bits.

−Mj=1 masks (disables) the jth interrupt input.

−Mj=0 unmasks (enables) the jth interrupt input.

Programming the 8259 Operation Command Word 1 (OCW1)

Page 52: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 12: Format of the OCW1.

Page 53: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; OCW1:; mask IRQ4 on master 8259 (port 2)mov al, 00010000bout 2, al; mask IRQ5 on slave 8259 (port 6)mov al, 00100000bout 6, al

Page 54: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Programmed only when the AEOI mode is not selected for the 8259A.

In this case, this OCW selects the way (mode) that the 8259A responds to an interrupt.

The formats of the OCW2 is shown in Figure 13. The R, SL, and EOI bits control the Rotate and End

of Interrupt modes and combinations of the two. The L2, L1, and L0 bits determine the interrupt

level acted upon when the SL bit is active.

Programming the 8259 Operation Command Word 2 (OCW2)

Page 55: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Nonspecific End-of-Interrupt Mode:−A command sent by the interrupt service procedure to

signal the end of the interrupt. −The 8259A automatically determines which interrupt

level was active and resets the correct bit of the interrupt status register.

−Resetting the status bit allows the interrupt to take action again or a lower priority interrupt to take effect.

Specific End-of-Interrupt Mode:−A command that allows a specific interrupt request to

be reset. −The exact position is determined with bits L2–L0 of

OCW2.

Programming the 8259 Operation Command Word 2 (OCW2)

Page 56: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Rotate-on-Nonspecific EOI Mode:−A command that functions exactly like the Nonspecific End-

of-Interrupt command, except that it rotates interrupt priorities after resetting the interrupt status register bit.

−The level reset by this command becomes the lowest priority interrupt.

−For example, if IR4 was just serviced by this command, it becomes the lowest priority interrupt input and IR5 becomes the highest priority (see Figure 14).

Rotate-on-Automatic EOI Mode:−A command that selects automatic EOI with rotating priority. −This command must only be sent to the 8259A once if this

mode is desired. −If this mode must be turned off, use the clear command.

Programming the 8259 Operation Command Word 2 (OCW2)

Page 57: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Rotate-on-Specific EOI Mode:−Functions as the specific EOI, except that it selects

rotating priority. Set Priority Mode:

−Allows the programmer to set the lowest priority interrupt input using the L2–L0 bits.

Programming the 8259 Operation Command Word 2 (OCW2)

Page 58: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 13: Format of the OCW2.

Page 59: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; OCW2:; send specific EOI command to reset ; ISR6 on master 8259 (port 0) mov al, 01100110bout 0, al

Page 60: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 14: Automatic rotation example.

(a) Before rotate

(b) After rotate

Page 61: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Selects register to be read, operation of the special mask register, and poll command.

The formats of the OCW3 is shown in Figure 14.−The ESMM bit Enable Special Mask Mode.

When ESMM=1 it enables the SMM bit to set or reset the Special Mask Mode.

When ESMM=0 the SMM bit becomes a don't care.−SMM: Special Mask Mode.

If ESMM=1 and SMM=1 the 8259A will enter Special Mask Mode. If ESMM=1 and SMM=0 the 8259A will revert to normal mask

mode. When ESMM=0, SMM has no effect.

−P: Set/reset Poll Command Mode.−RR, RIS: Select whether to read IRR or ISR register on next read

Programming the 8259 Operation Command Word 3 (OCW3)

Page 62: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Figure 14: Format of the OCW3.

Page 63: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Special Mask Mode:−Some applications may require an interrupt service routine to

dynamically alter the system priority structure during its execution under software control.

−For example, the routine may wish to inhibit lower priority requests for a portion of its execution but enable some of them for another portion.

−The difficulty here is that if an Interrupt Request is acknowledged and an End of Interrupt command did not reset its IS bit (i.e., while executing a service routine), the 8259A would have inhibited all lower priority requests with no easy way for the routine to enable them.

−That is where the Special Mask Mode comes in. − In the special Mask Mode, when a mask bit is set in OCW1, it inhibits

further interrupts at that level and enables interrupts from all other levels (lower as well as higher) that are not masked.

−Thus, any interrupts may be selectively enabled by loading the mask register.

Programming the 8259 Operation Command Word 3 (OCW3)

Page 64: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

Poll Command:− In this mode the INT output functions as it normally does. −The microprocessor should ignore this output.−This can be accomplished either by not connecting the INT output or

by masking interrupts within the microprocessor, thereby disabling its interrupt input.

−Service to devices is achieved by software using a Poll command.−The Poll command is issued by setting P=1 in OCW3. −The 8259A treats the next RD pulse to the 8259A (i.e., RD’=0, CS’=0)

as an interrupt acknowledge, sets the appropriate IS bit if there is a request, and reads the priority level.

− Interrupt is frozen from WR to RD.

Programming the 8259 Operation Command Word 3 (OCW3)

Page 65: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

; OCW3:; read IRR on next from master 8259 (port 0) mov al, 00001010bout 0, alin al, 0

Page 66: Khaled A. Al-Utaibi alutaibi@uoh.edu.sa.  Interrupts in Microcomputer Systems  Programmable Interrupt Controllers  General Description of the 8259A.

The following registers can be read via OCW3 (IRR and ISR or OCW1 [IMR]):− Interrupt Request Register (IRR):

8-bit register which contains the levels requesting an interrupt to be acknowledged.

The highest request level is reset from the IRR when an interrupt is acknowledged. (Not affected by IMR.)

The IRR can be read when, prior to the RD pulse, a Read Register Command is issued with OCW3 (RR=1, RIS=0.)

− In-Service Register (ISR): 8-bit register which contains the priority levels that are being serviced. The

ISR is updated when an End of Interrupt Command is issued. The ISR can be read, when, prior to the RD pulse, a Read Register Command

is issued with OCW3 (RR=1, RIS=1).− Interrupt Mask Register (IMR):

8-bit register which contains the interrupt request lines which are masked. For reading the IMR, no OCW3 is needed. The output data bus will contain

the IMR whenever RD is active and A0 = 1 (OCW1).

Reading the 8259A Status