Altera_Forum
Honored Contributor
16 years agoProblems with DMA
Hello, I need some help.
I try to use DMA to control UART to send datas on memory, but it failed.#include "altera_avalon_uart_regs.h"# include <stdio.h># include <io.h># include "system.h"# include "alt_types.h"# include "altera_avalon_uart.h"# include "altera_avalon_dma_regs.h"
typedef signed char sint8;
typedef signed short sint16;
typedef signed long sing32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
void Uart_Init(int base)
{
// Baud Rate = (Clock frequency) / ( divisor + 1 )
// divisor = (Clock frequency) / (Baud Rate) - 1
// Now Set the Baud Rate = 115200, so divisor = 15000000 / 115200 - 1 = 129 = 0x81
IOWR_ALTERA_AVALON_UART_DIVISOR(base, 0x81); //Set the Baud Rate = 115200
IOWR_ALTERA_AVALON_UART_CONTROL(base,0); //Disable all related interrupts
IOWR_ALTERA_AVALON_UART_STATUS(base, 0); //Clear Uart Status bits
}
void DMA_Test(int base)
{
volatile int i;
int mode;
void * destinaiton = IOADDR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE);
uint8 source;
for (i = 0; i < 10; i++)
{
source = i + 48;
}
IOWR_ALTERA_AVALON_DMA_STATUS(base, 0); // status bit must be reset
IOWR_ALTERA_AVALON_DMA_RADDRESS(base,(int *)source); // set read address (memory address in this case)
IOWR_ALTERA_AVALON_DMA_WADDRESS(base,(int *)destinaiton); // set write address (peripheral address in this case)
IOWR_ALTERA_AVALON_DMA_LENGTH(base,10); // set dma length
mode = ALTERA_AVALON_DMA_CONTROL_BYTE_MSK |
ALTERA_AVALON_DMA_CONTROL_GO_MSK |
ALTERA_AVALON_DMA_CONTROL_LEEN_MSK |
ALTERA_AVALON_DMA_CONTROL_WCON_MSK |
0;
IOWR_ALTERA_AVALON_DMA_CONTROL(base,mode);
}
int main()
{
Uart_Init(UART_0_BASE);
DMA_Test(DMA_0_BASE);
}