XilinxProcessorIPLib/drivers/axidma/src/xaxidma_bdring.c
int XAxiDma_BdRingAlloc(XAxiDma_BdRing * RingPtr, int NumBd,
	XAxiDma_Bd ** BdSetPtr)
{
	if (NumBd <= 0) {

		xdbg_printf(XDBG_DEBUG_ERROR, "BdRingAlloc: negative BD "
				"number %d\r\n", NumBd);

		return XST_INVALID_PARAM;
	}

	/* Enough free BDs available for the request? */
	if (RingPtr->FreeCnt < NumBd) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		"Not enough BDs to alloc %d/%d\r\n", NumBd, RingPtr->FreeCnt);

		return XST_FAILURE;
	}

	/* Set the return argument and move FreeHead forward */
	*BdSetPtr = RingPtr->FreeHead;
	XAXIDMA_RING_SEEKAHEAD(RingPtr, RingPtr->FreeHead, NumBd);
	RingPtr->FreeCnt -= NumBd;
	RingPtr->PreCnt += NumBd;

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
 * Reserve locations in the BD ring. The set of returned BDs may be modified in
 * preparation for future DMA transactions. Once the BDs are ready to be
 * submitted to hardware, the application must call XAxiDma_BdRingToHw() in the
 * same order which they were allocated here. Example:
 *
 * <pre>
 *        NumBd = 2;
 *        Status = XDsma_RingBdAlloc(MyRingPtr, NumBd, &MyBdSet);
 *
 *        if (Status != XST_SUCCESS)
 *        {
 *            // Not enough BDs available for the request
 *        }
 *
 *        CurBd = MyBdSet;
 *        for (i=0; i<NumBd; i++)
 *        {
 *            // Prepare CurBd.....
 *
 *            // Onto next BD
 *            CurBd = XAxiDma_BdRingNext(MyRingPtr, CurBd);
 *        }
 *
 *        // Give list to hardware
 *        Status = XAxiDma_BdRingToHw(MyRingPtr, NumBd, MyBdSet);
 * </pre>
 *
 * A more advanced use of this function may allocate multiple sets of BDs.
 * They must be allocated and given to hardware in the correct sequence:
 * <pre>
 *        // Legal
 *        XAxiDma_BdRingAlloc(MyRingPtr, NumBd1, &MySet1);
 *        XAxiDma_BdRingToHw(MyRingPtr, NumBd1, MySet1);
 *
 *        // Legal
 *        XAxiDma_BdRingAlloc(MyRingPtr, NumBd1, &MySet1);
 *        XAxiDma_BdRingAlloc(MyRingPtr, NumBd2, &MySet2);
 *        XAxiDma_BdRingToHw(MyRingPtr, NumBd1, MySet1);
 *        XAxiDma_BdRingToHw(MyRingPtr, NumBd2, MySet2);
 *
 *        // Not legal
 *        XAxiDma_BdRingAlloc(MyRingPtr, NumBd1, &MySet1);
 *        XAxiDma_BdRingAlloc(MyRingPtr, NumBd2, &MySet2);
 *        XAxiDma_BdRingToHw(MyRingPtr, NumBd2, MySet2);
 *        XAxiDma_BdRingToHw(MyRingPtr, NumBd1, MySet1);
 * </pre>
 *
 * Use the API defined in xaxidmabd.h to modify individual BDs. Traversal of
 * the BD set can be done using XAxiDma_BdRingNext() and XAxiDma_BdRingPrev().
 *
 * @param	RingPtr is a pointer to the descriptor ring instance to be
 *		worked on.
 * @param	NumBd is the number of BDs to allocate
 * @param	BdSetPtr is an output parameter, it points to the first BD
 *		available for modification.
 *
 * @return
 *		- XST_SUCCESS if the requested number of BDs were returned in
 *		the BdSetPtr parameter.
 *		- XST_INVALID_PARAM if passed in NumBd is not positive
 *		- XST_FAILURE if there were not enough free BDs to satisfy
 *		the request.
 *
 * @note	This function should not be preempted by another XAxiDma_BdRing
 *		function call that modifies the BD space. It is the caller's
 *		responsibility to provide a mutual exclusion mechanism.
 *
 *		Do not modify more BDs than the number requested with the NumBd
 *		parameter. Doing so will lead to data corruption and system
 *		instability.
 *
 *		This function can be used only when DMA is in SG mode
 *
 *****************************************************************************/
