📄 dma.c
字号:
Print("\nSource Data is %02x at Addr %08x", *SrcAddr, SrcAddr); Print("\nDestination Data is %02x at Addr %08x", *DstAddr, DstAddr); return(0); } DstAddr++; SrcAddr++; }// return(1);}//////////////////////////////////////////////////////////////////////////////// // GDMA Memory to Memory test Module /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void GdmaMemMemTest(void){ U32 gdmacon; // control register U32 gdmasrc; // source address register U32 gdmadst; // destination address register U32 gdmacnt; // counter register int channel; // GDMA channel int repeat; // repeat count int bsize; // byte count int rvl; // U8 it; int j; // repeat num// rvl = 1; Print("\n\nGDMA memory to memory test");// Get GDMA Channel //////////////////////////////////////////////////////////// while(1) { Print("\nSelect GDMA Channel [0/1/Q]"); channel = get_upper(); if((channel == '1') || (channel == '0')) { channel -= '0'; break; } else if(channel == 'Q') { return; } } // Setup memory to memory gdma transfer ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// destination address ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// gdmadst = (U32) GDMATestDst; // default destination addr Print("\nChange Default Dest. Address (0x%08x)[Y/N/Q]", gdmadst); it = get_upper(); if(it == 'Q') { return; } else if(it == 'Y') {// change destination address ////////////////////////////////////////////////// Print("\nInput Destination Address 0x"); gdmadst = get_number(16,0); if(gdmadst == 0) { gdmadst = (U32) GDMATestDst; // default destination addr } } ////////////////////////////////////////////////////////////////////////////////// source address ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// gdmasrc = (U32) GDMATestSrc; // default source addr Print("\nChange Default Src. Address (0x%08x) [Y/N/Q]", gdmasrc); it = get_upper(); if(it == 'Q') { return; } else if(it == 'Y') {// change default destination address ////////////////////////////////////////// Print("\nInput Source Address 0x"); gdmasrc = get_number(16,0); if(gdmasrc == 0) { gdmasrc = (U32) GDMATestSrc; // default source addr } }////////////////////////////////////////////////////////////////////////////////// memory size (in bytes) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// gdmacnt = (U32) GDMATestSize; Print("\nChange Default Size (0x%08x) [Y/N/Q]", gdmacnt); it = get_upper(); if(it == 'Q') { return; } else if(it == 'Y') {// change default test size //////////////////////////////////////////////////// Print("\nInput Memory Test Size 0x"); gdmacnt = get_number(16,0); if(gdmacnt == 0) { gdmacnt = (U32) GDMATestSize; }// if(gdmacnt < 4) { gdmacnt = 4; } gdmacnt = (gdmacnt / 4) * 4; } /////////////////////////////////////////////////////////////////////////////// if(channel == 0) { gdmacon = GDMACON0; } else { gdmacon = GDMACON1; } // bsize = gdmacnt; // size in bytes///////////////////////////////////////////////////////////////////////////////// repeat count ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Print("\nInput Memory Test repeat times (5) 0x"); repeat = get_number(16,0); if(repeat == 0) { repeat = 5; }// Print("\n"); //................................................. Print("\nSelected GDMA channel : GDMA%d", channel); Print("\nGDMA%d source address : 0x%08x", channel, gdmasrc); Print("\nGDMA%d destination address : 0x%08x", channel, gdmadst); Print("\nGDMA%d memory test size : 0x%08x", channel, gdmacnt); Print("\nGDMA%d Mem test repeat times : 0x%08x", channel, repeat); Print("\n"); for(j = 0; j < (repeat * 3); j++) {// Transfer width will be changed to 8,16,32 bit gdmacon &= ~GDMACON_TW; if((j%3) == 0) { // transfer width = byte /////////////////////////////////////////////////////// gdmacon |= GDMACON_TW_BYTE; // Transfer Width = byte (8bit) gdmacnt = bsize; // Transfer count = bytes count } else if((j%3) == 1) {// transfer width = half word ////////////////////////////////////////////////// gdmacon |= GDMACON_TW_HALFWORD; // Transfer Width = half word (16 bit) gdmacnt = bsize / 2; // Transfer count = half word count } else if((j%3) == 2) {// transfer width = word /////////////////////////////////////////////////////// gdmacon |= GDMACON_TW_WORD; // Transfer Width = word gdmacnt = bsize / 4; // Transfer count = word count }// Initialize source memory with ascii pattern ///////////////////////////////// GdmaMemInit((U32 *) gdmasrc, (U32 *) gdmadst, (int) bsize); // GDMA related register all clear to reset state ////////////////////////////// GdmaReset(channel); gdmacon |= GDMACON_SI | // GDMA Stop Interrupt Enable GDMACON_MODE_MEMMEM; // memory to memory gdmacon &= ~GDMACON_DST_DEC; // clear destination decrement bit gdmacon &= ~GDMACON_SRC_DEC; // clear source decrement bit if(channel) { Gdma1DoneFlag = 0; } else { Gdma0DoneFlag = 0; } // Enable GDMA Channel Interrupt /////////////////////////////////////////////// GdmaIntEnable(channel); // enable interrupt if(channel == 1) {// Set GDMA channel 1 registers //////////////////////////////////////////////// GDMASRC1 = gdmasrc; GDMADST1 = gdmadst; GDMACNT1 = gdmacnt; GDMACON1 = gdmacon; GDMA1_RUN_ENABLE = 1;// Wait GDMA1 Done Interrupt /////////////////////////////////////////////////// while(Gdma1DoneFlag == 0) { } Gdma1DoneFlag = 0; } else {// Set GDMA channel 0 registers //////////////////////////////////////////////// GDMASRC0 = gdmasrc; GDMADST0 = gdmadst; GDMACNT0 = gdmacnt; GDMACON0 = gdmacon; GDMA0_RUN_ENABLE = 1;// Wait GDMA0 Done Interrupt /////////////////////////////////////////////////// while(Gdma0DoneFlag == 0) { } Gdma0DoneFlag = 0; } // Disable_Int(nGLOBAL_INT); // disable global interrupt GdmaReset(channel);// Disable GDMA interrupt & clear interrupt Done flag ////////////////////////// GdmaIntDisable(channel); if( GdmaMemComp ( (void *) gdmasrc, // source address (void *) gdmadst, // destination address bsize // size in bytes ) == 0 ) { rvl = 0; break; } } if(rvl == 0) { Print("\nFail.\n"); } else { Print("\nOk.\n"); }}////////////////////////////////////////////////////////////////////////////////// UART0/UART1 to memory test //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static void UartToMemTest(void){ int uart; // UART number int gdma; // gdma number Print("\n\nUART0/UART1 to memory transfer test");// Get GDMA Channel //////////////////////////////////////////////////////////// while(1) { Print("\nSelect UART0/UART1 [0/1/Q]"); uart = get_upper(); // get UART number from console if( uart == 'Q') { return; } else if((uart == '1') || (uart == '0')) { uart -= '0'; break; } }// Get GDMA Channel //////////////////////////////////////////////////////////// while(1) { Print("\nSelect GDMA Channel[0/1/Q]"); gdma = get_upper(); // get GDMA channel number if(gdma == 'Q') { return; } else if( (gdma == '1') || (gdma == '0') ) { gdma -= '0'; break; } }// GDMA Uart0 to Memory transfer test ////////////////////////////////////////// UartToMemoryTest(uart, gdma); // UART to memory test} //////////////////////////////////////////////////////////////////////////////// // UART uart_channel to Memory test //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void UartToMemoryTest(int uart, int gdma){ U32 gdmasrc; // GDMA source address U32 gdmadst; // GDMA destination address U32 gdmacon; // GDMA control register U32 gdmacnt; // GDMA transfer count register U32 uartcont; // saved content of UARTCONT1/UARTCONT0 U8 * ptr; // pointer in destination buffer int size; // count of received data int changed; // changed flag of destination buffer int i; // position in destination buffer// destination address not valid => set the destination address //////////////// gdmadst = (U32) GDMATestDst; // default destination address // Rx byte count /////////////////////////////////////////////////////////////// Print("\nReceived Data data count 0x"); size = get_number(16,0); // read size from console if(size < 1) { size = 1; // set size to low limit } if(gdmacnt > GDMATestSize) { size = GDMATestSize; // set size to upper limit } // gdmacnt = size; // transfer count // Set destination buffer ////////////////////////////////////////////////////// ptr = (U8 *) gdmadst; // pointer in destination buffer for(i = 0; i < size; ++i) { // fill destination *ptr++ = i; // buffer } // Print destination address, size ///////////////////////////////////////////// Print("\nReceived data size = 0x%08x", gdmacnt); Print("\nGDMA DownLoad area = 0x%08x", gdmadst);// GDMA related register all clear to reset state ////////////////////////////// GdmaReset(gdma); // configure GDMA control register & UART control register ///////////////////// gdmacon = GDMACON_SI | // GDMA Stop Interrup Enable GDMACON_SRC_FIX | // source address fix GDMACON_TD_UTONEM | // 0 trasfer firection for UART mode GDMACON_TW_BYTE; // 0 transfer width - byte if(uart == 1) { gdmacon |= GDMACON_MODE_U1; // mode = UART1 uartcont = UARTCONT1; // read UARTCONT1 content } else if(uart == 0) { gdmacon |= GDMACON_MODE_U0; // mode = UART0 uartcont = UARTCONT0; // read UARTCONT0 content }////////////////////////////////////////////////////////////////////////////////// set GDMA registers ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// uartcont &= ~UARTCON_RXM; // clear UART Rx mode bits if(gdma == 1) { uartcont |= UARTCON_RXM_GDMA1REQ; // Rx mode = GDMA1 request // set GDMA channel 1 registers //////////////////////////////////////////////// GDMASRC1 = gdmasrc; // GDMA 1 source address GDMADST1 = gdmadst; // GDMA 1 destination address GDMACNT1 = gdmacnt; // GDMA 1 transfer count GDMACON1 = gdmacon; // GDMA 1 control register } else if(gdma == 0) { uartcont |= UARTCON_RXM_GDMA0REQ; // Rx mode = GDMA1 request // set GDMA channel 0 registers //////////////////////////////////////////////// GDMASRC0 = gdmasrc; // GDMA 0 source address GDMADST0 = gdmadst; // GDMA 0 destination address GDMACNT0 = gdmacnt; // GDMA 0 transfer count GDMACON0 = gdmacon; // GDMA 0 control register }// print GDMA registers //////////////////////////////////////////////////////// PrintGDMASRC(gdma); // GDMA source address PrintGDMADST(gdma); // GDMA destination address PrintGDMACNT(gdma); // GDMA transfer count PrintGDMACON(gdma); // GDMA control register Print("\n"); if(uart == 1) { UARTCONT1 = uartcont; } else if(uart == 0) { UARTCONT0 = uartcont; } // Enable GDMA Channel Interrupt, Clear Done Flag and Global enable interrupt // GdmaIntEnable(gdma); Enable_Int(nGLOBAL_INT); // global interrupt // Start GDMA Channel ////////////////////////////////////////////////////////// if(gdma)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -