AMD Am186 CC User Manual page 155

Table of Contents

Advertisement

DMA Controller
Example of Using Buffer Queues and Circular Buffers with the UARTs
Note: This section discusses implementation tradeoffs for using the general-purpose DMA
channels. To have a concrete system to discuss, the integrated UART and High-Speed
UART are used as examples, but much of this information is applicable to using the general-
purpose DMA channels with other peripherals as well. In general, there are two distinct
ways that general-purpose DMA can be used: buffer queues and circular buffers. These
two techniques are discussed and contrasted below. In addition, these two methods can
be mixed (e.g., queues of messages for transmit and circular buffers for receive). A careful
analysis of the final system is required to determine the best method to use.
Many systems, especially those communicating with other equipment rather than with
human beings in interactive mode, transmit and receive messages in large blocks. These
messages can be forwarded to a host PC through the USB interface, or forwarded through
an ISDN line or other WAN setup using HDLC. With this sort of message protocol, it may
be advantageous under some circumstances to perform a DMA transfer directly to or from
a queue of buffers, rather than to or from a single circular buffer per direction.
Buffer queues are a viable way to transfer data to and from some devices with general-
purpose DMA. However, buffer queues are only useful for DMA with the UARTs under very
special circumstances.
The primary advantage to using DMA transfer straight from a queue of buffers is the
reduction of data motion. Transmission is relatively straightforward: the DMA channel is
programmed with the correct source address and transfer count for each buffer; and the
DMA channel is set up to stop transmitting and to interrupt when the end of the buffer is
reached. When the interrupt occurs, the buffer is freed, and the next buffer is set up to be
transferred out using DMA.
Reception is more difficult because it is not always known up front exactly how long the
incoming message is. Even if the message size is fixed, line errors can corrupt the perceived
length. For both reception and transmission, issues such as compression, transparency,
and CRC generation and checking mean that software must usually examine each character
individually. In this case, using a circular buffer is generally the best way to use DMA with
a UART (because each character is being read by software anyway, and the number of
characters to be transmitted is different than the number of characters in the original buffer),
although DMA is not necessarily the best way to transfer data to and from the UART.
The determination of whether to use DMA at all for this sort of protocol processing is
dependent on system loading and maximum UART baud rate. If CPU cycles are at a
premium (e.g., for data compression), it may be worthwhile to use DMA.
Many UART serial drivers use circular buffers for temporary storage of incoming and
outgoing characters. The primary drawback to using a circular buffer is that it doubles the
bus bandwidth required to handle each character received or transmitted. For example, if
a string is written out to a serial port, using a circular buffer requires four bus transactions
for each character (read it from the string, write it to the buffer, read it from the buffer, write
it to the transmit port), whereas without the buffer, two transactions would suffice (read the
character from the string, write it to the transmit port). Nevertheless, circular buffers are
popular because the alternative often requires more coding and is usually more error-prone
(e.g., a buffer containing a string could inadvertently be reused before the string is
completely transmitted).
For this reason, the Am186CC/CH/CU microcontrollers' DMA has excellent circular buffer
support. With the general-purpose DMA channels, this is achieved by setting bits in the
GDxCON1 register to a nonzero value to select a buffer size between 1 and 64 Kbytes.
Am186™CC/CH/CU Microcontrollers User's Manual
8-21

Advertisement

Table of Contents
loading

This manual is also suitable for:

Am186 chAm186 cu

Table of Contents