Dma.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:6k
源码类别:

uCOS

开发平台:

C/C++

  1. /*****************************************
  2.   NAME: dma.c
  3.   DESC: DMA memory2memory test
  4.   HISTORY:
  5.   2003.05.15:Leon YH KIM: draft ver 0.0
  6.  *****************************************/
  7. #include <string.h>
  8. #include "def.h"
  9. #include "option.h"
  10. #include "2440addr.h"
  11. #include "2440lib.h"
  12. #include "2440slib.h" 
  13. static void __irq Dma0Done(void);
  14. static void __irq Dma1Done(void);
  15. static void __irq Dma2Done(void);
  16. static void __irq Dma3Done(void);
  17. void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst);
  18. typedef struct tagDMA
  19. {
  20.     volatile U32 DISRC;     //0x0
  21.     volatile U32 DISRCC;    //0x4
  22.     volatile U32 DIDST;     //0x8
  23.     volatile U32 DIDSTC;    //0xc
  24.     volatile U32 DCON;     //0x10
  25.     volatile U32 DSTAT;     //0x14
  26.     volatile U32 DCSRC;     //0x18
  27.     volatile U32 DCDST;     //0x1c
  28.     volatile U32 DMASKTRIG; //0x20
  29. }DMA;
  30. static volatile int dmaDone;
  31. void Test_DMA(void)
  32. {
  33.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000, 0x8000,2,1); //word,burst
  34.     //DMA Ch 0
  35.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x80000,0,0); //byte,single
  36.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x40000,1,0); //halfword,single
  37.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,2,0); //word,single
  38.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,0,1); //byte,burst
  39.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x10000,1,1); //halfword,burst
  40.     DMA_M2M(0,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000, 0x8000,2,1); //word,burst
  41.     //DMA Ch 1
  42.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x80000,0,0); //byte,single
  43.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x40000,1,0); //halfword,single
  44.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,2,0); //word,single
  45.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,0,1); //byte,burst
  46.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x10000,1,1); //halfword,burst
  47.     DMA_M2M(1,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000, 0x8000,2,1); //word,burst
  48.     //DMA Ch 2
  49.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x80000,0,0); //byte,single
  50.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x40000,1,0); //halfword,single
  51.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,2,0); //word,single
  52.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,0,1); //byte,burst
  53.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x10000,1,1); //halfword,burst
  54.     DMA_M2M(2,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000, 0x8000,2,1); //word,burst
  55.     //DMA Ch 3
  56.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x80000,0,0); //byte,single
  57.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x40000,1,0); //halfword,single
  58.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,2,0); //word,single
  59.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x20000,0,1); //byte,burst
  60.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000,0x10000,1,1); //halfword,burst
  61.     DMA_M2M(3,_NONCACHE_STARTADDRESS,_NONCACHE_STARTADDRESS+0x800000, 0x8000,2,1); //word,burst   
  62. }
  63. void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst)
  64. {
  65.     int i,time;
  66.     volatile U32 memSum0=0,memSum1=0;
  67.     DMA *pDMA;
  68.     int length;
  69.     
  70.     length=tc*(burst ? 4:1)*((dsz==0)+(dsz==1)*2+(dsz==2)*4);
  71.     
  72.     Uart_Printf("[DMA%d MEM2MEM Test]n",ch);
  73.     switch(ch)
  74.     {
  75.     case 0:
  76.      pISR_DMA0=(int)Dma0Done;
  77.      rINTMSK&=~(BIT_DMA0);  
  78.      pDMA=(void *)0x4b000000;
  79.      break;
  80.     case 1:
  81.      pISR_DMA1=(int)Dma1Done;
  82.      rINTMSK&=~(BIT_DMA1);  
  83.      pDMA=(void *)0x4b000040;
  84.      break;
  85.     case 2:
  86. pISR_DMA2=(int)Dma2Done;
  87.      rINTMSK&=~(BIT_DMA2);  
  88.      pDMA=(void *)0x4b000080;
  89. break;
  90.     case 3:
  91.         pISR_DMA3=(int)Dma3Done;
  92.         rINTMSK&=~(BIT_DMA3);  
  93.         pDMA=(void *)0x4b0000c0;
  94.         break;
  95.     }
  96.                                                                                                                             
  97.     Uart_Printf("DMA%d %8xh->%8xh,size=%xh(tc=%xh),dsz=%d,burst=%dn",ch, srcAddr,dstAddr,length,tc,dsz,burst);
  98.     Uart_Printf("Initialize the src.n");
  99.     
  100.     for(i=srcAddr;i<(srcAddr+length);i+=4)
  101.     {
  102.      *((U32 *)i)=i^0x55aa5aa5;
  103.      memSum0+=i^0x55aa5aa5;
  104.     }
  105.     Uart_Printf("DMA%d startn",ch);
  106.     
  107.     dmaDone=0;
  108.     
  109.     pDMA->DISRC=srcAddr;
  110.     pDMA->DISRCC=(0<<1)|(0<<0); // inc,AHB
  111.     pDMA->DIDST=dstAddr;
  112.     pDMA->DIDSTC=(0<<2) | (0<<1)|(0<<0); // inc,AHB
  113.     pDMA->DCON=tc|(1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|
  114.              (0<<23)|(1<<22)|(dsz<<20)|(tc);
  115.      //HS,AHB,TC interrupt,whole, SW request mode,relaod off
  116.     pDMA->DMASKTRIG=(1<<1)|1; //DMA on, SW_TRIG
  117.     Timer_Start(3);//128us resolution       
  118.     while(dmaDone==0);
  119.     time=Timer_Stop();
  120.     
  121.     Uart_Printf("DMA transfer done. time=%f, %fMB/Sn",(float)time/ONESEC3, length/((float)time/ONESEC3)/1000000.);
  122.     rINTMSK=BIT_ALLMSK;
  123.     
  124.     for(i=dstAddr;i<dstAddr+length;i+=4)
  125.     {
  126.      memSum1+=*((U32 *)i)=i^0x55aa5aa5;
  127.     }
  128.     
  129.     Uart_Printf("memSum0=%x,memSum1=%xn",memSum0,memSum1);
  130.     if(memSum0==memSum1)
  131.      Uart_Printf("DMA test result--------------------------------------O.K.n");
  132.     else 
  133.      Uart_Printf("DMA test result--------------------------------------ERROR!!!n");
  134. }
  135. static void __irq Dma0Done(void)
  136. {
  137.     ClearPending(BIT_DMA0);
  138.     dmaDone=1;
  139. }
  140. static void __irq Dma1Done(void)
  141. {
  142.     ClearPending(BIT_DMA1);
  143.     dmaDone=1;
  144. }
  145. static void __irq Dma2Done(void)
  146. {
  147.     ClearPending(BIT_DMA2);
  148.     dmaDone=1;
  149. }
  150. static void __irq Dma3Done(void)
  151. {
  152.     ClearPending(BIT_DMA3);
  153.     dmaDone=1;
  154. }