📄 dma.c
字号:
/*****************************************
NAME: 24A0dma.c
DESC: DMA memory to memory test
HISTORY:
2003.03.19 Baik Seung Woo ver 0.0
*****************************************/
#include <string.h>
#include "def.h"
#include "option.h"
#include "24a0addr.h"
#include "24a0lib.h"
#include "24a0slib.h"
#include "dma.h"
#include "dma2.h"
#include "extdmam.h"
#include "extdmas.h"
//DMA channel
static void __irq Dma0Done(void);
static void __irq Dma1Done(void);
static void __irq Dma2Done(void);
static void __irq Dma3Done(void);
void M2M_test(int ch, int s_addr, int d_addr, int burst, int dsz, int tc);
static volatile int dmaDone;
void * dma_func[][2]=
{
(void *)Test_DMA, "DMA M2M test(500KB) ",
(void *)Test_DMA_1MH, "DMA M2M test(1MB) ",
(void *)Test_DMAWorst, "DMA 4-ch test ",
(void *)Intro , "EXTDMA main B'd ",
(void *)Test_Dmareq, "EXTDMA REQUEST signal B'd ",
(void *)Memory_Write_test, "Address & data write test ",
0,0
};
void Ch9_DMA(void)
{
while(1)
{
int i = 0;
Uart_Printf("\n");
while(1)
{ //display menu
Uart_Printf("%2d:%s\t",i,dma_func[i][1]);
i++;
if((int)(dma_func[i][0])==0)
{
Uart_Printf("\n");
break;
}
if((i%3)==0)
Uart_Printf("\n");
}
Uart_Printf("\nSelect the function to test : ");
i = Uart_GetIntNum();
Uart_Printf("\n");
if(i==-1) break;
if(i>=0 && (i<(sizeof(dma_func)/8)) )
( (void (*)(void)) (dma_func[i][0]) )();
}
}
void Memory_Write_test(void)
{
volatile U32 i,j;
while(Uart_GetKey()!='\n')
{
Uart_Printf("Type address....:");
i = Uart_GetIntNum();
if(i==-1) break;
Uart_Printf("Type data.... :");
j = Uart_GetIntNum();
if(i==-1) break;
*((U32 *)i) =j;
Uart_Printf("Real Addr & Data %x = %x\n",i,*((U32 *)i));
}
}
void Test_DMA_1MH(void)
{
//ch-0
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 0, 0xffff0);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 1, 0x7fff8);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 2, 0x3fffc);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 0, 0x3fffc);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 1, 0x1fffe);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 2, 0xffff);
//ch-1
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 0, 0xffff0);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 1, 0x7fff8);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 2, 0x3fffc);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 0, 0x3fffc);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 1, 0x1fffe);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 2, 0xffff);
//ch-2
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 0, 0xffff0);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 1, 0x7fff8);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 2, 0x3fffc);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 0, 0x3fffc);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 1, 0x1fffe);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 2, 0xffff);
//ch-3
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 0, 0xffff0);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 1, 0x7fff8);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 0, 2, 0x3fffc);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 0, 0x3fffc);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 1, 0x1fffe);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x100000, 1, 2, 0xffff);
}
void Test_DMA(void)
{
//ch-0
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 0, 0x80000);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 1, 0x40000);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 2, 0x20000);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 0, 0x20000);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 1, 0x10000);
M2M_test(0, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 2, 0x8000);
//ch-1
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 0, 0x80000);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 1, 0x40000);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 2, 0x20000);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 0, 0x20000);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 1, 0x10000);
M2M_test(1, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 2, 0x8000);
//ch-2
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 0, 0x80000);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 1, 0x40000);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 2, 0x20000);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 0, 0x20000);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 1, 0x10000);
M2M_test(2, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 2, 0x8000);
//ch-3
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 0, 0x80000);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 1, 0x40000);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 0, 2, 0x20000);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 0, 0x20000);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 1, 0x10000);
M2M_test(3, _NONCACHE_STARTADDRESS, _NONCACHE_STARTADDRESS + 0x80000, 1, 2, 0x8000);
}
void M2M_test(int ch, int s_addr, int d_addr, int burst, int dsz, int tc)
{
int i,j=0,k=0;
U32 trscount;
volatile U32 memSum0=0, memSum1=0;
if(dsz==0)
{
trscount=tc*(burst ? 4:1)*1;
Uart_Printf("Transfer count1 =%x\n",trscount);
}
else if(dsz==1)
{
trscount=tc*(burst ? 4:1)*2;
Uart_Printf("Transfer count2 =%x\n",trscount);
}
else if(dsz==2)
{
trscount=tc*(burst ? 4:1)*4;
Uart_Printf("Transfer count3 =%x\n",trscount);
}
switch(ch)
{
case 0 :
pISR_DMA = (int)Dma0Done;
rINTMSK = ~(BIT_DMA);
rINTSUBMSK=~(BIT_SUB_DMA0);
break;
case 1 :
pISR_DMA = (int)Dma1Done;
rINTMSK = ~(BIT_DMA);
rINTSUBMSK=~(BIT_SUB_DMA1);
break;
case 2 :
pISR_DMA = (int)Dma2Done;
rINTMSK = ~(BIT_DMA);
rINTSUBMSK=~(BIT_SUB_DMA2);
break;
case 3 :
pISR_DMA = (int)Dma3Done;
rINTMSK = ~(BIT_DMA);
rINTSUBMSK=~(BIT_SUB_DMA3);
break;
}
dmaDone=0;
for(i=s_addr;i<s_addr+trscount;i+=4)
{
*((U32 *)i)=i;
memSum0+=i;
}
Uart_Printf("DMA%d start\n",ch);
switch(ch)
{
case 0 :
rDISRC0=s_addr;
rDISRCC0=(0<<1)|(0<<0);
rDIDST0=d_addr;
rDIDSTC0=(0<<2)|(0<<1)|(0<<0);//Check Interrupt occurrence time
rDCON0=((unsigned)1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|(0<<23)|(1<<22)|(dsz<<20)|(tc);
rDMASKTRIG0=(1<<1)|(1<<0);
break;
case 1 :
rDISRC1=s_addr;
rDISRCC1=(0<<1)|(0<<0);
rDIDST1=d_addr;
rDIDSTC1=(0<<2)|(0<<1)|(0<<0);//Check Interrupt occurrence time
rDCON1=((unsigned)1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|(0<<23)|(1<<22)|(dsz<<20)|(tc);
rDMASKTRIG1=(1<<1)|(1<<0);
break;
case 2 :
rDISRC2=s_addr;
rDISRCC2=(0<<1)|(0<<0);
rDIDST2=d_addr;
rDIDSTC2=(0<<2)|(0<<1)|(0<<0);//Check Interrupt occurrence time
rDCON2=((unsigned)1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|(0<<23)|(1<<22)|(dsz<<20)|(tc);
rDMASKTRIG2=(1<<1)|(1<<0);
break;
case 3 :
rDISRC3=s_addr;
rDISRCC3=(0<<1)|(0<<0);
rDIDST3=d_addr;
rDIDSTC3=(0<<2)|(0<<1)|(0<<0);//Check Interrupt occurrence time
rDCON3=((unsigned)1<<31)|(1<<30)|(1<<29)|(burst<<28)|(1<<27)|(0<<23)|(1<<22)|(dsz<<20)|(tc);
rDMASKTRIG3=(1<<1)|(1<<0);
break;
}
while(dmaDone==0);
Uart_Printf("DMA transfer done.\n");
rINTMSK = BIT_ALLMSK;
rINTSUBMSK=BIT_SUB_ALLMSK;
for(k=d_addr;k<d_addr+trscount;k+=4) //Compare source data with destination data
{
if(*((U32 *)k) != 0x11000000+j)
Uart_Printf("Error!!! Src value=%x, Addr %x=%x\n",0x11000000+j,k,*((U32 *)k));
j=j+4;
}
/*
for(i=d_addr;i<d_addr+trscount;i+=4)
{
memSum1+=*((U32 *)i);
}
Uart_Printf("memSum0=%x,memSum1=%x\n",memSum0,memSum1);
if(memSum0==memSum1)
Uart_Printf("DMA test result......................O.K.\n");
else
Uart_Printf("DMA test result......................ERROR.\n");
*/
}
void __irq Dma0Done(void)
{
//Uart_Printf("Current TC0 : %x\n",rDSTAT0);
rSUBSRCPND=BIT_SUB_DMA0;
ClearPending(BIT_DMA);
dmaDone=1;
}
void __irq Dma1Done(void)
{
//Uart_Printf("Current TC1 : %x\n",rDSTAT1);
rSUBSRCPND=BIT_SUB_DMA1;
ClearPending(BIT_DMA);
dmaDone=1;
}
void __irq Dma2Done(void)
{
//Uart_Printf("Current TC2 : %x\n",rDSTAT2);
rSUBSRCPND=BIT_SUB_DMA2;
ClearPending(BIT_DMA);
dmaDone=1;
}
void __irq Dma3Done(void)
{
//Uart_Printf("Current TC3 : %x\n",rDSTAT3);
rSUBSRCPND=BIT_SUB_DMA3;
ClearPending(BIT_DMA);
dmaDone=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -