?? dma.c
字號:
/*****************************************
NAME: dma.c
DESC: DMA memory2memory test
HISTORY:
2001.03.31:purnnamu: draft ver 0.0
*****************************************/
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
static void __irq Dma0Done(void);
static void __irq Dma1Done(void);
static void __irq Dma2Done(void);
static void __irq Dma3Done(void);
//ch->DMA 通道數(shù); srcAddr->源地址; dstAddr->目的地址; tc->傳輸數(shù)據(jù)的大小
//dsz->Data size to be transferred; burst->Initial transfer count
void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst);
typedef struct tagDMA
{
volatile U32 DISRC; //0x0 DMA initial source register
volatile U32 DISRCC; //0x4 DMA initial source control register
volatile U32 DIDST; //0x8 DMA initial destination register
volatile U32 DIDSTC; //0xc DMA initial destination control register
volatile U32 DCON; //0x10 DMA control register
volatile U32 DSTAT; //0x14 DMA count register
volatile U32 DCSRC; //0x18 DMA current Source Register
volatile U32 DCDST; //0x1c DMA current destination register
volatile U32 DMASKTRIG; //0x20 DMA mask trigger register
}DMA;
static volatile int dmaDone;
void Test_DMA(void)
{
//DMA Ch 0
DMA_M2M(0,0x31000000,0x30000000+0x800000,0x10,0,0); //byte,single
}
void DMA_M2M(int ch,int srcAddr,int dstAddr,int tc,int dsz,int burst)
{
int i;
volatile U32 memSum0=0,memSum1=0;
DMA *pDMA;
int length;
length=tc*(burst ? 4:1)*((dsz==0)+(dsz==1)*2+(dsz==2)*4);
Uart_Printf("GEC2440 DMA CH%d MEM-MEM Test\n",ch);
switch(ch)
{
case 0:
pISR_DMA0=(int)Dma0Done;
rINTMSK&=~(BIT_DMA0);
pDMA=(void *)0x4b000000;
break;
case 1:
pISR_DMA1=(int)Dma1Done;
rINTMSK&=~(BIT_DMA1);
pDMA=(void *)0x4b000040;
break;
case 2:
pISR_DMA2=(int)Dma2Done;
rINTMSK&=~(BIT_DMA2);
pDMA=(void *)0x4b000080;
break;
case 3:
pISR_DMA3=(int)Dma3Done;
rINTMSK&=~(BIT_DMA3);
pDMA=(void *)0x4b0000c0;
break;
}
Uart_Printf("DMA%d %8xh->%8xh,size=%xh(tc=%xh),dsz=%d,burst=%d\n",ch,
srcAddr,dstAddr,length,tc,dsz,burst);
Uart_Printf("Initialize the src.\n");
for(i=srcAddr;i<(srcAddr+length);i+=4)
{
*((U32 *)i)=i^0x55aa5aa5;
memSum0+=i^0x55aa5aa5;
}
Uart_Printf("DMA%d start\n",ch);
dmaDone=0;
pDMA->DISRC=srcAddr;
pDMA->DISRCC=(0<<1)|(0<<0); // inc,AHB
pDMA->DIDST=dstAddr;
pDMA->DIDSTC=(0<<1)|(0<<0); // inc,AHB
pDMA->DCON=tc|(1<<31)|(1<<30)|(burst<<28)|(1<<27)|\
(0<<23)|(1<<22)|(dsz<<20)|(tc);
//HS,AHB,TC interrupt,whole, SW request mode,relaod off
pDMA->DMASKTRIG=(1<<1)|1; //DMA on, SW_TRIG
while(1)
{
if(!(pDMA->DSTAT&(0x3<<20)))
break;
}
Uart_Printf("DMA transfer done\n");
rINTMSK=BIT_ALLMSK;
for(i=dstAddr;i<dstAddr+length;i+=4)
{
memSum1+=*((U32 *)i)=i^0x55aa5aa5;
}
Uart_Printf("GEC2440 DMA CH%d MEM-MEM Test Finished\n",ch);
}
static void __irq Dma0Done(void)
{
ClearPending(BIT_DMA0);
dmaDone=1;
}
static void __irq Dma1Done(void)
{
ClearPending(BIT_DMA1);
dmaDone=1;
}
static void __irq Dma2Done(void)
{
ClearPending(BIT_DMA2);
dmaDone=1;
}
static void __irq Dma3Done(void)
{
ClearPending(BIT_DMA3);
dmaDone=1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -