XilinxProcessorIPLib/drivers/llfifo/src/xstreamer.c
void XStrm_Read(XStrm_RxFifoStreamer *InstancePtr, void *BufPtr,
		   unsigned Bytes)
{
	u8 *DestPtr = (u8 *) BufPtr;
	unsigned BytesRemaining = Bytes;
	unsigned FifoWordsToXfer;
	unsigned PartialBytes;
	unsigned i;

	while (BytesRemaining) {
		xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: BytesRemaining: %d\n", BytesRemaining);
		/* Case 1: There are bytes in the holding buffer
		 *
		 *   1) Read the bytes from the holding buffer to the target buffer.
		 *   2) Loop back around and handle the rest of the transfer.
		 */
		if (InstancePtr->HeadIndex != InstancePtr->FifoWidth) {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 1: InstancePtr->HeadIndex [%d] != InstancePtr->FifoWidth [%d]\n",
				    InstancePtr->HeadIndex, InstancePtr->FifoWidth);
			i = InstancePtr->HeadIndex;

			PartialBytes = min(BytesRemaining,
				InstancePtr->FifoWidth -
				InstancePtr->HeadIndex);
			InstancePtr->HeadIndex += PartialBytes;
			BytesRemaining -= PartialBytes;
			InstancePtr->FrmByteCnt -= PartialBytes;
			while (PartialBytes--) {
				*DestPtr = InstancePtr->AlignedBuffer.bytes[i];
				i++;
				DestPtr++;
			}
		}
		/* Case 2: There are no more bytes in the holding buffer and
		 *         the target buffer is 32 bit aligned and
		 *         the number of bytes remaining to transfer is greater
		 *         than or equal to the fifo width.
		 *
		 *   1) We can go fast by reading a long string of fifo words right out
		 *      of the fifo into the target buffer.
		 *   2) Loop back around to transfer the last few bytes.
		 */
		else if ((((UINTPTR)DestPtr & 3) == 0) &&
			 (BytesRemaining >= InstancePtr->FifoWidth)) {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 2: DestPtr: %p, BytesRemaining: %d, InstancePtr->FifoWidth: %d\n",
				    DestPtr, BytesRemaining, InstancePtr->FifoWidth);
			FifoWordsToXfer =
			    BytesRemaining / InstancePtr->FifoWidth;

			(*(InstancePtr->ReadFn)) (InstancePtr->FifoInstance,
						DestPtr, FifoWordsToXfer);
			DestPtr += FifoWordsToXfer * InstancePtr->FifoWidth;
			BytesRemaining -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
			InstancePtr->FrmByteCnt -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
		}
		/* Case 3: There are no more bytes in the holding buffer and
		 *         the number of bytes remaining to transfer is less than
		 *         the fifo width or
		 *         things just don't line up.
		 *
		 *   1) Fill the holding buffer.
		 *   2) Loop back around and handle the rest of the transfer.
		 */
		else {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 3\n");
			/*
			 * At the tail end, read one fifo word into the local holding
			 * buffer and loop back around to take care of the transfer.
			 */
			(*InstancePtr->ReadFn) (InstancePtr->FifoInstance,
						&(InstancePtr->AlignedBuffer.
						  bytes[0]), 1);
			InstancePtr->HeadIndex = 0;
		}
	}
	if ((InstancePtr->FrmByteCnt) == 0) {
		InstancePtr->HeadIndex = 0;
	}
}
/*****************************************************************************/
/**
*
* XStrm_Read reads <i>Bytes</i> bytes from the FIFO specified by
* <i>InstancePtr</i> to the block of memory, referenced by <i>BufPtr</i>.
*
* Care must be taken to ensure that the number of bytes read with one or more
* calls to XStrm_Read() does not exceed the number of bytes available given
* from the last call to XStrm_RxGetLen().
*
* @param    InstancePtr references the FIFO on which to operate.
*
* @param    BufPtr specifies the memory address to place the data read.
*
* @param    Bytes specifies the number of bytes to read.
*
* @return   N/A
*
******************************************************************************/
XStrm_Read reads Bytes bytes from the FIFO specified by
InstancePtr to the block of memory, referenced by BufPtr.

Care must be taken to ensure that the number of bytes read with one or more
calls to XStrm_Read() does not exceed the number of bytes available given
from the last call to XStrm_RxGetLen().
XStrm_Read reads Bytes bytes from the FIFO specified by InstancePtr to the block of memory referenced by BufPtr . Care must be taken to ensure that the number of bytes read with one or more calls to XStrm_Read () does not exceed the number of bytes available given from the last call to XStrm_RxGetLen () .
void XStrm_Read(XStrm_RxFifoStreamer *InstancePtr, void *BufPtr,
		   unsigned Bytes)
{
	u8 *DestPtr = (u8 *) BufPtr;
	unsigned BytesRemaining = Bytes;
	unsigned FifoWordsToXfer;
	unsigned PartialBytes;
	unsigned i;
	while (BytesRemaining) {
		xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: BytesRemaining: %d\n", BytesRemaining);
		if (InstancePtr->HeadIndex != InstancePtr->FifoWidth) {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 1: InstancePtr->HeadIndex [%d] != InstancePtr->FifoWidth [%d]\n",
				    InstancePtr->HeadIndex, InstancePtr->FifoWidth);
			i = InstancePtr->HeadIndex;
			PartialBytes = min(BytesRemaining,
				InstancePtr->FifoWidth -
				InstancePtr->HeadIndex);
			InstancePtr->HeadIndex += PartialBytes;
			BytesRemaining -= PartialBytes;
			InstancePtr->FrmByteCnt -= PartialBytes;
			while (PartialBytes--) {
				*DestPtr = InstancePtr->AlignedBuffer.bytes[i];
				i++;
				DestPtr++;
			}
		}
		else if ((((UINTPTR)DestPtr & 3) == 0) &&
			 (BytesRemaining >= InstancePtr->FifoWidth)) {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 2: DestPtr: %p, BytesRemaining: %d, InstancePtr->FifoWidth: %d\n",
				    DestPtr, BytesRemaining, InstancePtr->FifoWidth);
			FifoWordsToXfer =
			    BytesRemaining / InstancePtr->FifoWidth;
			(*(InstancePtr->ReadFn)) (InstancePtr->FifoInstance,
						DestPtr, FifoWordsToXfer);
			DestPtr += FifoWordsToXfer * InstancePtr->FifoWidth;
			BytesRemaining -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
			InstancePtr->FrmByteCnt -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
		}
		else {
			xdbg_printf(XDBG_DEBUG_FIFO_RX, "XStrm_Read: Case 3\n");
			(*InstancePtr->ReadFn) (InstancePtr->FifoInstance,
						&(InstancePtr->AlignedBuffer.
						  bytes[0]), 1);
			InstancePtr->HeadIndex = 0;
		}
	}
	if ((InstancePtr->FrmByteCnt) == 0) {
		InstancePtr->HeadIndex = 0;
	}
}
void XStrm_Read ( XStrm_RxFifoStreamer * InstancePtr , void * BufPtr , unsigned Bytes ) { u8 * DestPtr = ( u8 * ) BufPtr ; unsigned BytesRemaining = Bytes ; unsigned FifoWordsToXfer ; unsigned PartialBytes ; unsigned i ; while ( BytesRemaining ) { xdbg_printf ( XDBG_DEBUG_FIFO_RX , " \n " , BytesRemaining ) ; if ( InstancePtr -> HeadIndex != InstancePtr -> FifoWidth ) { xdbg_printf ( XDBG_DEBUG_FIFO_RX , " \n " , InstancePtr -> HeadIndex , InstancePtr -> FifoWidth ) ; i = InstancePtr -> HeadIndex ; PartialBytes = min ( BytesRemaining , InstancePtr -> FifoWidth - InstancePtr -> HeadIndex ) ; InstancePtr -> HeadIndex += PartialBytes ; BytesRemaining -= PartialBytes ; InstancePtr -> FrmByteCnt -= PartialBytes ; while ( PartialBytes -- ) { * DestPtr = InstancePtr -> AlignedBuffer . bytes [ i ] ; i ++ ; DestPtr ++ ; } } else if ( ( ( ( UINTPTR ) DestPtr & 3 ) == 0 ) && ( BytesRemaining >= InstancePtr -> FifoWidth ) ) { xdbg_printf ( XDBG_DEBUG_FIFO_RX , " \n " , DestPtr , BytesRemaining , InstancePtr -> FifoWidth ) ; FifoWordsToXfer = BytesRemaining / InstancePtr -> FifoWidth ; ( * ( InstancePtr -> ReadFn ) ) ( InstancePtr -> FifoInstance , DestPtr , FifoWordsToXfer ) ; DestPtr += FifoWordsToXfer * InstancePtr -> FifoWidth ; BytesRemaining -= FifoWordsToXfer * InstancePtr -> FifoWidth ; InstancePtr -> FrmByteCnt -= FifoWordsToXfer * InstancePtr -> FifoWidth ; } else { xdbg_printf ( XDBG_DEBUG_FIFO_RX , " \n " ) ; ( * InstancePtr -> ReadFn ) ( InstancePtr -> FifoInstance , & ( InstancePtr -> AlignedBuffer . bytes [ 0 ] ) , 1 ) ; InstancePtr -> HeadIndex = 0 ; } } if ( ( InstancePtr -> FrmByteCnt ) == 0 ) { InstancePtr -> HeadIndex = 0 ; } }
XStrm_Read reads <i>Bytes</i> bytes from the FIFO specified by
<i>InstancePtr</i> to the block of memory, referenced by <i>BufPtr</i>.
XStrm_Read reads <i > Bytes< / i > bytes from the FIFO specified by <i > InstancePtr< / i > to the block of memory referenced by <i > BufPtr< / i > .
/* Case 1: There are bytes in the holding buffer
		 *
		 *   1) Read the bytes from the holding buffer to the target buffer.
		 *   2) Loop back around and handle the rest of the transfer.
		 */ /* Case 2: There are no more bytes in the holding buffer and
		 *         the target buffer is 32 bit aligned and
		 *         the number of bytes remaining to transfer is greater
		 *         than or equal to the fifo width.
		 *
		 *   1) We can go fast by reading a long string of fifo words right out
		 *      of the fifo into the target buffer.
		 *   2) Loop back around to transfer the last few bytes.
		 */ /* Case 3: There are no more bytes in the holding buffer and
		 *         the number of bytes remaining to transfer is less than
		 *         the fifo width or
		 *         things just don't line up.
		 *
		 *   1) Fill the holding buffer.
		 *   2) Loop back around and handle the rest of the transfer.
		 */ /*
			 * At the tail end, read one fifo word into the local holding
			 * buffer and loop back around to take care of the transfer.
			 */