|
我用的是WinCE5.0的系统,使用的BVDMAIN的bsp。
在driver里面有一个DMA文件夹,里面有一些使用DMA时相关的函数。还有一个例程代码。
但是我用例程代码调试,总是不成功。
请教一下是什么原因,谢谢
代码如下:
- #define FPGA_DMA_BUFFER_SIZE 0x40000
- #define FPGA_DMA_BUFFER_PHYSICAL (MEM_BASE_PHYSICAL +FPGA_BUFFER_OFFSET)
- #define FPGA_DMA_BUFFER_VIRTUAL (MEM_BASE_U_VIRTUAL+FPGA_BUFFER_OFFSET)
- #define FPGA_SRAM_BASE_OFFSET 0x20000
- #define FPGA_SRAM_BASE_PHYSICAL (IM_STORAGE_BASE_PHYSICAL + FPGA_SRAM_BASE_OFFSET)
- #define FPGA_SRAM_BASE_VIRTUAL (IM_STORAGE_BASE_U_VIRTUAL + FPGA_SRAM_BASE_OFFSET)
- #define TEST_BUFFER_SIZE 512
- P_XLLP_UINT32_T pDescriptor;
- P_XLLP_UINT32_T pSrcMemory;
- P_XLLP_UINT32_T pDstMemory;
- P_XLLP_UINT32_T pExtMemory;
- //实测:没有被调用
- void XllpDmacTestDeviceHandler(void* userContext, XLLP_UINT32_T channelDcsr)
- {
- P_XLLP_UINT32_T pSrcLocal = pSrcMemory;
- P_XLLP_UINT32_T pDstLocal = pDstMemory;
- XLLP_UINT32_T i;
- // Compare Src and Dst.
- for(i=1; i< TEST_BUFFER_SIZE; i++)
- {
- if( *pSrcLocal++ != *pDstLocal++ )
- {
- RETAILMSG(_DMA_TEST_, (TEXT("DMA_TEST Cmp Xfer Failure...\r\n")));
- break;
- }
- }
- return;
- }
- // Function Name: XllpDmacTest
- // Description: Setup a simple memory-to-memory transfer with the DMA hardware.
- INT WINAPI XllpDmacTest(void)
- {
- XLLP_DMAC_CHANNEL_T Channel;
- P_XLLP_UINT32_T pbDMATemp;
- XLLP_UINT32_T i;
- BOOL bSuccess=FALSE;
- P_XLLP_INT32_T pByteSrc;
- P_XLLP_INT32_T pByteDst;
- P_XLLP_UINT32_T pPhyDescriptor;
- P_XLLP_UINT32_T pPhySrcMemory;
- P_XLLP_UINT32_T pPhyDstMemory;
- P_XLLP_UINT32_T pPhyExtMemory;
- XLLP_DMAC_COMMAND_T TestCmd;
-
- if(XLLP_STATUS_SUCCESS != XllpDmacAllocChannel(&Channel, XLLP_DMAC_CHANNEL_PRIORITY_MEDIUM))
- {
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...XllpDmacAllocChannel failed...\r\n")));
- return XLLP_FALSE;
- }
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...DMA_TEST AllocChannel=%d...\r\n"),Channel));
-
- //
- // ?? Map a Memory-to-Memory Transfer. // May not be needed.
- //
- XllpDmacMapDeviceToChannel(
- XLLP_DMAC_MEM2MEM_MOVE,
- Channel
- );
- //
- // Allocate a block of virtual memory big enough to hold the DMA buffers
- //
- #if 0
- pDstMemory = VirtualAllocCopy(FPGA_DMA_BUFFER_SIZE,
- "DMA TEST : FPGA_DMA_BUFFER",(PVOID)(FPGA_DMA_BUFFER_VIRTUAL));
- pbDMATemp = VirtualAllocCopy((2*4*TEST_BUFFER_SIZE),
- "DMA TEST : FPGA_DMA_BUFFER",(PVOID)(FPGA_SRAM_BASE_VIRTUAL));
- if ((NULL == pDstMemory) || (NULL == pbDMATemp))
- {
- RETAILMSG(_DMA_TEST_, (TEXT("pDstMemory = 0x%08X\r\n"), pDstMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("pbDMATemp = 0x%08X\r\n"), pbDMATemp));
- bSuccess = FALSE;
- }
- else
- {
- bSuccess = TRUE;
- }
- if (bSuccess)
- {
- // Save pointers to the virtual & physical addresses so the driver can access them.
- pDescriptor = pbDMATemp + TEST_BUFFER_SIZE;
- pSrcMemory = pbDMATemp;
- pDstMemory = pDstMemory;
- pExtMemory = 0;
- pPhyDescriptor = (P_XLLP_UINT32_T)(FPGA_SRAM_BASE_VIRTUAL + (4 * TEST_BUFFER_SIZE));
- pPhySrcMemory = (P_XLLP_UINT32_T)(FPGA_SRAM_BASE_VIRTUAL);
- pPhyDstMemory = (P_XLLP_UINT32_T)(FPGA_DMA_BUFFER_VIRTUAL);
- pPhyExtMemory = 0;
- }
- else
- {
- RETAILMSG(_DMA_TEST_, (TEXT("VirtualAllocCopy failed\r\n")));
- return XLLP_FALSE;
- }
- #else
- pbDMATemp = VirtualAllocCopy(FPGA_DMA_BUFFER_SIZE,
- "DMA TEST : FPGA_DMA_BUFFER",(PVOID)(FPGA_DMA_BUFFER_VIRTUAL));
- if (NULL == pbDMATemp)
- {
- RETAILMSG(_DMA_TEST_, (TEXT("pbDMATemp = 0x%08X\r\n"), pbDMATemp));
- bSuccess = FALSE;
- }
- else
- {
- bSuccess = TRUE;
- }
- if (bSuccess)
- {
- // Save pointers to the virtual & physical addresses so the driver can access them.
- pDescriptor = pbDMATemp;
- pSrcMemory = pbDMATemp + 1024;
- pDstMemory = pbDMATemp + 2048;
- pExtMemory = 0;
- pPhyDescriptor = (P_XLLP_UINT32_T)(FPGA_DMA_BUFFER_VIRTUAL);
- pPhySrcMemory = (P_XLLP_UINT32_T)(FPGA_DMA_BUFFER_VIRTUAL + 4096);
- pPhyDstMemory = (P_XLLP_UINT32_T)(FPGA_DMA_BUFFER_VIRTUAL + 8192);
- pPhyExtMemory = 0;
- }
- else
- {
- RETAILMSG(_DMA_TEST_, (TEXT("VirtualAllocCopy failed\r\n")));
- return XLLP_FALSE;
- }
- #endif
- RETAILMSG(_DMA_TEST_, (TEXT("\r\nPHYSICAL Address:\r\n")));
- RETAILMSG(_DMA_TEST_, (TEXT("PhyDescriptor= 0x%08X\r\n"), pPhyDescriptor));
- RETAILMSG(_DMA_TEST_, (TEXT("PhySrcMemory = 0x%08X\r\n"), pPhySrcMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("PhyDstMemory = 0x%08X\r\n"), pPhyDstMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("PhyExtMemory = 0x%08X\r\n"), pPhyExtMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("\r\nLOCAL Address:\r\n")));
- RETAILMSG(_DMA_TEST_, (TEXT("Descriptor = 0x%08X\r\n"), pDescriptor));
- RETAILMSG(_DMA_TEST_, (TEXT("SrcMemory = 0x%08X\r\n"), pSrcMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("DstMemory = 0x%08X\r\n"), pDstMemory));
- RETAILMSG(_DMA_TEST_, (TEXT("ExtMemory = 0x%08X\r\n"), pExtMemory));
- //
- // Configure Channels to use Descriptors.
- //
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...Configure a channel for Descriptors...\r\n")));
- XllpDmacCfgChannelDescTransfer(
- (P_XLLP_DMAC_DESCRIPTOR_T)pPhyDescriptor,
- Channel,
- //XLLP_DMAC_DRCMR_T aDeviceDrcmr,
- XLLP_DMAC_MEM2MEM_MOVE,
- XLLP_DMAC_ALIGNMENT_OFF
- );
- //
- // Register Device Handler
- //
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...Register Device Handler...\r\n")));
- XllpDmacRegisterDeviceHandler ( Channel,
- XllpDmacTestDeviceHandler,
- NULL
- );
- //
- // Link Descriptors
- //
- // Only one Descriptor, so linking is not needed.
- //
- // Enable interrupts for the requested channel. Not Needed.
- //
- //
- // Load data into the descriptor.
- //
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...Load the descriptor...\r\n")));
- TestCmd.aLen = (TEST_BUFFER_SIZE * 4);
- TestCmd.aWidth = XLLP_DMAC_WIDTH_32;
- TestCmd.aSize = XLLP_DMAC_BURSTSIZE_32;
- TestCmd.aEndian = XLLP_FALSE; // Litter Endian.
- TestCmd.aFlyByT = XLLP_FALSE; // Normal Transfer. No Fly by
- TestCmd.aFlyByS = XLLP_FALSE; // Normal Transfer. No Fly by
- TestCmd.aEndIrqEn = XLLP_FALSE; // Interrupt when len = 0.
- TestCmd.aStartIrqEn = XLLP_FALSE; // No Interrupt when Desc is loaded.
- TestCmd.aAddrMode = XLLP_FALSE; // Src & Dst contains values for addresses.
- TestCmd.aCmpEn = XLLP_FALSE;
- TestCmd.aFlowTrg = XLLP_FALSE;
- TestCmd.aFlowSrc = XLLP_FALSE;
- TestCmd.aIncTrgAddr = XLLP_TRUE;
- TestCmd.aIncSrcAddr = XLLP_TRUE;
- XllpDmacFillLinkedDesc(
- (P_XLLP_DMAC_DESCRIPTOR_T)pDescriptor,
- NULL,
- XLLP_DMAC_DESC_STOP_CHANNEL,
- XLLP_DMAC_DISABLE_DESC_BRANCH,
- (XLLP_UINT32_T)pPhySrcMemory,
- (XLLP_UINT32_T)pPhyDstMemory,
- &TestCmd
- );
- //
- //
- // Put a Pattern in the Src memory.
- //
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...Initialize source memory....\r\n")));
- pByteSrc = pSrcMemory;
- pByteDst = pDstMemory;
- for(i = 0; i < TEST_BUFFER_SIZE; i++)
- {
- *pByteSrc++ = i + 1;
- *pByteDst++ = i + 3;
- }
- RETAILMSG(_DMA_TEST_,
- (TEXT("\r\nSrcMemory[0]:0x%08X, SrcMemory[%d]:0x%08X\r\n"),
- pSrcMemory[0], TEST_BUFFER_SIZE - 1, pSrcMemory[TEST_BUFFER_SIZE - 1]));
- RETAILMSG(_DMA_TEST_,
- (TEXT("\r\DstMemory[0]:0x%08X, DstMemory[%d]:0x%08X\r\n"),
- pDstMemory[0], TEST_BUFFER_SIZE - 1, pDstMemory[TEST_BUFFER_SIZE - 1]));
- // Start the Transfer
- //
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...The the M-M Xfer...\r\n")));
- XllpDmacStartTransfer( Channel );
-
- if (WAIT_OBJECT_0 == WaitForSingleObject(pDMAGlobals->hDMAEvent[Channel], INFINITE))
- {
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...DMA_TEST Wait a event...\r\n")));
- //
- // Compare Src and Dst Patterms (Do this in the registerd handler. // pkdebug)
- //
- pByteSrc = pSrcMemory;
- pByteDst = pDstMemory;
- for(i = 0; i < TEST_BUFFER_SIZE; i++)
- {
- if( *pByteSrc++ != *pByteDst++ )
- {
- RETAILMSG(_DMA_TEST_, (TEXT("DMA_TEST Cmp Xfer Failure...\r\n")));
- // Address of first failed location.
- RETAILMSG(_DMA_TEST_, (TEXT("pSrcLocal = 0x%08X, pDstLocal = 0x%08X\r\n"),
- --pByteSrc, --pByteDst ));
- // Content of first failed location.
- RETAILMSG(_DMA_TEST_, (TEXT("SrcLocal = 0x%08X, DstLocal = 0x%08X\r\n"),
- *pByteSrc, *pByteDst ));
- break;
- }
- }
- RETAILMSG(_DMA_TEST_, (TEXT("DMA_TEST Cmp Xfer OK...\r\n")));
- }
- // Completed
- RETAILMSG(_DMA_TEST_, (TEXT("\r\n...Completed DMAC Test...\r\n")));
-
- return XLLP_TRUE;
- }
复制代码
|
|