Reserve locations in the BD ring. The set of returned BDs may be modified in
preparation for future DMA transactions. Once the BDs are ready to be
submitted to hardware, the application must call XAxiDma_BdRingToHw() in the
same order which they were allocated here. Example.



if (Status != XST_SUCCESS)
{
Not enough BDs available for the request
}







A more advanced use of this function may allocate multiple sets of BDs.





Use the API defined in xaxidmabd.h to modify individual BDs. Traversal of
the BD set can be done using XAxiDma_BdRingNext() and XAxiDma_BdRingPrev().

@param       RingPtr is a pointer to the descriptor ring instance to be
worked on.
@param       NumBd is the number of BDs to allocate
@param       BdSetPtr is an output parameter, it points to the first BD
available for modification.

@return
- XST_SUCCESS if the requested number of BDs were returned in
the BdSetPtr parameter.
- XST_INVALID_PARAM if passed in NumBd is not positive
- XST_FAILURE if there were not enough free BDs to satisfy
the request.

@note        This function should not be preempted by another XAxiDma_BdRing
function call that modifies the BD space. It is the caller's
responsibility to provide a mutual exclusion mechanism.

Do not modify more BDs than the number requested with the NumBd
parameter. Doing so will lead to data corruption and system
instability.

This function can be used only when DMA is in SG mode
Reserve locations in the BD ring . The set of returned BDs may be modified in preparation for future DMA transactions . Once the BDs are ready to be submitted to hardware the application must call XAxiDma_BdRingToHw () in the same order which they were allocated here . Example . if ( Status ! = XST_SUCCESS ) { Not enough BDs available for the request } A more advanced use of this function may allocate multiple sets of BDs . Use the API defined in xaxidmabd . h to modify individual BDs . Traversal of the BD set can be done using XAxiDma_BdRingNext () and XAxiDma_BdRingPrev () . @param RingPtr is a pointer to the descriptor ring instance to be worked on . @param NumBd is the number of BDs to allocate @param BdSetPtr is an output parameter it points to the first BD available for modification . @return - XST_SUCCESS if the requested number of BDs were returned in the BdSetPtr parameter . - XST_INVALID_PARAM if passed in NumBd is not positive - XST_FAILURE if there were not enough free BDs to satisfy the request . @note This function should not be preempted by another XAxiDma_BdRing function call that modifies the BD space . It is the caller ' s responsibility to provide a mutual exclusion mechanism . Do not modify more BDs than the number requested with the NumBd parameter . Doing so will lead to data corruption and system instability . This function can be used only when DMA is in SG mode
int XAxiDma_BdRingAlloc(XAxiDma_BdRing * RingPtr, int NumBd,
	XAxiDma_Bd ** BdSetPtr)
{
	if (NumBd <= 0) {
		xdbg_printf(XDBG_DEBUG_ERROR, "BdRingAlloc: negative BD "
				"number %d\r\n", NumBd);
		return XST_INVALID_PARAM;
	}
	if (RingPtr->FreeCnt < NumBd) {
		xdbg_printf(XDBG_DEBUG_ERROR,
		"Not enough BDs to alloc %d/%d\r\n", NumBd, RingPtr->FreeCnt);
		return XST_FAILURE;
	}
	*BdSetPtr = RingPtr->FreeHead;
	XAXIDMA_RING_SEEKAHEAD(RingPtr, RingPtr->FreeHead, NumBd);
	RingPtr->FreeCnt -= NumBd;
	RingPtr->PreCnt += NumBd;
	return XST_SUCCESS;
}
int XAxiDma_BdRingAlloc ( XAxiDma_BdRing * RingPtr , int NumBd , XAxiDma_Bd * * BdSetPtr ) { if ( NumBd <= 0 ) { xdbg_printf ( XDBG_DEBUG_ERROR , " " " \r \n " , NumBd ) ; return XST_INVALID_PARAM ; } if ( RingPtr -> FreeCnt < NumBd ) { xdbg_printf ( XDBG_DEBUG_ERROR , " \r \n " , NumBd , RingPtr -> FreeCnt ) ; return XST_FAILURE ; } * BdSetPtr = RingPtr -> FreeHead ; XAXIDMA_RING_SEEKAHEAD ( RingPtr , RingPtr -> FreeHead , NumBd ) ; RingPtr -> FreeCnt -= NumBd ; RingPtr -> PreCnt += NumBd ; return XST_SUCCESS ; }
Reserve locations in the BD ring.
Reserve locations in the BD ring .
/* Enough free BDs available for the request? */ /* Set the return argument and move FreeHead forward */