8237 DMA Controller
8237 DMA Controller
controller
Input-Output Interfacing
Peripheral Interfacing:
I/O programming: Programmed I/O, Interrupt Driven
I/O, DMA I/O interface: serial and parallel
communication, memory I/O mapped I/Os.
Peripheral Devices: 8237 DMA controller, 8255-
Programmable peripheral interface, 8253/8254
Programmable timer/counter.8259 programmable
Interrupt Controller.
Peripheral Interfacing
device performs
CPU reads device status bits operation
no
status = done/ready?
CPU is
yes
“busy waiting”
in polling loop
Interrupt Driven I/O
Basic Operation
• CPU starts I/O device. Let it generate an interrupt when the job is
done.
• Disadvantages: Too many interrupts generated.
• DMA usually has separate chip do the I/O transfer for the CPU.
When the job is done one interrupt is generated.
Direct Memory Accessing; the 8237 DMA Chip
DMA
Direct Memory Access (DMA) is a method of allowing data to be moved
from one location to another in a computer without intervention from the
central processor (CPU). It is also a fast way of transferring data within
(and sometimes between) computers.
ALE
B
Data Bus
A
Data Bus
Micro
Memory
Processor B
Control Bus A
Control Bus
OR , IOW
HLDA HOLD MEMR , MEMW B
HRQ
DMA
HLDA Controller Control Bus Peripheral
Device
HREQ (Disk
OR, IOW Controller)
MEMR , MEMW
DACK0
DMA Protocol (I)
DMA operation is initiated by DMA operation is initiated by
Hardware, peripheral I/O sends a request to DMA controller (DMAC)
by pulling DREQ (DMA request) high (DMAC)
Software, CPU write a request command to DMA/C.
The DMAC will put a high on its HRQ (Hold request), signaling the
CPU through its HOLD pin that it needs to use the buses.
The CPU will finish the present bus cycle and respond to the DMA
request by putting high on its HDLA (hold the DMA request by putting
high on its HDLA (hold ack .).HOLD must remain active high as long
as DMA is performing its task.
DMAC will activate DACK (DMA DMAC will activate DACK (DMA ack )
which tells the peripheral device that it will start to transfer the data.
Single Transfer Mode In this mode device can make only one transfer (byte or word). After each
transfer DMAC gives the control of all buses to the microprocessor. Due to this microprocessor
can have access to the buses on a regular basis.
It allows the DMAC to time share the buses with the microprocessor, hence this mode is most
commonly used.
The operation of the DMA in a single transfer mode is as given below :
1. I/O device asserts DRQ line when it is ready to transfer data. .
2. The DMAC asserts HLDA line to request use of the buses from the microprocessor.
3. The microprocessor asserts HLDA, granting the control of buses to the DMAC.
4. The DMAC asserts DACK to the requesting I/O device and executes DMA bus cycle, resulting
data transfer .
5. I/O device deasserts its DRQ after data transfer of one byte or word.
6. DMA deasserts DACK line.
7. The word/byte transfer count is decremented and the memory address is incremented.
8. The HOLD line is deasserted to give control of all buses back to the microprocessor .
9. HOLD signal is reasserted to request the use of buses when I/O device is ready to transfer
another byte or word. The same process is then repeated until the last transfer.
10. When the transfer count is exhausted, TC is generated to indicate the end of the
transfer.
Block I Burst Transfer Mode
In this mode device can make number of transfers as programmed in the word count register.
After each transfer word count is decremented by 1 and the address is decremented or
incremented by 1. The DMA transfer is continued until the word count "rolls over" from zero to
FFFFH, a terminal count (TC) or an external END of Process (EOP) is encountered. Block
transfer mode is used when the DMAC needs to transfer a block of data.
The operation of DMA in block transfer mode is as given below:
1. I/O device asserts DRQ line when it is ready to transfer data.
2. The DMAC asserts HLDA line to request use of the buses from the microprocessor.
3. The microprocessor asserts HLDA, granting the control of buses to the DMAC
4. The DMAC asserts DACK to the requesting I/O device and executes DMA bus
cycle, resulting data transfer.
5. I/O device deasserts its DRQ after data transfer of one byte or word.
6. DMA deasserts DACK line.
7. The word/byte transfer count is decremented and the memory address is incremented.
8. When the transfer count is exhausted, the data transfer is not complete and DMAC wait for
another DMA request from the I/O device,indicated that it has another byte or word to
transfer.When DMAC receive DMA request step through are repeated.
9. Microprocessor then deasserts the HLDA signal to tell the DMAC that it has
resumed control of the buses.
Demand Transfer Mode In this mode the device is programmed to continue making
transfers until a TC or external EOP is encountered or until DREQ goes inactive.
The operation of DMA in demand transfer mode is as given below:
1. I/O device asserts DRQ line when it is ready to transfer data.
2. DMAC asserts HLDA line to request use of the buses from the microprocessor.
3. The microprocessor asserts HLDA, granting the control of buses to the DMAC.
4. The DMAC asserts DACK to the requesting I/O device and executes DMA bus
cycle, resulting data transfer. "
5. I/O device deasserts its DRQ after data transfer of one byte or word.
6. DMA deasserts DACK line.
7. The word/byte transfer count is decremented and the memory address is
incremented.
8. The DMAC continues to execute transfer cycles until the I/O device deasserts
DRQ indicating its inability to continue delivering data. The DMAC deasserts
HOLD signal, giving the buses back to microprocessor. It also deasserts DACK.
9. I/O device can re-initiate demand transfer by reasserting DRQ signal.
10. Transfer continues in this way until the transfer count has been exhausted.
Cascade Mode
DMA channels can be expanded using this mode. Fig. shows that two addition devices
are cascaded to the master device using two channels of the master device. This two
level DMA system. In this the HRQ and HLDA signals from the additional 8237 A are
connected to the DREQ and DACK signals of a channel of the master 8237 A. This
allows the DMA requests of the additional devices to communicate through the priority
network circuitry of the preceding device. Note: More 8237As can be added by adding
more levels in the DMA system.
Fig shows the detail connections for master and slave DMAC's.
Transfer Types
Memory-to-Memory Transfer
In this mode block of data from one memory address is moved to another memory
address. In this mode current address register of channel 0 is used to point the source
address and the current address register of channel 1 is used to point the destination
address in the first transfer cycle, data byte from the source address is loaded in the
temporary register of the 8237 A and in the next transfer cycle the data from the
temporary register is stored in the memory pointed by destination address. After each
data transfer current address registers are decremented or incremented according to
current settings. The channel 1 current word count register is also decremented by 1
after each data transfer.
Autoinitialize
In this mode, during the initialization the base address and word count registers are
loaded simultaneously with the current address and word count registers by the
microprocessor.
After the first block transfer i.e. after the activation of the EOP signal, the original
values of the current address and current word count registers are automatically
restored from the base address and base word count register of that channel. After
autoinitialization the channel is ready to perform another DMA service, without CPU
intervention.
Priority
In the 8237 A there are two priority selection options. 1. Fixed. Priority . 2. Rotating Priority.
1 Fixed Priority
In the fixed priority channel 0 has the highest priority and the channel 3 has the lowest priority.
Table shows the priority ratings.
Priority Channel
Highest 1 0
2 1
3 2
Lowest 4 3
Rotating Priority
In this, channel being serviced gets the lowest priority and the channel next to it gets the highest
priority as shown in Fig.
With rotating priority in a single chip DMA system, any device requesting service is guaranteed to be
recognized after no more than three higher priority services have occurred. This prevents anyone channel
from monopolizing the system.
Register Description
1. Current Address Register: Each channel has 16-bit current address
register. This register stores the value of the address used during DMA
transfers. The address in the current address register is automatically
incremented or decremented after each transfer. This register is loaded or
read by the microprocessor and it also be re-initialized back to its
original value after EOP in the autoinitialization mode.
2. Current Word Register: Each channel has a 16-bit current word count
register. This register determines the number of transfers to be
performed. After each transfer the contents of word count register is
decremented by 1.
3. Base Address and Base Word Count Registers: Each channel has
base address and base word count registers. These 16-bit registers store
the original value of their associated current registers. During
autoinitialization these values are used to restore the current registers to
their original values. The base registers are stored simultaneously with
their corresponding current registers.
Command register • It is an 8-bit register that controls the operation of the 8237.
• It must be programmed by the CPU.
• It is cleared by the RESET signal from the CPU or the master clear instruction of the
DMA.
Mode Register
1 0 1 1 0 0 0 1 = B5H
Source Program :
MOV AL, 50H ; Load Command word
OUT 88H, AL ; Send Command word
MOV AL, 50H ; Load lower byte of address
OUT 82H, AL ; Send lower byte of address
MOV AL, 20H ; load higher byte of address
OUT 82H, AL ; send higher byte of address
MOV AL, FFH ; Load lower byte of count
OUT 83H, AL ; Send lower byte of count
MOV AL, 00H ; load higher byte of count
OUT 83H, AL ; send higher byte of count
MOV AL, B5H ; Load mode word
OUT 8BH, B5H ; Send mode word