8257 DMA Controller
8257 DMA Controller
I
_ a;Dtet
!
t0
Puipheral lntwfacing
T[," iOPBOGRAMMING
;''-= k-now
that binary information received from an external device is usually stored
rru-:: r: '-"':or later processing.
in
Information transferred from the central computer inio u,
,"b' :'= ::iginates in the memory unit. The CPU merely "*tu"rut
executes the I/O instructions and. may
rlirr:::: ie data temporarily, but the ultimate source or
destination is the memory unit. Data
r':;:';.:: between the central computer and I/O devices may be handled
in a varie"ty of modes.
: : ' -odes use the CPU as an intermed.iate path; others transfer the data directly to an from
ri: I - :ri:ror/ unit. Data transfer to
and from peripherals may be handled in one of three possible
: :.:.
- Programmed I/O
- Interrupt-initiated VO
l. Direct memory access (DMA)
Programmed UO Interrupt DMA IOp
Programmed I/O operations are theresult of I/O instructions
* written in the computer
'-:am' Each data item transfer is initiated by an instruction in the program. Usually, the
:-'----'fer is to and from a CPU register and peripheral.
other instructions are needed to transf'er
"r; jata to and from CPU and memory. Transferring data under prograrn control requires
:--'tant monitoring of the peripheral by the CPU. Once
a data transfer is initiated, the CpU is
-'-':ired to monitor the interface to see
when a transfer can again be made. It is up to the
-
' :rammed instructions executed in the CPU to keep close tabs on everything
that is taking
; .re in the interface unit and the I/O device.
10.3
PERIPHERAL
10.4
IntheprogTammedliomethod,theCPUstaysinaprogramloopuntiltheVo,
indicates that it is ready for data transfer. This is a time-consuming process since it keep.
an interrupt facility and special comm
fro"".ro. busy needlessiy. It can be avoided by using signal when the data are available
io inform the interface io issue an interrupt' request
the device. In the meantime the cPU pro""ud to execute another prog:ram' The inte-:
"u.,
meanwhilekeepsmonitoringthedevice'Whentheinterfacedetermin"t,:11:11i^1.11':!.
to the computer' Upon detecting
ready for data transfer, it geierates an interrupt request
signal, the CPU momentariiy stops the task it is processing'
btul-"1:=-
external
utrLgl llal interrupt
urvvr r sl/v vtb^'$^,
returns to the task it was ongl
service program to process the I/O transfer, and then
performing.
peripheral' In direct
Transfer of data under programmed uo is between cPU and
access (DMA), the interface transfers data into and
out of the memory unit through the
bus. The cPU initiates the transfer by supplying the
interface with the starting address
then proceeds to execute other tasks' \\
the number ofwords needed to be transferred and
the memory bus' when
the transfer is made, the DMA requests memory cycles through
request is granted by the memorv controller, the DMA transfers,th:,11i? yT:Y]lX T::
memory Uo tran:
irr" Cpu ir"."ly deiays its memory access operation to allow the direct
I/o-memory transfers
since peripheral speed is usually slower than processor speed,
infrequent compared to processor access to memory'
Many computers combine the interface logic with the'":"i""f-u-i1:
t11iT:t:ff
pro""rro, (IoP). The IoP can handle many perip)
access into one unit and call it an Vo
the computer is divided into
through a DMA and interrupt facility. In such a system,
,"purlt" modules: the memory unit, the CPU, and the IOP'
Example of Programmed l/O
access to rnemorl-'
In the programmed I/o method, the I/o device does not have direct
of severai instructions by t;
transfer from an I/O device to memory requires the execution
ffiilffi;;f."I"r", instruction to transfer the data from the device to the CPU and
store instruction to transfer the data from the cPU to memory'
other isntructions may'
and to count the numbers of
needed to verify that the data are available from the device
transferred.
interface into the cPU
An example of data transfer from an vo device through an
one at a time as they are availab
shown in Fig. 10.1(o). The device transfers bytes of data
I/O bus and enables its data v
When a byte of data is available, the device flu."t it is the
enables the data accepted I
line. The interface accepts the byte into its iata register and
The interface sets u .u., ,ro* disable the data valid line, but
it will not transfer another
until the data accepted line is disabled by the interface'
A program is written for the computer to check the flag in the
status register to dete
is by reading the
ifa byte has been piaced in the dataregister by the VO device' This done
;"#;ffi " 6i,tl""ster and checking the value of the then flag bit. If the flag is equal to 1'
cleared to 0 by either the c
cPU reads the data from the data register. The flag bit is . r n - -- rL^ 11^-:^is clear
designed' Once the flag ^l^^.
or the interface, depending on how the interface circuits are
then transfer the next d
the interface disables thJdata accepted line and the device can
byte.
PE RIPH EBAL INTER FACI NG
10.5
Data legister
Address bus
Data vald
CPU I/C)
VO read device
Status Data accepted
VO wriie regfister r'
F = Flag bit
Fig. 10.1(a) Data transfer f rom l/O device to Cpt-J.
lnterrupt-lnitiated l/O
An alternative to the CPU constantly monitoring the flag is to let the interface inform the
computer when it is ready to transfer data. This mode of transfer uses the interrupt facility.
While the CPU is running a program, it does not check the flag. However, when the flag is set,
the computer is momentarily interrupted from proceeding with the current program and is
l: tr]emo{, informed of the fact that the flag has been set. The CPU deviates from what it is doing to take
€riphera-: care of the input or output transfer. After the transfer is completed, the computer returns to
into thre= the previous program to continue what i{ was doing before the interrupt.
Vectored Interrupt: The CPU responds to the interrupt signal by storing the return
address from the progrtam counter into a memory stack and then control branches to a service
routine that processes the required I/O transfer. The way that the processor chooses the branch
nemory. A address of the service routine varies from one unit to another. In principle, there are two
ons by the methods for accomplishing this. One is called uectored, intercupt and the other, nonuectored,
IPU and a interrupt. In a nonvectored interrupt, the branch address is assigned to a fixed location in
ns may be memory. In a vectored interrupt, the source that interrupts supplies the branch information to
rs of words the computer. This information is called the interrupt uector.In some computers the interrupt
vector is the frrst address of the I/O service routine. In other computers the interrupt vector is
an address that points to a location in memory r,vhere the beginning address of the I/O service
he CPU is
available. routine is stored.
data valid
epted line. 10.1.1 lntroduction to DMA controller (SZS7 and 8237)
iother byte Direct memory access is an IIO technique commonly used for high-speed data tfansfer. In
microprocessor controlled data transfer, the speed of peripheral is less than or equal to the
determine speed ofmicroprocessor. Ifthe speed ofperipheral is greater than the speed ofmicrqprocessor,
J the status then the microprocessor is disconnected and DMA controller is used to transfer data. The DI\{A
al to 1, the controlled data transfer does not require software hence it is faster than microprocessor
:r the CPU controlled data transfer. This tcchnique used on any system that requires a high speed data
i is cleared, transfer rate. e.9,, C.R.T. systern, floppy disk drive system, hard disc derive system, High speed
r next data ADC etc.
In microprocessor based system data transfer can i.e., controlled by either softu,a:-e or
hardware. It uses program instructions to transfer data from I/O device to memorv or from
PERIPHERAL INTERFA0ING
10.6
perform following
memory and vo device. To transfer data by this method microprocessor
operation.
1. Fetch the instruction form memory'
2. Decode the instruction.
3. Execute the instruction'
To perform these operations microprocessor requires consid'erable
time' so this method
such this data transfer from magnetic
of data transfer is not suitable for large data transfeis
disk or optical disk to memory. Above technique is known as
software controlled data
transfer,
External device gnerates
In other technique external device is used to control d.ata transfer.
and a11ows peripheral device to
address and control signats requited to control data transfer
direct memory access (DMA)
directly access the meriory. Hence this technique is referred to as
as DMA Controller Fig' 10' 1(b )'
and externai device which controls the data transfer refred to
a-, a*
MEMR, MEMW
HOLD
Fig. 10,1(b)
DMA cycle to transfer one byte. After transferring one byte it increments address register
decrements byte count register and transfer next byte. In this way, it transfers all data b;
between memory and input/output devices. After transferring all data bytes, the DMA contr,-,
disables 'HOLD' signal and enters into slave mode.
DliA. In this mode only one DMA cycle is added between two machine cycles ofof the
the
microprocessor as shown in Fig. 10.3, hence the instruction execution speed
microprocessor is reduced slightly.
(lnslructlon CYcles)
*
Ml Mz M3 Mp
DMA
DMA DMA DMA
cycle "1 cycle 2 cycle 3 Fi9.10.3.
cycle N
The sequence of events that take place is shown by flowchart of Fig. 10.4.
ransferring one
; \.,'hen the next
the bus back to
lr,,'er than burst Fig. 10.4. Flowchaft for cycle steel DMA.
10.10 PERIPH ERAI- INTERFAC', :
In this mocie the DMA controller sends 'HOLD' signal to the microprocessor and waits :-:
HLDA signal. After receiving HLDA signal, ihe DMA controller gains control of the system b.-
and execuies only one DMA cycle. After transferring one byte, it disables 'HOLD' signal a::
enters into slave mode. The microprocessor then gains control of the sysiem bus and execur.:
next machine cycle. If the count is not zero and next data is available then the DMA controil=:
sends 'HOLD' signal to the microprocessor and transfers next byte of data block.
(lll) DMAverify.
(u) I/O read, (ui\ t/O
write, rui I ) Interrupt
r Lumbers of acknowledge, (ulil) Jdle.
7. The rnj:croplocessor performs arithmetii, The DMA controller performs oniy data transfe:
logical data transfer and decision operation, hence data cannot be processed.
making opelations, hence data can be
processed.
8. A11 address and control signals are All address and controi signals are generated
generated by microProcessor. DN'IA controller.
9. Data lines of8257 are connected to the Data lines of 8257 are connected to the higher
systern data lines' system address lines.
10. The intialization of DMA controller, The DMA controller cannot intialize devices.
DMA and non-DMA I/O devices is done
by microprocessor.
11. TC, AEN, ADSTB, MARK etc. signals TC, AEN, ADSTB, MAIIK, etc. signals are
cannot be activated. activated.
12. The microprocessor provides instructio The DMA controller does not provide
set. set.
Pin Direction
Dr-Do vo Databus (8 bits bidirectional)
IOR ao I/O read bidirectional
CLK I Clockinput
Reset I Reset input
Rcady I Readyinput
HRQ o HOLD request (to 8085)
I_ILDA I HoId acknowiedge (From 8085)
AEN o Address enable
(contd...)
:: 2 IP H ERAL INTER FACING 10.13
I
I
-_}READY 635 A3<+
734 A2<-.-..-r.
-}HLDA
<-ADSTB 833 A1€
<-AEN 932 46€
<-HRO .10 8257 31 VCC<-
-----|cE 11 30 DO+
12 29 D1 e
->CLK
-----|Reset 13 28 D2e
+-D7ffi2 14 27 D3e
+-DAeks '15 26 Da€
--_)DHe3 16 25 onCK-o->
*+DRQ2 17 24 6lffir+
18 23 Dse
->DRQ1
---+DRe6 19 22 D6e
*\/-^'5t 20 21 D76
Fi9.10.5.
Symbol Description
Do'Dr: These are bidirectional tristate, buffered, multiplexes data (Do -
Dr)/address (As - A15) lines. In salve mode, these line function as
bi-directional data lines. In this mode, data lines are used to transfer
information (Address, count value, corltrol world and status word)
between microprocessor and 8257's registers. In master mode,
these lines function as address output lines (A. - Aru). 8257 places
tntd...) co ttt d
10.14 P E R I P H ER A L I NT E B FAC I,\..
:::...1
PER I PH ER AL INT EB FACIN G
10.16
INTERNAL BUS
DRQo
Ds-Dz
orcro
ron.
iOW. DRQl
CLK
HE SET -) 6;6r"1
Ao #
A1
s
Ar s
A3 +
A4
A5
4.,
A7
READY DRQ3
HRO
HLDA, DACR3
Llelvr n
ME[,1IV
AEI\
ADSTB
TC
IIAFK
(o) Mode Set Register. It is a utrite only register. It is used to set oper(tting nodes of
-;257. This register must be programmed ai'ter initialization of required DMA channeis.
The
:ddress of this register is (As Az Ar Ao = 1000). The format of mode set register is shown in
: ig. 10.7.
'i
vl
D ioJd
= Auto io rnode I
'1
= Enable DlvlA CH-O
(
0 * Ho'taiin inoflty
''l:lnJ Dll,'1A Ch-0
0 = Disable Dl"1A
I
I
1; afler
1 = Stop a1 TC # 1 = Enablc Dl'lA
Dl'']A CH-l
;a5le channel aiter TC)
(DisaSl Disaolc DL4A dH'1
0 = Disatlc
3nnel is enabled after TC
0 = Chann
ended write mode
1 = Extend
rmal
0 = Norma mode {- 1 = Enable DiUA
Dir{A CH-2
D[4A CH-2
0 = Disable Dlr4A
:ating pri1]rlty
1 = Rotat
:d priority 1 = Enable DMA
DMA CH-3
0 = Fixed
0 = Disable Dl"/A CH-3
1 = 8?57 exer;LttirtQ
it cvcie
I
le. urrdate I
-: .\cL
O=A'2s2"ro.r,.,, 1l , 1t''rC
='fC activaled ft)r CH-3
DlvlA cycle 0=TC not activated for CH-3
data
F!9. 10.8. Status register.
nals (c) F/L Flip-Flop (First/Last FliplF'lop). Thc rvord leng$h of 8257 is 8 bits, hence it
.-q. It can accept or gcnerate B bit data simultaneously. But the address and count registers are 16
bit. The microprocessor cannot access a 16 bit register simultaneously. A0 - A, address lines
atus are used to distinguish between 16 bit registers, but they are not used to distinguish betu'een
IStEI lower and higher by'tes of the 16 bit registers. The 8257 provides on clip F/1, flip-flop to distinguish
IS 14 signal. It also gets reset rvhenever the rnode set register is loaded. Hence the initialization
ilave prograrn can begin w,ith loading a "durnmy" (00H0 in mode set reg"ister. To access lorver blte of
a 16 bit register, the F/L flip-flop shoulci be reset and for higher byte of a 16 bit register the F/
10.18 PERI PH ERAL INTER FAC I :,.
L fiip-flop should be set. This flip-flop is togglecl af'ter each CH register access. The interrup:
must be disatrled before accessing 16 bit register.
The selection of registers is shown in tabie below :
A$ A2 A1 Ao FIL Register
0 0 0 0 0 LSB CH-0 Address register
0 0 0 0 1 MSB CH-0 Address register
0 0 0 1 0 LSB CH-O Terminal count register
0 0 0 1 1 X,[SB CH-O Termina] count register
i4) Priority Resolver. It contains priority resoiving logic circuit the resolves the priority
af each cirannel. It can be initialized either in rotating or fixecl priority rnode.
{5i DMA Channel. 8257 provides four separate channels. Each channel contains two 16
l:it regJistcr viz. (1) 16 bit address register (2) 16 bit count register.
(a) 16 Bit Address Register. It is a 16 bit register. It is used to hold the starting
address of rnemory. This register is incremented after each DMA cycle. If the adclress register
is read in the middle of a DMA operation, it provides the adclress of next memorv location. The
format of address register is as shown in Fig. 10.9.
rndicate type of DMA cycle or direction of data transfer. The format of TC register is as Sho\!rr
in Fig. 10.10.
i<- ril = 0 _._ !i
TCr2ircrl lTCloi rce
Binary code o{ N-1 where N is number of bytes to be transferred
1 1 lllegal lllegal
Fig.10.11.
(2) Fixed Priority Mode. If the RP bit of mode set register is reset then 8257 operates
in fixed priority mode. In fixed priority mode, channel 0 has highest priority and channel 3 has
lowest priority. The propriety is resolved during 54 of each DMA cycle.
(3) Extend Write Mode. If the EW bit of rnode set register is set then 8257 generates
advanced or extencled writc control signais (IOW and MEMW), 1.e., MEMW or IOW will go low
one clock cycle earlier as shown in Fig. 10.12. This mode is used to interface slower device to
systen\. If the memory devices or VC) device connected is slightly slower, then for synchronization
it used READY signal. In this method the write signal is delayed by adding rvait states into a
DMA cycle. This reduces tire speed of transfer'. But in extended write mode, the writ signal is
- lits. extended earlier r,vithout adding states, 1.e., the set up time of write input signal of an input/
output device or rnemory is increased in extended lvrite mode rvithout reducing the speed of
.-ould
transfer. Thus sigaal allou, more time to external logic for deciding if additional rvait states are
?, bits
needed. Microcomputer systems may use lnelnory and input/output devices of difl'erent speeds.
10.20 PERIPHERAL INTERFA: ,:
.lf,] :
Ii'the wait state generator is common fbr aii devices, then it wili introduce wait states --:
DMA cycles of the speed cornpatible devices, because the wait generator decides whether to a: :
rvait state or not, at the falling edge of IOW or NItrMW signal. Hence, extended write mode r- _'..
be used for speed compatibie devices if the wit state generator is common. If the wait s:.:.,
generator is uot used, then extended write morie can be used to access slorn, devices, but :: :
speed of the slow device should be less than, {'s =? where, fs is the speed of cornpatible der':-.
Normal
low
Exterided
low
Fig.10.12.
(4) TC STOP Mode. If the TC stop bit mode set register is set, then 8257 disables t:-.
channel whose TC is reached. In this case, channel is disabled by 8257 itself. If the TC stop t-.
of mode set register is reset, then the corresponding channel must be disabled by t::
rnicrocomputer systern through software. The channel should not be left enabled after termin;
count, in any case. The TC stop bit option should be common for all channels.
(5) Auto Load Mode. If AL bit of mode set register is then the 8257 operates in autoloa:
mode. In this mode the data is transferred by channel 2 only, i.e., other channels are not use:
for data transfer. If the AL bit is set, then the 8257 can be used for repeat block or blocr
chaining operations.
(i) Repeat Bloch Operatiort. If the AL bit is set, the paramcters (memory address an:
terminal count) of CH-2 and TC are cluplicated into CH-3 register it CI{-2 is programmed. I-
this mode, ENS and TC bits are irrelevant. The new parameters are not written into the CH-:
registers. The CH-2 transfers first DMA block between memory and input/output device. After
transferring first DMA block, the 8257 executes an between memory and input/output device
After transferring first DMA block, tbe 8257 executes an 'update cycle'. During this cycle ir
transfers contents ofCII-3 register into CH-2 register and sets update flag in statue register.
After completion of an update cycle, CH-2 transfers two or more,
(ii) Bloclt Clruining Operatiort. In this operation CH-2 transfers two or more different
data blocks. CH-3 must be loaded with different parameters a{'ter initialization of CH-2 registers.
In tiris mode both the channels have to be enabled. The TC stop bit is irrelevant. The autoloaci
timing diagram is shown Fig. 10.13.
Blockt Block2 Block3
Parameter Parameler CH2 update Parameter CH2 update
occurs here occlrrs here
liO Wrile
nro.X3 Oft,4n
Update
flag
Initially CH-2 and CH-S register are lnitialized with Btock 1 and Block 2 pararneters
respectively. Thel, CH-2 transfers data block, between memory and inpuUoutput device.
During
last DNIA cycle it activates TC signal and sets the update flag. The 8257 executes an update
cycle. During this cycle it transfers contents of CH-3 registers into CH-2 registers.
But CH-2
,Lgirt"r, are updated at the end of update cyc1e. To terminate the update cycle, at ieast one
DMA cycle must be executecl. This DMA cycle will be the first DMA cycle of next data block.
The update flag is cleared at the end of frrst DMA cycle of next data block. The microprocessor
w.rites new parameters (block parameter) into CH-3 registers.
(Note that the DRQ2 signal
should be disabled during initialization of CH-3 registers). The CH-2 then transfers second byte
of noxt data block. In this way, CH-2 transfers tow or more data blocks' The TC signal can be
used to interrupt the nicroprocessor.