📄 zdma.c
字号:
/****************************************************************
* ARMSYS S3C44B0X ZDMA mem2mem TEST *
****************************************************************
1.2005.5.17:: ZDMA mem2mem TEST
***************************************************************/
/**********************************************************************
CAUTION: DMA operation is being done in cache-on state NOW.
So,some read value may be not same with real memory value
because of the cache. Users must fully consider the role of
cache after DMA has been being operated. It is the best way
using non-cacheable region in the memory area written by DMA.
**********************************************************************/
#include <string.h>
#include "..\target\44b.h"
#include "..\target\44blib.h"
#include "..\target\def.h"
#include "..\inc\zdma.h"
volatile int zdma0Done,zdma1Done;
void __irq Zdma0Done(void);
void __irq Zdma1Done(void);
void Test_Zdma0(void)
{
unsigned char *src, *dst;
int i;
unsigned int memSum;
rINTMSK=BIT_GLOBAL;
pISR_ZDMA0=(int)Zdma0Done;
Uart_Printf("[内存到内存ZDMA0数据传输测试...]\n");
dst=(unsigned char *)_malloc_(0x80000);
src=(unsigned char *)_malloc_(0x80000);
rNCACHBE1=( ( (((unsigned)dst+0x100000)>>12) +1 )<<16 )|((unsigned)dst>>12);
Uart_Printf("目的地址dst=0x%x,源地址src=0x%x\n",(int)dst,(int)src);
/* Copy by word */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=0x1;
Uart_Printf("\n数据位宽:32bit\n");
Zdma0Int((int)src,(int)dst,0x80000,2); //word
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x80000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
/* Copy by half-word */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=2;
Uart_Printf("\n数据位宽:16bit\n");
Zdma0Int((int)src,(int)dst,0x80000,1); //half-word
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x100000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
/* Copy by byte */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=3;
Uart_Printf("\n数据位宽:8bit\n");
Zdma0Int((int)src,(int)dst,0x80000,0); //byte
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x180000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
_free_(src);
_free_(dst);
}
void Test_Zdma1(void)
{
unsigned char *src, *dst;
int i;
unsigned int memSum;
rINTMSK=BIT_GLOBAL;
pISR_ZDMA1=(int)Zdma1Done;
Uart_Printf("[内存到内存ZDMA1数据传输测试...]\n");
dst=(unsigned char *)_malloc_(0x80000);
src=(unsigned char *)_malloc_(0x80000);
rNCACHBE1=( ( (((unsigned)dst+0x100000)>>12) +1 )<<16 )|((unsigned)dst>>12);
Uart_Printf("目的地址dst=0x%x,源地址src=0x%x\n",(int)dst,(int)src);
/* Copy by word */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=1;
Uart_Printf("\n数据位宽:32bit\n");
Zdma1Int((int)src,(int)dst,0x80000,2); //word
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x80000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
/* Copy by half-word */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=2;
Uart_Printf("\n数据位宽:16bit\n");
Zdma1Int((int)src,(int)dst,0x80000,1); //half-word
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x100000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
/* Copy by byte */
memSum=0;
for(i=0;i<0x80000;i++)
*(src+i)=3;
Uart_Printf("\n数据位宽:8bit\n");
Zdma1Int((int)src,(int)dst,0x80000,0); //byte
for(i=0;i<0x80000;i++)
memSum+=*(dst+i);
Uart_Printf("数据之和=0x%x ----> ",memSum);
if(memSum==0x180000) Uart_Printf("传输O.K.\n");
else Uart_Printf("传输ERROR!!!\n");
_free_(src);
_free_(dst);
}
void Zdma0Int(int srcAddr,int dstAddr,int length,int dw)
//returns the checksum
{
int time;
zdma0Done=0;
rINTMSK=~(BIT_GLOBAL|BIT_ZDMA0);
rZDISRC0=srcAddr|(dw<<30)|(1<<28); //Data size: WORD & address load: Increment
rZDIDES0=dstAddr|( 2<<30)|(1<<28); //Data size: WORD & address load: Increment
rZDICNT0=length |( 2<<28)|(1<<26)|(3<<22)|(0<<20); //whole service & unit transfer mode &
rZDICNT0 |= (1<<20); //after ES3
//whole,unit transfer,int@TC,enable DMA
rZDCON0=0x1; // start!!!
Timer_Start(3); //128us resolution
while(zdma0Done==0);
time=Timer_Stop();
Uart_Printf("ZDMA0 地址:0x%x -> 0x%x,共0x%xbyte \n",srcAddr,dstAddr,length);
//Uart_Printf("速率:%f字节/秒 \n",length/time/128E-6);
rINTMSK=BIT_GLOBAL;
}
void Zdma1Int(int srcAddr,int dstAddr,int length,int dw)
//returns the checksum
{
int time;
zdma1Done=0;
rINTMSK=~(BIT_GLOBAL|BIT_ZDMA1);
rZDISRC1=srcAddr|(dw<<30)|(1<<28); // inc
rZDIDES1=dstAddr|( 2<<30)|(1<<28); // inc
rZDICNT1=length |( 2<<28)|(1<<26)|(3<<22)|(0<<20);
rZDICNT1 |= (1<<20);//after ES3
//whole,unit transfer,int@TC,enable DMA
rZDCON1=0x1; // start!!!
Timer_Start(3);//128us resolution
while(zdma1Done==0);
time=Timer_Stop();
Uart_Printf("ZDMA1 地址:0x%x -> 0x%x,共0x%xbyte \n",srcAddr,dstAddr,length);
//Uart_Printf("速率:%f字节/秒 \n",length/time/128E-6);
rINTMSK=BIT_GLOBAL;
}
void __irq Zdma0Done(void)
{
rI_ISPC=BIT_ZDMA0; //clear pending
//rI_ISPC; //is needed only when cache=on & wrbuf=on & BSFRD=0
zdma0Done=1;
}
void __irq Zdma1Done(void)
{
rI_ISPC=BIT_ZDMA1; //clear pending
//rI_ISPC; //is needed only when cache=on & wrbuf=on & BSFRD=0
zdma1Done=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -