Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Problems 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);
}

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello,

    For me you code seems ok, and the DMA should work. I also try to work with UART and DMA, in the same way as you, but it does not work. In my case, I looked the status register of DMA after to have launch the transfer, and it seems to work well because the bit LEN and DONE are set to 1, but I have nothing on the UART port.

    Have you solved your problem ?

    Jérôme