📄 test_dma.c.bak
字号:
#include <string.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "dma.h"
typedef struct{ //can't use __packed???
volatile U32 DISRC; //0x0
volatile U32 DISRCC; //0x4
volatile U32 DIDST; //0x8
volatile U32 DIDSTC; //0xc
volatile U32 DCON; //0x10
volatile U32 DSTAT; //0x14
volatile U32 DCSRC; //0x18
volatile U32 DCDST; //0x1c
volatile U32 DMASKTRIG; //0x20
}DMA;
/*
参数说明:ch :DMA 通道数
srcAddr:源地址
dstAddr:目的地址
tc: 传输数据的大小
*/
void DMA_M2M ( int ch , int SrcAddr , int dstAddr , int tc , int dsz , int burst )
{
int i , time ;
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 ( " [ DMA % d MEMZMEM Test ] \n " , ch ) ;
switch ( ch ) //选择DMA 通道,并进行相应通道的中断设置
{
case 0 :
pISR_DMA0=(int ) Dma0D0ne ;
pINTMSK &=~(BIT_DMA0 ) ;
pDMA =(void * ) 0x4b000000 ;
break ;
case l :
pISR_DMA1 =(int ) Dma1D0ne ;
rINTMSK &=~(BIT_DMA1 ) ;
pDMA =(void * ) 0x4b000040 ;
break ;
case 2 :
pISR_DMA2 =(int ) DmaZD0ne ;
rINTMSK &=~(BIT_DMA2) ;
pDMA =(void * ) 0x4b0000S0 ;
break ;
case 3 :
pIsR _ DMA3 =(int ) Dma3D0ne ;
rINTMSK &=~(BIT_DMA3 ) ;
pDMA =(void * ) 0x4b0000c0 ;
break ;
}
Uart_Printf ( " DMA % d % sxh ->% sxh , 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 ^0x55aasaas ;
memSum0 +=i ^0x55aasaas ;
}
Uart_Printf( " DMA % d start \ n " , ch ) ;
DmaDone =0 ;
/* 下面几条语句设置DMA 相关寄存器 */
pDMA->DISRC =srcAddr ; /*设置DMA 源地址*/
pDMA->DISRCC =(0 << 1 )|( 0 << 0 ) ; // inc , AHB
pDMA->DIDST =dstAddr ; //设置DMA 目的地址
pDMA->DIDSTC =(0 << 1 )|( 0 << 0 ) ; // inc , AHB
pDMA->DC0N =tc | ( IUL << 31 )|( 1 << 30 )|( 1 << 29 )|( burst << 28 )|( 1 << 27 ) l \ ( 0 << 23 )|( 1 << 22 )|( dsz << 20 )|( tc ) ;
// HS , AHB , TC interrupt , wh0le , SW request m0de , relaod 0ff
pDMA->DMASKTRIG =(1 << 1 ) 11 ; // DMA 0n , stTR IG //打开DMA通道
Timer_Start( 3 ) ; // 128us res0luti0n //启动计数器
while( DmaDone ==0 ) ;
time =Timer_Stop() ; //停止计数器
Uart_Printf( " DMA % d end \n " , ch ) ;
rINTMSK |=(BIT_DMA0 | BIT_DMA1 | BIT_DMA2 I BIT_DMA3 ) ; //使能DMA中断
for ( i =dstAddr ; i < dstAddr +length ; i +=4 )
{
memSum1 +=*( ( U32 * ) i )=i ^0x55aasaas ;
}
Uart_Printf ( " memSum0 =%x , memSum1 =%x \n" , memSum0 , memSum1 ) ;
if ( memSum0 ==memSuml ) Uart_Printf (" DMA test result - - - - - --O.K \n" ) ;
else Uart_Printf ( " DMA test result - - - - --ERR0R ! ! ! \n " ) ;
}
/*
DMA 测试函数 void Test_DMA ( void )
功能说明:测试DMA 通道0 , 1 , 2 ,3 ,分别用字节,半字,字方式来传输,来测试性能。
主要代码如下:
*/
void Test_DMA ( void )
{
int ch;
//DMA ch0
for(i=0;i<4;i++)
{
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x80000,0,0);//byte,single
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x40000,1,0);//halfword,single
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x20000,2,0);//word,single
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x80000,0,1);//byte,burst
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x40000,1,1);//halfword,burst
DMA_M2M(i,_NONCACHE_STARTADDRESS ,_NONCACHE_STARTADDRESS+0x80000,0x20000,2,1);//word,burst
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -