XilinxProcessorIPLib/drivers/axicdma/src/xaxicdma_bdring.c
u32 XAxiCdma_BdRingFromHw(XAxiCdma *InstancePtr, int BdLimit,
			     XAxiCdma_Bd ** BdSetPtr)
{
	XAxiCdma_Bd *CurBdPtr;
	int BdCount;
	u32 BdSts;

	CurBdPtr = InstancePtr->HwBdHead;
	BdCount = 0;
	BdSts = 0;

	/* If no BDs in work group, then there's nothing to search */
	if (InstancePtr->HwBdCnt == 0) {
		*BdSetPtr = (XAxiCdma_Bd *)NULL;

		return 0;
	}

	if (BdLimit > InstancePtr->HwBdCnt) {
		BdLimit = InstancePtr->HwBdCnt;
	}

	/* Starting at HwBdHead, keep moving forward in the list until:
	 *  - A BD is encountered with its completed bit clear in the status
	 *    word which means hardware has not completed processing of that
	 *    BD.
	 *  - InstancePtr->HwBdTail is reached
	 *  - The number of requested BDs has been processed
	 */
	while (BdCount < BdLimit) {
		/* Read the status */
		XAXICDMA_CACHE_INVALIDATE((UINTPTR)CurBdPtr);
		BdSts = XAxiCdma_BdGetSts(CurBdPtr);

		/* If the hardware still hasn't processed this BD then we are
		 * done
		 */
		if (!(BdSts & XAXICDMA_BD_STS_COMPLETE_MASK)) {
			break;
		}

		BdCount++;

		/* Reached the end of the work group */
		if (CurBdPtr == InstancePtr->HwBdTail) {
			break;
		}

		/* Move on to the next BD in work group */
		CurBdPtr = XAxiCdma_BdRingNext(InstancePtr, CurBdPtr);
	}

	/* If BdCount is non-zero then BDs were found to return. Set return
	 * parameters, update pointers and counters, return success
	 */
	if (BdCount) {
		*BdSetPtr = InstancePtr->HwBdHead;
		InstancePtr->HwBdCnt -= BdCount;
		InstancePtr->PostBdCnt += BdCount;
		XAXICDMA_RING_SEEKAHEAD(InstancePtr,
		    InstancePtr->HwBdHead, BdCount);

		return BdCount;
	}
	else {
		*BdSetPtr = (XAxiCdma_Bd *)NULL;

		return 0;
	}

	return 0;
}
/*****************************************************************************/
/**
 * This function tries to retrieve completed BDs from the hardware.
 *
 * @param	InstancePtr is the driver instance we are working on
 * @param	BdLimit is the maximum number of completed BDs to retrieve
 * @param	BdSetPtr is the set of completed BDs
 *
 * @return	The number of completed BDs.
 *
 * @note	None.
 *
 *****************************************************************************/
This function tries to retrieve completed BDs from the hardware.
@param       InstancePtr is the driver instance we are working on
@param       BdLimit is the maximum number of completed BDs to retrieve
@param       BdSetPtr is the set of completed BDs

@return      The number of completed BDs.

@note        None.
This function tries to retrieve completed BDs from the hardware . @param InstancePtr is the driver instance we are working on @param BdLimit is the maximum number of completed BDs to retrieve @param BdSetPtr is the set of completed BDs @return The number of completed BDs . @note None .
u32 XAxiCdma_BdRingFromHw(XAxiCdma *InstancePtr, int BdLimit,
			     XAxiCdma_Bd ** BdSetPtr)
{
	XAxiCdma_Bd *CurBdPtr;
	int BdCount;
	u32 BdSts;
	CurBdPtr = InstancePtr->HwBdHead;
	BdCount = 0;
	BdSts = 0;
	if (InstancePtr->HwBdCnt == 0) {
		*BdSetPtr = (XAxiCdma_Bd *)NULL;
		return 0;
	}
	if (BdLimit > InstancePtr->HwBdCnt) {
		BdLimit = InstancePtr->HwBdCnt;
	}
	while (BdCount < BdLimit) {
		XAXICDMA_CACHE_INVALIDATE((UINTPTR)CurBdPtr);
		BdSts = XAxiCdma_BdGetSts(CurBdPtr);
		if (!(BdSts & XAXICDMA_BD_STS_COMPLETE_MASK)) {
			break;
		}
		BdCount++;
		if (CurBdPtr == InstancePtr->HwBdTail) {
			break;
		}
		CurBdPtr = XAxiCdma_BdRingNext(InstancePtr, CurBdPtr);
	}
	if (BdCount) {
		*BdSetPtr = InstancePtr->HwBdHead;
		InstancePtr->HwBdCnt -= BdCount;
		InstancePtr->PostBdCnt += BdCount;
		XAXICDMA_RING_SEEKAHEAD(InstancePtr,
		    InstancePtr->HwBdHead, BdCount);
		return BdCount;
	}
	else {
		*BdSetPtr = (XAxiCdma_Bd *)NULL;
		return 0;
	}
	return 0;
}
u32 XAxiCdma_BdRingFromHw ( XAxiCdma * InstancePtr , int BdLimit , XAxiCdma_Bd * * BdSetPtr ) { XAxiCdma_Bd * CurBdPtr ; int BdCount ; u32 BdSts ; CurBdPtr = InstancePtr -> HwBdHead ; BdCount = 0 ; BdSts = 0 ; if ( InstancePtr -> HwBdCnt == 0 ) { * BdSetPtr = ( XAxiCdma_Bd * ) NULL ; return 0 ; } if ( BdLimit > InstancePtr -> HwBdCnt ) { BdLimit = InstancePtr -> HwBdCnt ; } while ( BdCount < BdLimit ) { XAXICDMA_CACHE_INVALIDATE ( ( UINTPTR ) CurBdPtr ) ; BdSts = XAxiCdma_BdGetSts ( CurBdPtr ) ; if ( ! ( BdSts & XAXICDMA_BD_STS_COMPLETE_MASK ) ) { break ; } BdCount ++ ; if ( CurBdPtr == InstancePtr -> HwBdTail ) { break ; } CurBdPtr = XAxiCdma_BdRingNext ( InstancePtr , CurBdPtr ) ; } if ( BdCount ) { * BdSetPtr = InstancePtr -> HwBdHead ; InstancePtr -> HwBdCnt -= BdCount ; InstancePtr -> PostBdCnt += BdCount ; XAXICDMA_RING_SEEKAHEAD ( InstancePtr , InstancePtr -> HwBdHead , BdCount ) ; return BdCount ; } else { * BdSetPtr = ( XAxiCdma_Bd * ) NULL ; return 0 ; } return 0 ; }
This function tries to retrieve completed BDs from the hardware.
This function tries to retrieve completed BDs from the hardware .
/* If no BDs in work group, then there's nothing to search */ /* Starting at HwBdHead, keep moving forward in the list until:
	 *  - A BD is encountered with its completed bit clear in the status
	 *    word which means hardware has not completed processing of that
	 *    BD.
	 *  - InstancePtr->HwBdTail is reached
	 *  - The number of requested BDs has been processed
	 */ /* Read the status */ /* If the hardware still hasn't processed this BD then we are
		 * done
		 */ /* Reached the end of the work group */ /* Move on to the next BD in work group */ /* If BdCount is non-zero then BDs were found to return. Set return
	 * parameters, update pointers and counters, return success
	 */