📄 dmawince.c
字号:
return FALSE;
}
if (WaitForSingleObject(*hDmacMutex, timeout) == WAIT_TIMEOUT)
{
CloseHandle(*hDmacMutex);
return FALSE;
}
return TRUE;
}
VOID XllpDmacFreeMutex
(
HANDLE hDmacMutex
)
{
ReleaseMutex(hDmacMutex);
CloseHandle(hDmacMutex);
}
void XllpDmacDumpStatus( XLLP_DMAC_CHANNEL_T aChannel )
{
//RETAILMSG(1,(TEXT("DMA:>DumpStatus DmaChan=%02d Src=0x%08x Tgt=0x%08x Cmd=0x%08x Dcsr=0x%08x DINT=0x%08x \r\n"),aChannel, pDmacHandle->DDG[aChannel].DSADR, pDmacHandle->DDG[aChannel].DTADR, pDmacHandle->DDG[aChannel].DCMD, pDmacHandle->DCSR[aChannel], pDmacHandle->DINT ));
//RETAILMSG(1,(TEXT("DMA:>DrcmrRx=0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \r\n"), pDmacHandle->DRCMR1[48], pDmacHandle->DRCMR1[50],pDmacHandle->DRCMR1[52],pDmacHandle->DRCMR1[54],pDmacHandle->DRCMR1[56],pDmacHandle->DRCMR1[58],pDmacHandle->DRCMR1[60] ));
//RETAILMSG(1,(TEXT("DMA:>DrcmrTx=0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \r\n"), pDmacHandle->DRCMR1[49], pDmacHandle->DRCMR1[51],pDmacHandle->DRCMR1[53],pDmacHandle->DRCMR1[55],pDmacHandle->DRCMR1[57],pDmacHandle->DRCMR1[59],pDmacHandle->DRCMR1[61] ));
}
void XllpDmacEnableInterrupt
(
)
{
volatile XLLP_INTC_T *v_pICReg;
v_pICReg = (volatile XLLP_INTC_T *) INTC_BASE_U_VIRTUAL;
INTC_DMAC_INT_EN(v_pICReg->icmr);
}
void XllpDmacDisableInterrupt
(
)
{
volatile XLLP_INTC_T *v_pICReg;
v_pICReg = (volatile XLLP_INTC_T *) INTC_BASE_U_VIRTUAL;
INTC_DMAC_INT_EN(v_pICReg->icmr);
}
//******************************************************************************
//
// Function Name: OSMemAlloc
//
// Description: Allocates a block of memory
//
//
// Input Arguments:
// numBytes: Number of bytes to allocate
//
// Output Arguments:
//
//
// Return Value:
// void*: Pointer to allocated memory. NULL if unsuccessful.
//
// Notes:
// Memory allocated by this call is aligned on page boundary (4K on XScale)
//
//*******************************************************************************
VOID* OSMemAlloc
(
UINT32 numBytes
)
{
return VirtualAlloc(0, numBytes, MEM_COMMIT, PAGE_READWRITE | PAGE_NOCACHE);
}
//******************************************************************************
//
// Function Name: OSMemFree
//
// Description: Frees a previously allocated block of memory
//
//
// Input Arguments:
// VOID* memPtr: pointer to memory to deallocate
//
// Output Arguments:
//
//
// Return Value:
//
//
// Notes:
//
//
//*******************************************************************************
VOID OSMemFree
(
VOID* memPtr
)
{
VirtualFree(memPtr, 0, MEM_RELEASE);
}
//******************************************************************************
//
// Function Name: OSGetMaxPages
//
// Description: Returns max number of physical pages that may be occupied by a user buffer
//
//
// Input Arguments:
// pBuffer: Virtual address to user buffer
// bufferLength: Length of user buffer
//
// Output Arguments:
//
//
// Return Value:
// Maximum number of physical pages that can be spanned by user buffer
//
// Notes:
// WinCe generally allocates memory aligned on page boundaries.
//
//*******************************************************************************
XLLP_UINT32_T OSGetMaxPages
(
XLLP_UINT8_T *pBuffer,
XLLP_UINT32_T bufferLength
)
{
return ADDRESS_AND_SIZE_TO_SPAN_PAGES(pBuffer, bufferLength);
}
//******************************************************************************
//
// Function Name: OSLockPhysicalPages
//
// Description: Locks physical pages representing a virtual address space into memory.
// Returns information about locked pages to user
//
//
// Input Arguments:
// VOID* virtualAddress: Pointer to virtual address space to lock
// UINT32 numBytesTolock; Number of bytes of linear address sace to lock
// UINT32 osFlags: OS specific flags.
//
// Output Arguments:
// UINT32 *pageAddresses: Array in which list of all physical pages representing
// buffer is returned
//
// Return Value:
// TRUE: if successful
// FALSE: otherwise
//
// Notes:
// Invokes LockPages on WinCE which is supported for .NET, PocketPC and SmartPhone
// platforms
//
//*******************************************************************************
BOOL OSLockPhysicalPages
(
VOID* virtualAddress,
XLLP_UINT32_T numBytesToLock,
XLLP_UINT32_T *pageAddresses,
XLLP_UINT32_T osFlags
)
{
return LockPages(virtualAddress, numBytesToLock, pageAddresses, osFlags);
}
//******************************************************************************
//
// Function Name: OSUnlockPhysicalPages
//
// Description: Unlocks previously locked physical pages representing a virtual
// address space into memory.
//
// Input Arguments:
// VOID* virtualAddress: Pointer to virtual address space to lock
// UINT32 numBytesToUnlock; Number of bytes of linear address sace to unlock
//
// Output Arguments:
//
// Return Value:
// TRUE: if successful
// FALSE: otherwise
//
// Notes:
// Invokes UnlockPages on WinCE which is supported for .NET, PocketPC and SmartPhone
// platforms
//
//*******************************************************************************
BOOL OSUnlockPhysicalPages
(
VOID* virtualAddress,
XLLP_UINT32_T numBytesToUnlock
)
{
return UnlockPages(virtualAddress, numBytesToUnlock);
}
#if 0
#define TEST_BUFFER_SIZE 64
P_XLLP_UINT8_T pDescriptor;
P_XLLP_UINT8_T pSrcMemory;
P_XLLP_UINT8_T pDstMemory;
P_XLLP_UINT8_T pExtMemory;
//*******************************************************************************
//
// Function Name: XllpDmacTestHandler
//
//
// Description: Perform processing after the data transfer.
//
//
//*******************************************************************************
void XllpDmacTestDeviceHandler(void* userContext, XLLP_UINT32_T channelDcsr)
{
P_XLLP_UINT8_T pSrcLocal = pSrcMemory;
P_XLLP_UINT8_T pDstLocal = pDstMemory;
XLLP_UINT32_T i;
//NKDbgPrintfW(TEXT("/r/n Registered Handler running....\r\n"));
// Compare Src and Dst.
for(i=1; i< TEST_BUFFER_SIZE; i++)
{
if( *pSrcLocal++ != *pDstLocal++ )
{
//NKDbgPrintfW(TEXT("DMA Cmp Xfer Failure...\r\n"));
// Address of first failed location.
//NKDbgPrintfW(TEXT("pDstLocal = , pDstLocal = \r\n"), --pSrcLocal, --pDstLocal );
// Content of first failed location.
//NKDbgPrintfW(TEXT(" DstLocal = , DstLocal = \r\n"), *pSrcLocal, *pDstLocal );
break;
}
}
// Exit
return;
}
//typedef void (*DeviceDmaIntHandler) (void* userContext, XLLP_UINT32_T channelDcsr);
//*******************************************************************************
//
// Function Name: XllpDmacTest
//
//
// Description: Setup a simple memory-to-memory transfer with the DMA hardware.
//
//
//*******************************************************************************
XLLP_BOOL_T XllpDmacTest() // pkdebug.
{
XLLP_DMAC_CHANNEL_T Channel;
//P_XLLP_DMAC_CHANNEL_T pChannel = &Channel;
P_XLLP_UINT8_T pbDMATemp;
XLLP_UINT32_T i;
BOOL bSuccess=FALSE;
P_XLLP_INT8_T pByteSrc;
P_XLLP_INT8_T pByteDst;
P_XLLP_UINT8_T pPhyDescriptor;
P_XLLP_UINT8_T pPhySrcMemory;
P_XLLP_UINT8_T pPhyDstMemory;
P_XLLP_UINT8_T pPhyExtMemory;
XLLP_DMAC_COMMAND_T TestCmd;
//NKDbgPrintfW(TEXT("\r\nDMAC Test...\r\n"));
//
// Initialization already done via GDE_Init.
//
//if( XllpDmacInit() ) // Initialize
//{
// NKDbgPrintfW(TEXT("XllpDmacInit failed\r\n"));
// return XLLP_FALSE;
//}
//
// Obtain a channel
//
//NKDbgPrintfW(TEXT("\r\nObtain a channel\r\n"));
if(XLLP_STATUS_SUCCESS != XllpDmacAllocChannel( &Channel, XLLP_DMAC_CHANNEL_PRIORITY_MEDIUM))
{
//NKDbgPrintfW(TEXT("XllpDmacAllocChannel failed\r\n"));
return XLLP_FALSE;
}
//NKDbgPrintfW(TEXT("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
//
pbDMATemp = (P_XLLP_VINT8_T)VirtualAlloc(0,
TEST_BUFFER_SIZE * 4,
MEM_RESERVE,
PAGE_NOACCESS);
if (pbDMATemp)
{
// Map the physical DMA buffer to the virtual address we just allocated
bSuccess = VirtualCopy(pbDMATemp,
(LPVOID)(DMA_BUFFER_VIRTUAL/256), // Borrow use of Audio Physical buffer
TEST_BUFFER_SIZE * 4,
PAGE_READWRITE | PAGE_NOCACHE);
}
else
{
//NKDbgPrintfW(TEXT("VirtualAlloc failed\r\n"));
return XLLP_FALSE;
}
if (bSuccess)
{
// Save pointers to the virtual & physical addresses so the driver can access them.
pDescriptor = pbDMATemp;
pSrcMemory = pbDMATemp + TEST_BUFFER_SIZE;
pDstMemory = pbDMATemp + 2*TEST_BUFFER_SIZE;
pExtMemory = pbDMATemp + 3*TEST_BUFFER_SIZE;
pPhyDescriptor = (P_XLLP_UINT8_T)(DMA_BUFFER_VIRTUAL);
pPhySrcMemory = (P_XLLP_UINT8_T)(DMA_BUFFER_VIRTUAL + TEST_BUFFER_SIZE);
pPhyDstMemory = (P_XLLP_UINT8_T)(DMA_BUFFER_VIRTUAL + 2*TEST_BUFFER_SIZE);
pPhyExtMemory = (P_XLLP_UINT8_T)(DMA_BUFFER_VIRTUAL + 3*TEST_BUFFER_SIZE);
}
else
{
//NKDbgPrintfW(TEXT("VirtualCopy failed\r\n"));
return XLLP_FALSE;
}
//NKDbgPrintfW(TEXT("VirtBufAdr=0x%x\r\n"), pDescriptor);
//NKDbgPrintfW(TEXT("PhysBufAdr=0x%x\r\n"), pPhyDescriptor);
//
// Configure Channels to use Descriptors.
//
//NKDbgPrintfW(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
//
//NKDbgPrintfW(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.
//
//NKDbgPrintfW(TEXT("\r\n...Load the descriptor...\r\n"));
TestCmd.aLen = 32;
TestCmd.aWidth = XLLP_DMAC_WIDTH_32;
TestCmd.aSize = XLLP_DMAC_BURSTSIZE_8;
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.
//
//NKDbgPrintfW(TEXT("\r\n...Initialize source memory....\r\n"));
pByteSrc = pSrcMemory;
pByteDst = pDstMemory;
for(i=1; i< TEST_BUFFER_SIZE; i++)
{
*pByteSrc++ = (XLLP_INT8_T)i;
*pByteDst++ = 0;
}
// Start the Transfer
//
//NKDbgPrintfW(TEXT("\r\n...The the M-M Xfer...\r\n"));
XllpDmacStartTransfer( Channel );
//
// Compare Src and Dst Patterms (Do this in the registerd handler. // pkdebug)
//
//for(i=0; i < TRANFER_SIZE; i++)
//{
// if( XLLP_FALSE )
// return XLLP_FALSE
//}
// Completed
//NKDbgPrintfW(TEXT("\r\n...Completed DMAC Test...\r\n"));
return XLLP_TRUE;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -