📄 ddk_sdma.c
字号:
// chan
// [in] - Virtual channel returned by DDKSdmaOpenChan function.
//
// index
// [in] - Index of buffer descriptor within the chain to
// be configured.
//
// modeFlags
// [in] - Specifies the buffer desciptor mode word flags that
// control the "continue", "wrap", and "interrupt" settings.
//
// memAddr1PA
// [in] - For memory-to-memory transfers, this parameter specifies
// the physical memory source address for the transfer. For
// memory-to-peripheral transfers, this parameter specifies the
// physical memory source address for the transfer. For
// peripheral-to-memory transfers, this parameter specifies the
// physical memory destination address for the transfer.
//
// memAddr2PA
// [in] - Used only for memory-to-memory transfers to specify
// the physical memory destination address for the transfer.
// Ignored for memory-to-peripheral and peripheral-to-memory
// transfers.
//
// dataWidth
// [in] - Used only for memory-to-peripheral and peripheral-to-memory
// transfers to specify the width of the data for the peripheral
// transfer. Ignored for memory-to-memory transfers.
//
// numBytes
// [in] - Specifies the size of the transfer in bytes.
//
// Returns:
// Returns TRUE if the buffer descriptor was configured, otherwise
// returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DDKSdmaSetBufDesc(UINT8 chan, UINT32 index,
UINT32 modeFlags, UINT32 memAddr1PA, UINT32 memAddr2PA,
DDK_DMA_ACCESS dataWidth, UINT16 numBytes)
{
BOOL rc = FALSE;
PSDMA_BUF_DESC pBufDesc;
PSDMA_BUF_DESC_EXT pBufDescExt;
// Validate channel
if (!SdmaValidChan(chan))
{
ERRORMSG(1, (_T("Channel validation failed!\r\n")));
goto cleanUp;
}
// Validate buffer descriptor index
if (index >= g_pHostSharedUA->chanDesc[chan].numBufDesc)
{
ERRORMSG(1, (_T("Invalid BD index!\r\n")));
goto cleanUp;
}
// If channel uses extended buffer descriptors
if (g_pHostSharedUA->chanDesc[chan].bExtended)
{
pBufDescExt = (PSDMA_BUF_DESC_EXT)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
pBufDescExt[index].mode =
CSP_BITFVAL(SDMA_MODE_COMMAND, dataWidth) |
CSP_BITFVAL(SDMA_MODE_EXT, SDMA_MODE_EXT_USED) |
CSP_BITFVAL(SDMA_MODE_ERROR, SDMA_MODE_ERROR_NOTFOUND) |
modeFlags |
CSP_BITFVAL(SDMA_MODE_DONE, SDMA_MODE_DONE_NOTREADY) |
CSP_BITFVAL(SDMA_MODE_COUNT, numBytes);
pBufDescExt[index].srcAddrPA = memAddr1PA;
pBufDescExt[index].destAddrPA = memAddr2PA;
}
// Else channel uses non-extended buffer descriptors
else
{
pBufDesc = (PSDMA_BUF_DESC)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
pBufDesc[index].mode =
CSP_BITFVAL(SDMA_MODE_COMMAND, dataWidth) |
CSP_BITFVAL(SDMA_MODE_EXT, SDMA_MODE_EXT_UNUSED) |
CSP_BITFVAL(SDMA_MODE_ERROR, SDMA_MODE_ERROR_NOTFOUND) |
modeFlags |
CSP_BITFVAL(SDMA_MODE_DONE, SDMA_MODE_DONE_NOTREADY) |
CSP_BITFVAL(SDMA_MODE_COUNT, numBytes);
pBufDesc[index].memAddrPA = memAddr1PA;
}
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: DDKSdmaGetBufDescStatus
//
// This function retrieves the status of the "done" and "error" bits from
// all of the buffer descriptors of a chain.
//
// Parameters:
// chan
// [in] - Virtual channel returned by DDKSdmaOpenChan function.
//
// index
// [in] - Index of buffer descriptor.
//
// pStatus
// [out] - Points to an array that will be filled with the status
// of each buffer descriptor in the chain.
//
// Returns:
// Returns TRUE if the buffer descriptor status was retrieved
// successfully, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DDKSdmaGetBufDescStatus(UINT8 chan, UINT32 index,
UINT32 *pStatus)
{
BOOL rc = FALSE;
PSDMA_BUF_DESC pBufDesc;
PSDMA_BUF_DESC_EXT pBufDescExt;
// Validate channel
if (!SdmaValidChan(chan))
{
ERRORMSG(1, (_T("Channel validation failed!\r\n")));
goto cleanUp;
}
// Validate buffer descriptor index
if (index >= g_pHostSharedUA->chanDesc[chan].numBufDesc)
{
ERRORMSG(1, (_T("Invalid BD index!\r\n")));
goto cleanUp;
}
// If channel uses extended buffer descriptors
if (g_pHostSharedUA->chanDesc[chan].bExtended)
{
// Get reference to buffer descriptor
pBufDescExt = (PSDMA_BUF_DESC_EXT)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// Get mode word from buffer descriptor
*pStatus = pBufDescExt[index].mode;
}
// Else channel uses non-extended buffer descriptors
else
{
// Get reference to buffer descriptor
pBufDesc = (PSDMA_BUF_DESC)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// Get mode word from buffer descriptor
*pStatus = pBufDesc[index].mode;
}
#if 0
// Isolate status bits
*pStatus &= (CSP_BITFMASK(SDMA_MODE_DONE) | CSP_BITFMASK(SDMA_MODE_ERROR));
#endif
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: DDKSdmaGetChainStatus
//
// This function retrieves the status of the "done" and "error" bits from
// the specified buffer descriptor.
//
// Parameters:
// chan
// [in] - Virtual channel returned by DDKSdmaOpenChan function.
//
// index
// [in] - Index of buffer descriptor.
//
// pStatus
// [out] - Retrieved status of the buffer descriptor.
//
// Returns:
// Returns TRUE if the buffer descriptor status was retrieved
// successfully, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DDKSdmaGetChainStatus(UINT8 chan, UINT32 *pStatus)
{
BOOL rc = FALSE;
UINT32 index;
PSDMA_BUF_DESC pBufDesc;
PSDMA_BUF_DESC_EXT pBufDescExt;
// Validate channel
if (!SdmaValidChan(chan))
{
ERRORMSG(1, (_T("Channel validation failed!\r\n")));
goto cleanUp;
}
// If channel uses extended buffer descriptors
if (g_pHostSharedUA->chanDesc[chan].bExtended)
{
// Get reference to buffer descriptor
pBufDescExt = (PSDMA_BUF_DESC_EXT)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// For each buffer descriptor in the chain
for (index = 0; index < g_pHostSharedUA->chanDesc[chan].numBufDesc;
index++)
{
#if 0
// Get mode word from buffer descriptor and isolate status bits
pStatus[index] = pBufDescExt[index].mode &
(CSP_BITFMASK(SDMA_MODE_DONE) | CSP_BITFMASK(SDMA_MODE_ERROR));
#endif
// Get mode word from buffer descriptor and isolate status bits
pStatus[index] = pBufDescExt[index].mode;
}
}
// Else channel uses non-extended buffer descriptors
else
{
// Get reference to buffer descriptor
pBufDesc = (PSDMA_BUF_DESC)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// For each buffer descriptor in the chain
for (index = 0; index < g_pHostSharedUA->chanDesc[chan].numBufDesc;
index++)
{
#if 0
// Get mode word from buffer descriptor and isolate status bits
pStatus[index] = pBufDesc[index].mode &
(CSP_BITFMASK(SDMA_MODE_DONE) | CSP_BITFMASK(SDMA_MODE_ERROR));
#endif
// Get mode word from buffer descriptor and isolate status bits
pStatus[index] = pBufDesc[index].mode;
}
}
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: DDKSdmaClearBufDescStatus
//
// This function clears the status of the "done" and "error" bits within
// the specified buffer descriptor.
//
// Parameters:
// chan
// [in] - Virtual channel returned by DDKSdmaOpenChan function.
//
// index
// [in] - Index of buffer descriptor.
//
// Returns:
// Returns TRUE if the buffer descriptor status was cleared
// successfully, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DDKSdmaClearBufDescStatus(UINT8 chan, UINT32 index)
{
BOOL rc = FALSE;
PSDMA_BUF_DESC pBufDesc;
PSDMA_BUF_DESC_EXT pBufDescExt;
// Validate channel
if (!SdmaValidChan(chan))
{
ERRORMSG(1, (_T("Channel validation failed!\r\n")));
goto cleanUp;
}
// Validate buffer descriptor index
if (index >= g_pHostSharedUA->chanDesc[chan].numBufDesc)
{
ERRORMSG(1, (_T("Invalid BD index!\r\n")));
goto cleanUp;
}
// If channel uses extended buffer descriptors
if (g_pHostSharedUA->chanDesc[chan].bExtended)
{
// Get reference to buffer descriptor
pBufDescExt = (PSDMA_BUF_DESC_EXT)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// Clear status bits
CSP_BITFINS(pBufDescExt[index].mode, SDMA_MODE_DONE,
SDMA_MODE_DONE_NOTREADY);
CSP_BITFINS(pBufDescExt[index].mode, SDMA_MODE_ERROR,
SDMA_MODE_ERROR_NOTFOUND);
}
// Else channel uses non-extended buffer descriptors
else
{
// Get reference to buffer descriptor
pBufDesc = (PSDMA_BUF_DESC)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
// Clear status bits
CSP_BITFINS(pBufDesc[index].mode, SDMA_MODE_DONE,
SDMA_MODE_DONE_NOTREADY);
CSP_BITFINS(pBufDesc[index].mode, SDMA_MODE_ERROR,
SDMA_MODE_ERROR_NOTFOUND);
}
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
// Function: DDKSdmaClearChainStatus
//
// This function clears the status of the "done" and "error" bits within
// all of the buffer descriptors of a chain.
//
// Parameters:
// chan
// [in] - Virtual channel returned by DDKSdmaOpenChan function.
//
// Returns:
// Returns TRUE if the buffer descriptor status for the chain was cleared
// successfully, otherwise returns FALSE.
//
//-----------------------------------------------------------------------------
BOOL DDKSdmaClearChainStatus(UINT8 chan)
{
BOOL rc = FALSE;
UINT32 index;
PSDMA_BUF_DESC pBufDesc;
PSDMA_BUF_DESC_EXT pBufDescExt;
// Validate channel
if (!SdmaValidChan(chan))
{
ERRORMSG(1, (_T("Channel validation failed!\r\n")));
goto cleanUp;
}
// If channel uses extended buffer descriptors
if (g_pHostSharedUA->chanDesc[chan].bExtended)
{
// Get reference to buffer descriptor
pBufDescExt = (PSDMA_BUF_DESC_EXT)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
for (index = 0; index < g_pHostSharedUA->chanDesc[chan].numBufDesc;
index++)
{
// Clear status bits
CSP_BITFINS(pBufDescExt[index].mode, SDMA_MODE_DONE,
SDMA_MODE_DONE_NOTREADY);
CSP_BITFINS(pBufDescExt[index].mode, SDMA_MODE_ERROR,
SDMA_MODE_ERROR_NOTFOUND);
}
}
// Else channel uses non-extended buffer descriptors
else
{
// Get reference to buffer descriptor
pBufDesc = (PSDMA_BUF_DESC)
g_pHostSharedUA->chanDesc[chan].pBaseBufDescUA;
for (index = 0; index < g_pHostSharedUA->chanDesc[chan].numBufDesc;
index++)
{
// Clear status bits
CSP_BITFINS(pBufDesc[index].mode, SDMA_MODE_DONE,
SDMA_MODE_DONE_NOTREADY);
CSP_BITFINS(pBufDesc[index].mode, SDMA_MODE_ERROR,
SDMA_MODE_ERROR_NOTFOUND);
}
}
rc = TRUE;
cleanUp:
return rc;
}
//-----------------------------------------------------------------------------
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -