Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12604 Discussions

DMA problem on alt_dma_txchan_send

Altera_Forum
Honored Contributor II
1,141 Views

Hi every body. 

I have a problem with the NIOS DMA setting. 

In my system, I need to read data from a device by a MM-Avalon interface, and write the data in a other device with the MM-Avalon interface. The memoryes in the devices are FIFO. The part of my code about DMA is: 

 

# include "system.h" 

# include <io.h> 

# include <stdio.h> 

# include <sys/alt_irq.h> 

 

.... 

 

int rc; 

 

alt_dma_txchan txchan; 

alt_dma_rxchan rxchan; 

 

void* tx_data = (void*) (MC_BASE+MC_READ);  

void* rx_buffer = (void*) (GIGAINT_BASE);  

 

 

if ((txchan = alt_dma_txchan_open(DMA_0_NAME)) == null

ret++; 

 

 

alt_dma_txchan_reg (*pTxchan); 

 

 

if(alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_32,null)<0) 

printf ("Failed to set ALT_DMA_SET_MODE_32 in TX\r\n"); 

 

 

if(alt_dma_txchan_ioctl(txchan,ALT_DMA_RX_ONLY_OFF,tx_data)<0) 

printf ("Failed to set ALT_DMA_RX_ONLY_OFF in TX \r\n"); 

 

 

if(alt_dma_txchan_ioctl(txchan,ALT_DMA_TX_ONLY_ON,tx_data)<0) 

printf ("Failed to set ALT_DMA_TX_ONLY_ON in TX \r\n"); 

 

 

 

 

 

if ((rxchan = alt_dma_rxchan_open(DMA_0_NAME)) == null

ret++; 

 

if(alt_dma_rxchan_ioctl(rxchan,ALT_DMA_SET_MODE_32,null)) 

printf ("Failed to set ALT_DMA_SET_MODE_32 in RX\r\n"); 

 

 

if(alt_dma_rxchan_ioctl(rxchan,ALT_DMA_TX_ONLY_OFF,rx_buffer)) 

printf ("Failed to set ALT_DMA_TX_ONLY_OFF in RX \r\n");  

 

 

if(alt_dma_rxchan_ioctl(rxchan,ALT_DMA_RX_ONLY_ON,rx_buffer)) 

printf ("Failed to set ALT_DMA_RX_ONLY_ON in RX \r\n");  

 

 

rc = alt_dma_txchan_send ( txchan,tx_data,length,null,null); 

if (rc < 0) 

printf ("Failed to post transmit request, reason = %i\r\n", rc); 

 

 

rc = alt_dma_rxchan_prepare (rxchan,rx_buffer,length,done,null); 

if (rc < 0) 

printf ("Failed to post read request, reason = %i\r\n", rc); 

 

 

while (!rx_done); 

 

.... 

 

"done" is the function to call when the DMA end. 

"length" is 256, and teh DMA dimension is 1024 

 

The problem is the function < alt_dma_txchan_send > return -22, but i don't understand where is the bug.  

 

Help me!!! 

 

Thank you 

 

 

 

 

 

0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
378 Views

I had the same issue.  

 

In my case I had accidentally kept the width of DMA length register as 4 bits, resulting in the -22 error you described. To solve this, I adjusted the width of the DMA length register to 13 bits (default setting). This is good enough for most transfers.
0 Kudos
Reply