⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdram2uart.txt

📁 将SDRAM中数据通过DMA送至UART,可以通过串口助手查看数据.
💻 TXT
字号:
#include<stdio.h>
#include "system.h"
#include "sys/alt_dma.h"
#include<unistd.h>

/* DMA发送完成标志 */
volatile int dma_tx_done = 0;
//volatile int dma_tx_done2 = 0;
/* DMA完成回调函数 */
void dma_done (void* handle)
{
  dma_tx_done = 1;  /* DMA发送完成*/
}
int main()
{
  alt_dma_txchan txchan;  /* DMA发送通道控制句柄*/
  //alt_dma_rxchan rxchan;
  //static char buf[256]={0};       /*发送数据选通*/
  int i;
  int rc;
 // for(i=0; i<256; i++)
 // { /* 初始化发送数据缓冲 */
 //   buf[i] = i;
 // }
 // void* tx_data = (void*) SDRAM_BASE;                 /* pointer to data to send */
 // void* rx_buffer = (void*) UART_BASE+4; /* on_chip_memory addr*/
 for(i=0;i<3;i++)
 { 
  /* Create the transmit channel */
  if ((txchan = alt_dma_txchan_open("/dev/dma_0")) == NULL)
  {
    printf ("Failed to open transmit channel\n");
  }
  /* Create the receive channel */
 // if ((rxchan = alt_dma_rxchan_open("/dev/dma_0")) == NULL)
 // {
 //   printf ("Failed to open receive channel\n");
 //   exit (1);
 // }
 else
 {
    //for(i=0;i<2;i++)
    //{
    alt_dma_txchan_ioctl (txchan,ALT_DMA_SET_MODE_8,NULL);  
/* 设定DMA控制器向IO外设:UART发送数据 */    
    alt_dma_txchan_ioctl(txchan,ALT_DMA_TX_ONLY_ON,(void*)(UART_BASE+4));  
/* 发送DMA数据传输请求 */ 
  //for(i=0;i<10;i++)
  //{
    if((rc = alt_dma_txchan_send(txchan,SDRAM_BASE+10240+4096*i,4096,dma_done,
                                      NULL))<0){                              
       printf("Fail to send");
       printf("Error is %d.\n",rc);
                                      }                          
 
  while(!dma_tx_done);
  printf("Transfer success!");  /* 发送完成 */
 }
 usleep(25600000);
 }
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -