⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dma.c

📁 嵌入式的DMA功能
💻 C
字号:
//DMA的初始化
int ZDMAInt(uint32 srcAddr, uint32 dstAddr, uint32 Length, int Dw)
{
	int Time;
	ZDMA0Done = 0;
	rINTMSK = ~(BIT_GLOBAL | BIT_ZDMA0);
	rZDISRC0 = srcAddr | (Dw<<30) | (1<<28);    //设置存储区源地址
	rZDIDES0 = dstAddr | (2<<30) | (1<<28);      //设置存储区目的地址
	rZDICNT0 = Length | (2<<28) | (1<<26) | (3<<22) | (1<<20);   //设置传输模式

	rZDCON0 = 0x01;            //启动DMA
	
	Timer_Start(3);               //开始计时
	While(ZDMA0Done == 0);     //等待DMA传送完成
	Time = Timer_Stop();          //完成计时
	UART_Printf(“ZDMA0 %8x->%8x,%x: Time = dms\n”,srcAddr,dstAddr,Length,Time);
                               //输出源/目的地址,数据传输长度,传输时间
	
	rINTMSK = BIT_GLOBAL;
	return Time;                //返回传输时间
}

    //SDRAM与外部存储器之间的数据传输
	void main(void)
{
	uint32 *src,*dst;
	int i;
	uint32 memSum;
	
	rINTMSTK |= BIT_GLOBAL;
	pISR_ZDMA0 = (int)ZDMA0Done;

	UART_Printf(“\n   ZDMA0 SDRAM -? Memory Test  \n”);
	
	src = (uint32 *)0x7fd00000;
	dst = (uint32 *)(0x80000000+4);
	rNCAHBE1 = (((((uint32)dst +0x100000)>>12)+1)<<16) | ((uint32)dst>>12);

	UART_Printf(“ dst = %x, src = %x\n”, (uint32)dst, (uint32)src);

  /* copy by word 字拷贝*/
	memSum = 0;
	for(i = 0; i<tLength; i++)
{
	    memSum += *(dst + i);
}
ZDMA0Int(src, dst, tLength, 2);
UART_Printf(“ Sum of the Memory = %8x: <Copy by word>”, memSum);
if(memSum == tLength)
{
	UART_Printf(“ OK! \n”);
}
else
{
	UART_Printf(“  WRONG! \n”);
}

/*copy by half-word半字拷贝*/
memSum = 0;
for(i = 0 ; i<tLength ; i++)
{
	*(src+i) = 2;
}
ZDMA0Int(src, dst, tLength, 1);
for(i = 0; i<tLength; i++)
{
	memSum += *(dst+1);
}
UART_Printf(“Sum of the memory = %8x:<Copy by half word>”,memSum);
if(memSum == 0x100000)
{
	UART_Printf(“  OK !   \n”);
}
else 
{
	UART_Printf(“  Get ERROR!  \n”);
}

/*copy by byte字节拷贝*/
memSum = 0;
for(i = 0 ; i<tLength ; i++)
{
	*(src+i) = 3;
}
ZDMA0Int(src, dst, tLength, 0);
for(i = 0; i<tLength; i++)
{
	memSum += *(dst+1);
}
UART_Printf(“Sum of the memory = %8x:<Copy by half word>”,memSum);
if(memSum == 0x180000)
{
	UART_Printf(“  OK !   \n”);
}
else 
{
	UART_Printf(“  Get ERROR!  \n”);
}

		free(src);
		free(dst);
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -