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

📄 dma.c

📁 smdk40100 40mhz test code
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************/
/*				DMA Function Test				*/
/* Function : dma.c								*/
/* Description : DMA Test Routine						*/
/* Author : Yong Hyeon Kim	E-mail: telecom2@sec.samsung.com		*/
/* Note : 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 "..\include\k401.h"
#include "..\include\k401lib.h"
#include "..\include\def.h"
#include "..\include\dma.h"

volatile int dma0stop;
volatile int dma1stop;

void __irq Dma0Done(void);
void __irq Dma1Done(void);
void __irq ExtDma0Done(void);

int DMA0_Int_Single(void);
int DMA1_Int_Block(void);
int DMA0_Pol_Block(void);
int DMA1_Pol_Single(void);
int DMA0_ISRAM2MEM(void);
int DMA1_MEM2ISRAM(void);

void DMA0INT_Single(int srcAddr, int dstAddr, int length, int dw);
void DMA1INT_Block(int srcAddr, int dstAddr, int length, int dw);
void DMA0POL_Block(int srcAddr, int dstAddr, int length, int dw);
void DMA1POL_Single(int srcAddr, int dstAddr, int length, int dw);
void ExtDMA0INT_Single(int srcAddr, int dstAddr, int length, int dw);

int Test_DMA(void)
{
    int isYes;

    Uart_Printf("DMA Function Test\n");
    Uart_Printf("=========================================================================\n");
    Uart_Printf(" #1: ");

    isYes=0;
    isYes+=DMA0_Int_Single();

    Uart_Printf(" #2: ");
    isYes+=DMA1_Int_Block();

    Uart_Printf(" #3: ");
    isYes+=DMA0_Pol_Block();

    Uart_Printf(" #4: ");
    isYes+=DMA1_Pol_Single();

    Uart_Printf(" #5: ");
    isYes+=DMA0_ISRAM2MEM();

    Uart_Printf(" #6: ");
    isYes+=DMA1_MEM2ISRAM();

    Uart_Printf("=========================================================================\n");
    if(isYes==6)Uart_Printf("DMA Function Test OK!!!!\n");
    else Uart_Printf("DMA Function Test Fail!!!\n");
}

int DMA0_Int_Single(void)
{
    int isYes=0;
    U8 *src, *dst;
    int i, memsum;

    rSYSCON&=~(BIT_GLOBAL);

    Uart_Printf("  DMA0 Memory to Memory transfer Test(Stop Interrupt, Single Mode)\n");

    dst=(U8 *)((int)malloc(0x100000)+0x8000000);
    src=(U8 *)((int)malloc(0x100000)+0x8000000);
    Uart_Printf("  Source Address=0x%x, Destination Address=0x%x\n",src,dst);

    pISR_DMA0=(unsigned)Dma0Done;

    // Copy by Word
    // Source Data Write

    rINTPND=~(BIT_DMA0);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA0;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=1;

    DMA0INT_Single((int)src, (int)dst, 0x40000, 2); // Transfer Width=Word(32-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x100000)
    {
	Uart_Printf(", Word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Word transfer Fail!!!\n");

    // Copy by Half-word
    // Source Data Write

    rINTPND=~(BIT_DMA0);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA0;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=2;

    DMA0INT_Single((int)src, (int)dst, 0x80000, 1); // Transfer Width=Half-word(16-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x200000)
    {
	Uart_Printf(", Half-word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Half-word transfer Fail!!!\n");

    // Copy by Byte
    // Source Data Write

    rINTPND=~(BIT_DMA0);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA0;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=3;

    DMA0INT_Single((int)src, (int)dst, 0x100000, 0); // Transfer Width=Byte(8-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x300000)
    {
	Uart_Printf(", Byte transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Byte transfer Fail!!!\n");

    free(src-0x8000000);
    free(dst-0x8000000);

    if(isYes==3) return 1;
    else return 0;
}

int DMA1_Int_Block(void)
{
    int isYes=0;
    U8 *src, *dst;
    int i, memsum;

    rSYSCON&=~(BIT_GLOBAL);

    Uart_Printf("  DMA1 Memory to Memory transfer Test(Stop Interrupt, Block Mode)\n");

    dst=(U8 *)((int)malloc(0x100000)+0x8000000);
    src=(U8 *)((int)malloc(0x100000)+0x8000000);
    Uart_Printf("  Source Address=0x%x, Destination Address=0x%x\n",src,dst);

    pISR_DMA1=(unsigned)Dma1Done;

    // Copy by Word
    // Source Data Write

    rINTPND=~(BIT_DMA1);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA1;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=1;

    DMA1INT_Block((int)src, (int)(dst+0xffffc), 0x40000, 2); // Transfer Width=Word(32-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x100000)
    {
	Uart_Printf(", Word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Word transfer Fail!!!\n");

    // Copy by Half-word
    // Source Data Write

    rINTPND=~(BIT_DMA1);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA1;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=2;

    DMA1INT_Block((int)src, (int)(dst+0xffffe), 0x80000, 1); // Transfer Width=Half-word(16-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x200000)
    {
	Uart_Printf(", Half-word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Half-word transfer Fail!!!\n");

    // Copy by Byte
    // Source Data Write

    rINTPND=~(BIT_DMA1);		//clear pending status bit
    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_DMA1;			//support service program

    for(i=0; i<0x100000; i++)
	*(src+i)=3;

    DMA1INT_Block((int)src, (int)(dst+0xfffff), 0x100000, 0); // Transfer Width=Byte(8-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x300000)
    {
	Uart_Printf(", Byte transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Byte transfer Fail!!!\n");

    free(src-0x8000000);
    free(dst-0x8000000);

    if(isYes==3) return 1;
    else return 0;
}

int DMA0_Pol_Block(void)
{
    int isYes=0;
    U8 *src, *dst;
    int i, memsum;

    rSYSCON&=~(BIT_GLOBAL);

    Uart_Printf("  DMA0 Memory to Memory transfer Test(No Stop Interrupt, Block Mode)\n");

    dst=(U8 *)((int)malloc(0x100000)+0x8000000);
    src=(U8 *)((int)malloc(0x100000)+0x8000000);
    Uart_Printf("  Source Address=0x%x, Destination Address=0x%x\n",src,dst);

    // Copy by Word
    // Source Data Write

    for(i=0; i<0x100000; i++)
	*(src+i)=1;

    DMA0POL_Block((int)(src+0xffffc), (int)dst, 0x40000, 2); // Transfer Width=Word(32-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x100000)
    {
	Uart_Printf(", Word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Word transfer Fail!!!\n");

    // Copy by Half-word
    // Source Data Write

    for(i=0; i<0x100000; i++)
	*(src+i)=2;

    DMA0POL_Block((int)(src+0xffffe), (int)dst, 0x80000, 1); // Transfer Width=Half-word(16-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x200000)
    {
	Uart_Printf(", Half-word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Half-word transfer Fail!!!\n");

    // Copy by Byte
    // Source Data Write

    for(i=0; i<0x100000; i++)
	*(src+i)=3;

    DMA0POL_Block((int)(src+0xfffff), (int)dst, 0x100000, 0); // Transfer Width=Byte(8-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x300000)
    {
	Uart_Printf(", Byte transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Byte transfer Fail!!!\n");

    free(src-0x8000000);
    free(dst-0x8000000);

    if(isYes==3) return 1;
    else return 0;
}

int DMA1_Pol_Single(void)
{
    int isYes=0;
    U8 *src, *dst;
    int i, memsum;

    rSYSCON&=~(BIT_GLOBAL);

    Uart_Printf("  DMA1 Memory to Memory transfer Test(No Stop Interrupt, Single Mode)\n");

    dst=(U8 *)((int)malloc(0x100000)+0x8000000);
    src=(U8 *)((int)malloc(0x100000)+0x8000000);
    Uart_Printf("  Source Address=0x%x, Destination Address=0x%x\n",src,dst);

    // Copy by Word
    // Source Data Write

    for(i=0; i<0x100000; i++)
	*(src+i)=1;

    DMA1POL_Single((int)(src+0xffffc), (int)(dst+0xffffc), 0x40000, 2); // Transfer Width=Word(32-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x100000)
    {
	Uart_Printf(", Word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Word transfer Fail!!!\n");

    // Copy by Half-word
    // Source Data Write

    for(i=0; i<0x100000; i++)
	*(src+i)=2;

    DMA1POL_Single((int)(src+0xffffe), (int)(dst+0xffffe), 0x80000, 1); // Transfer Width=Half-word(16-bit)

    // Destination Data Read
    memsum=0;
    for(i=0; i<0x100000; i++)
	memsum+=*(dst+i);

    if(memsum==0x200000)
    {
	Uart_Printf(", Half-word transfer OK!!!\n");
	isYes+=1;
    }
    else Uart_Printf(", Half-word transfer Fail!!!\n");

    // Copy by Byte
    // Source Data Write

    for(i=0; i<0x100000; i++)

⌨️ 快捷键说明

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