This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

General DMA UART implementation

Dear All,

I am trying to implement a generic DMA-version of the buffered, interrupt-driven UART-driver, and realized that it is not that straightforward, so I thought I would ask some more experienced developers for some ideas/hints/design guidelines.

The goal is to be able to transmit arrays of data (messages) varying in length and frequency at high speed (with a good combination of overhead, resource need and latency). The examples I found usually expects fixed length and/or fixed interval data transfers (ADC, SPI etc.)

The reason I am looking for a solution is that although the interrupt-driven, (ring-)buffered UART implementation is simple, elegant and effective, at high speeds (2-5-10 Mbps) it introduces a undesirable amount of processing overhead. This is usually where DMA comes to the picture.

At first glance for the DMA-version there is a need for some buffering as being non-blocking (for reasonable amount of data) is a requirement.

The following ideas came to my mind:

Add the message to the ring-buffer, then

  1. use basic/single shot DMA-transfer for the entire message. Pro: easy to implement. Con: 1. need to separate to two transmits if the write pointer is below the read one; 2. A large message blocks the buffer until the transmission is complete.
  2. use 1. but transmit fixed chunks of data. Pro: less resource need; Con: harder to implement, need to handle fractions of chunks.
  3. overlay a ping-pong buffer over the ring-buffer (divide by half). Pro: easy to implement. Con: 1. introduces latency, if the messages are small and infrequent; 2. need to turn on/off regularly; 3. halves the buffer size (one half is usable, one half is being transmitted)
  4. divide the ring-buffer to n equal blocks and use scatter-gather by turning on/off blocks based on the ring-buffer pointers. Pro: sounds nice but Con: all the above... :)

I would be really grateful if you would share your thoughts.

Marton

  • Hello Marton

    There is another method. The first N bytes of a message is always the size of the incoming packet. Once this is know a ping-pong mechanism can be programmed to read the size worth of data (limited by 1024 element restriction of the DMA control structure). Only the first N bytes of message which hold the size are interrupt driven.

    Regards
    Amit