Leicester University Department of Engineering Microprocessors
Leicester University Department of Engineering Microprocessors
doc
Special hardware writes to / reads from memory directly (without CPU intervention) and saves the
timing associated with op-code fetch and decoding, increment and test addresses of source and
destination.
The DMA controller may either stop the CPU and access the memory (cycle stealing DMA) or use the
bus while the CPU is not using it (hidden cycle DMA).
The DMA controller has some control lines (to do a handshake with the CPU negotiating to be a bus
master and to emulate the CPU behaviour while accessing the memory), an address register which is
auto-incremented (or auto-decremented) at each memory access, and a counter used to check for final
byte (or word) count.
- At the End-of-Count the DMA controller may generate an interrupt request to tell the CPU:
'I have done a DMA operation. New data is available'.
DMA is commonly required to interface fast I/O devices such as video frame grabbers and hard disks:
1
s
video frame grabber: 512 x 512 bytes in 50 means that the transfer rate must be ≅ 13.1 MBytes/s
seek time - time to move the arm to the desired track (9 ms - 20 ms)
rotation latency - time for the desired sector to rotate under the head. Average = halfway turn
(3600rpm - 5400rpm)
transfer time - time to transfer a block of bits / bytes (2 - 4 MB/s)
controller time - overhead of electronics (a few milliseconds)
Example: What is the average time to read or write a 512-byte sector for a typical disk rotating @ 4000
rpm? The advertised seek time is 18 ms, the transfer rate is 2 MB/s, and the controller overhead is 2
ms.
Bus arbitration
Bus arbitration is the term used to describe the mechanism and the sequence of events that take place
when another potential bus master requests the buses and is granted the use of the buses. In other
words, deciding which potential bus master gets to use the bus next is called bus arbitration. For the
MC68000 bus arbitration consists of the following:
BR - The bus request signal is assigned by the potential bus master to the 68000 and signals intent to
use the buses. This signal indicates
BG - The bus grant signal is assigned by the 68000 in response to a BR , and means that the bus will
be released at the end of the current bus cycle. When BG is asserted BR can be de-asserted. BG can
be routed through a daisy chain or through a specific priority-encoded circuit.
BGACK - At the end of the current bus cycle the potential bus master takes control of the system
buses and asserts a bus grant acknowledge signal to inform the old bus master that it is now
controlling the buses. This signal should not be asserted until the following conditions are met:
NuBus has four arbitration lines. A candidate to bus master asserts its arbitration level on the 4-bit
open collector arbitration bus. If a competing master sees a higher level on the bus than its own level,
it ceases to compete for the bus. Each potential bus master simultaneously drives and samples the bus.
When one bus master has gained bus mastership and then relinquished it, it would not attempt to re-
establish bus mastership until all pending bus requests have been dealt with (fairness).
Here is an example of the steps that occur to cause and perform a DMA transfer. In this example, the
floppy disk controller (FDC) has just read a byte from a diskette and wants the DMA to place it in
memory at location 0x00123456. The process begins by the FDC asserting the DRQ2 signal (the DRQ
line for DMA channel 2) to alert the DMA controller.
The DMA controller will note that the DRQ2 signal is asserted. The DMA controller will then make
sure that DMA channel 2 has been programmed and is unmasked (enabled). The DMA controller also
makes sure that none of the other DMA channels are active or want to be active and have a higher
priority. Once these checks are complete, the DMA asks the CPU to release the bus so that the DMA
may use the bus. The DMA requests the bus by asserting the HRQ signal which goes to the CPU.
The CPU detects the HRQ signal, and will complete executing the current instruction. Once the
processor has reached a state where it can release the bus, it will. Now all of the signals normally
generated by the CPU (-MEMR, -MEMW, -IOR, -IOW and a few others) are placed in a tri-stated
condition (neither high or low) and then the CPU asserts the HLDA signal which tells the DMA
controller that it is now in charge of the bus.
Depending on the processor, the CPU may be able to execute a few additional instructions now that it
no longer has the bus, but the CPU will eventually have to wait when it reaches an instruction that
must read something from memory that is not in the internal processor cache or pipeline.
Now that the DMA ``is in charge'', the DMA activates its -MEMR, -MEMW, -IOR, -IOW output
signals, and the address outputs from the DMA are set to 0x3456, which will be used to direct the byte
that is about to transferred to a specific memory location.
The DMA will then let the device that requested the DMA transfer know that the transfer is
commencing. This is done by asserting the -DACK signal, or in the case of the floppy disk controller,
-DACK2 is asserted.
The floppy disk controller is now responsible for placing the byte to be transferred on the bus Data
lines. Unless the floppy controller needs more time to get the data byte on the bus (and if the peripheral
does need more time it alerts the DMA via the READY signal), the DMA will wait one DMA clock,
and then de-assert the -MEMW and -IOR signals so that the memory will latch and store the byte that
was on the bus, and the FDC will know that the byte has been transferred.
Since the DMA cycle only transfers a single byte at a time, the FDC now drops the DRQ2 signal, so
the DMA knows that it is no longer needed. The DMA will de-assert the -DACK2 signal, so that the
FDC knows it must stop placing data on the bus.
The DMA will now check to see if any of the other DMA channels have any work to do. If none of the
channels have their DRQ lines asserted, the DMA controller has completed its work and will now tri-
state the -MEMR, -MEMW, -IOR, -IOW and address signals.
Finally, the DMA will de-assert the HRQ signal. The CPU sees this, and de-asserts the HOLDA signal.
Now the CPU activates its -MEMR, -MEMW, -IOR, -IOW and address lines, and it resumes executing
instructions and accessing main memory and the peripherals.
For a typical floppy disk sector, the above process is repeated 512 times, once for each byte. Each time
a byte is transferred, the address register in the DMA is incremented and the counter in the DMA that
shows how many bytes are to be transferred is decremented.
When the counter reaches zero, the DMA asserts the EOP signal, which indicates that the counter has
reached zero and no more data will be transferred until the DMA controller is reprogrammed by the
CPU. This event is also called the Terminal Count (TC). There is only one EOP signal, and since only
DMA channel can be active at any instant, the DMA channel that is currently active must be the DMA
channel that just completed its task.
If a peripheral wants to generate an interrupt when the transfer of a buffer is complete, it can test for its
-DACKn signal and the EOP signal both being asserted at the same time. When that happens, it means
the DMA will not transfer any more information for that peripheral without intervention by the CPU.
The peripheral can then assert one of the interrupt signals to get the processors' attention. In the PC
architecture, the DMA chip itself is not capable of generating an interrupt. The peripheral and its
associated hardware is responsible for generating any interrupt that occurs. Subsequently, it is possible
to have a peripheral that uses DMA but does not use interrupts.
It is important to understand that although the CPU always releases the bus to the DMA when the
DMA makes the request, this action is invisible to both applications and the operating systems, except
for slight changes in the amount of time the processor takes to execute instructions when the DMA is
active. Subsequently, the processor must poll the peripheral, poll the registers in the DMA chip, or
receive an interrupt from the peripheral to know for certain when a DMA transfer has completed.
lect_dma.doc
FSS