Nios® V Processor Software Developer Handbook

ID 743810
Date 10/31/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.9.1. DMA Transmit Channels

DMA transmit requests are queued using a DMA transmit device handle. To obtain a handle, use the function alt_dma_txchan_open(). This function takes a single argument, the name of a device to use, as defined in system.h.

Obtaining a File Handle for a DMA Transmit Device dma_0

#include <stddef.h>

#include "sys/alt_dma.h"

int main(void) {
  alt_dma_txchan tx;
  tx = alt_dma_txchan_open("/dev/dma_0");
  if (tx == NULL) {
    /* Error */
  } else {
    /* Success */
  }
  return 0;
}

You can use this handle to post a transmit request using alt_dma_txchan_send(). The prototype is:

typedef void(alt_txchan_done)(void * handle);
int alt_dma_txchan_send(alt_dma_txchan dma,
  const void * from,
    alt_u32 length,
    alt_txchan_done * done,
    void * handle);

Calling alt_dma_txchan_send() posts a transmit request to channel dma. Argument length specifies the number of bytes of data to transmit, and argument from specifies the source address. The function returns before the full DMA transaction completes. The return value indicates whether the request is successfully queued. A negative return value indicates that the request failed. When the transaction completes, the user-supplied function done is called with argument handle to provide notification.

Two additional functions are provided for manipulating DMA transmit channels: alt_dma_txchan_space(), and alt_dma_txchan_ioctl(). The alt_dma_txchan_space() function returns the number of additional transmit requests that can be queued to the device. The alt_dma_txchan_ioctl()function performs device-specific manipulation of the transmit device.

Note: If you are using the Avalon Memory-Mapped® (Avalon-MM®) DMA device to transmit to hardware (not memory-to-memory transfer), call the alt_dma_txchan_ioctl()function with the request argument set to ALT_DMA_TX_ONLY_ON.