Altera_Forum
Honored Contributor
15 years agoHow to connect UART and DMA?
In the document "Embedded Peripherals IP", I find following paragraph:
"The UART core's Avalon-MM interface optionally implements Avalon-MM transfers with flow control. Flow control allows an Avalon-MM master peripheral to write data only when the UART core is ready to accept another character, and to read data only when the core has data available." Can anybody tell me how to implement this flow control, for I always failed to use UART in DMA model. The following code is that I used to write data to UART. Finally I can get "Transfer successful!" , but NO words disappear in the UART Monitor. # include <stdio.h># include <stdlib.h># include "sys/alt_dma.h"# include "altera_avalon_uart_regs.h"# include "system.h"# include "alt_types.h" static volatile int tx_done = 0; volatile static alt_u8 chr[3] = {'A','B','C'} ; static void done (void* handle) { tx_done++; } int main() { int rc; alt_dma_txchan txchan; void* source_buff_ptr = (void*) chr; void* destination_buff_ptr = (void*)IOADDR_ALTERA_AVALON_UART_TXDATA(DEBUG_UART_BASE); if((txchan = alt_dma_txchan_open("/dev/dma")) == NULL) { printf ("Failed to open transmit channel\n"); exit (1); } if ((rc = alt_dma_txchan_ioctl(txchan, ALT_DMA_TX_ONLY_ON, destination_buff_ptr)) < 0) { printf ("Failed to set ioctl, reason = %i\n", rc); exit (1); } if((rc = alt_dma_txchan_ioctl(txchan,ALT_DMA_SET_MODE_8 ,NULL))<0) { printf("Failed to set mode 8\n"); exit(1); } if ((rc = alt_dma_txchan_send(txchan, source_buff_ptr, 3, done, NULL)) < 0) { printf ("Failed to post transmit request, reason = %i\n", rc); exit (1); } while (!tx_done); printf ("Transfer successful!\n"); return 0; }