XilinxProcessorIPLib/drivers/mcdma/src/xmcdma_bd.c
u32 XMcDma_ChanSubmit(XMcdma_ChanCtrl *Chan, UINTPTR BufAddr, u32 len)
{
	u32 BdCount = 1;
	XMcdma_Bd *BdCurPtr = Chan->BdRestart;
	u32 i;
	u32 Bdlen = len;

	/* Calculate the Number of BD's required for transferring user
	 * requested Data */
	if (len > Chan->MaxTransferLen) {
		BdCount = (len + (Chan->MaxTransferLen - 1)) / Chan->MaxTransferLen;
		Bdlen = Chan->MaxTransferLen;
	}

	if (BdCount > Chan->BdCnt) {
		xil_printf("for transferring len bytes required Bd's is %x\n\r", BdCount);
		xil_printf("User requested only this %x many Bd's\n\r", Chan->BdCnt);

		return XST_FAILURE;
	}

	for (i = 0; i < BdCount; i++) {
		XMcdma_BdClear(BdCurPtr);

		XMcdma_BdSetBufAddr(BdCurPtr, BufAddr);

		if (len < Chan->MaxTransferLen)
			Bdlen = len;

		XMcdma_BdWrite(BdCurPtr, XMCDMA_BD_CTRL_OFFSET, Bdlen);

		Chan->BdTail = BdCurPtr;
		XMCDMA_CACHE_FLUSH((UINTPTR)(BdCurPtr));
		BdCurPtr = (XMcdma_Bd *)XMcdma_BdChainNextBd(Chan, BdCurPtr);
		BufAddr += Bdlen;
		len -= Bdlen;
	}

	XMCDMA_CACHE_FLUSH((UINTPTR)(BdCurPtr));
	DATA_SYNC;
	Chan->BdRestart = BdCurPtr;
	Chan->BdPendingCnt += BdCount;
	Chan->BdCnt -= BdCount;

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function Populates the BD Chain with the required buffer address and
* length fields.
*
* User can submit multiple buffers/buffer descriptors by calling this function
* multiple times
*
* @param	Chan is the MCDMA Channel to be worked on..
* @param	BufAddr is the buffer address to which data should send/recv.
* @param	len is the Amount of data user requested to send/recv.
*
* @return
*		- XST_SUCCESS if initialization was successful
*		- XST_FAILURE if the BdStartAddress or requested bdlen
*		  doesn't match for the driver requirements.
*
*****************************************************************************/
This function Populates the BD Chain with the required buffer address and
length fields.

User can submit multiple buffers/buffer descriptors by calling this function
multiple times
This function Populates the BD Chain with the required buffer address and length fields . User can submit multiple buffers / buffer descriptors by calling this function multiple times
u32 XMcDma_ChanSubmit(XMcdma_ChanCtrl *Chan, UINTPTR BufAddr, u32 len)
{
	u32 BdCount = 1;
	XMcdma_Bd *BdCurPtr = Chan->BdRestart;
	u32 i;
	u32 Bdlen = len;
	if (len > Chan->MaxTransferLen) {
		BdCount = (len + (Chan->MaxTransferLen - 1)) / Chan->MaxTransferLen;
		Bdlen = Chan->MaxTransferLen;
	}
	if (BdCount > Chan->BdCnt) {
		xil_printf("for transferring len bytes required Bd's is %x\n\r", BdCount);
		xil_printf("User requested only this %x many Bd's\n\r", Chan->BdCnt);
		return XST_FAILURE;
	}
	for (i = 0; i < BdCount; i++) {
		XMcdma_BdClear(BdCurPtr);
		XMcdma_BdSetBufAddr(BdCurPtr, BufAddr);
		if (len < Chan->MaxTransferLen)
			Bdlen = len;
		XMcdma_BdWrite(BdCurPtr, XMCDMA_BD_CTRL_OFFSET, Bdlen);
		Chan->BdTail = BdCurPtr;
		XMCDMA_CACHE_FLUSH((UINTPTR)(BdCurPtr));
		BdCurPtr = (XMcdma_Bd *)XMcdma_BdChainNextBd(Chan, BdCurPtr);
		BufAddr += Bdlen;
		len -= Bdlen;
	}
	XMCDMA_CACHE_FLUSH((UINTPTR)(BdCurPtr));
	DATA_SYNC;
	Chan->BdRestart = BdCurPtr;
	Chan->BdPendingCnt += BdCount;
	Chan->BdCnt -= BdCount;
	return XST_SUCCESS;
}
u32 XMcDma_ChanSubmit ( XMcdma_ChanCtrl * Chan , UINTPTR BufAddr , u32 len ) { u32 BdCount = 1 ; XMcdma_Bd * BdCurPtr = Chan -> BdRestart ; u32 i ; u32 Bdlen = len ; if ( len > Chan -> MaxTransferLen ) { BdCount = ( len + ( Chan -> MaxTransferLen - 1 ) ) / Chan -> MaxTransferLen ; Bdlen = Chan -> MaxTransferLen ; } if ( BdCount > Chan -> BdCnt ) { xil_printf ( " \n \r " , BdCount ) ; xil_printf ( " \n \r " , Chan -> BdCnt ) ; return XST_FAILURE ; } for ( i = 0 ; i < BdCount ; i ++ ) { XMcdma_BdClear ( BdCurPtr ) ; XMcdma_BdSetBufAddr ( BdCurPtr , BufAddr ) ; if ( len < Chan -> MaxTransferLen ) Bdlen = len ; XMcdma_BdWrite ( BdCurPtr , XMCDMA_BD_CTRL_OFFSET , Bdlen ) ; Chan -> BdTail = BdCurPtr ; XMCDMA_CACHE_FLUSH ( ( UINTPTR ) ( BdCurPtr ) ) ; BdCurPtr = ( XMcdma_Bd * ) XMcdma_BdChainNextBd ( Chan , BdCurPtr ) ; BufAddr += Bdlen ; len -= Bdlen ; } XMCDMA_CACHE_FLUSH ( ( UINTPTR ) ( BdCurPtr ) ) ; DATA_SYNC ; Chan -> BdRestart = BdCurPtr ; Chan -> BdPendingCnt += BdCount ; Chan -> BdCnt -= BdCount ; return XST_SUCCESS ; }
This function Populates the BD Chain with the required buffer address and
length fields.
This function Populates the BD Chain with the required buffer address and length fields .
/* Calculate the Number of BD's required for transferring user
	 * requested Data */