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

	while (BytesRemaining) {
		xdbg_printf(XDBG_DEBUG_FIFO_TX,
			    "XStrm_Write: BytesRemaining: %d\n",
			    BytesRemaining);
		/* Case 1: The holding buffer is full
		 *
		 *   1) Write it to the fifo.
		 *   2) Fall through to transfer more bytes in this iteration.
		 */
		if (InstancePtr->TailIndex == InstancePtr->FifoWidth) {
			xdbg_printf(XDBG_DEBUG_FIFO_TX,
				    "XStrm_Write: (case 1) TailIndex: %d; FifoWidth: %d; WriteFn: %p\n",
				    InstancePtr->TailIndex, InstancePtr->FifoWidth,
				    InstancePtr->WriteFn);
			(*InstancePtr->WriteFn) (InstancePtr->FifoInstance,
						 &(InstancePtr->AlignedBuffer.
						   bytes[0]), 1);
			InstancePtr->TailIndex = 0;
		}
		/* Case 2: There are no 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 writing a long string of fifo words right out
		 *      of the source buffer into the fifo.
		 *   2) Loop back around to transfer the last few bytes.
		 */
		if ((InstancePtr->TailIndex == 0) &&
		    (BytesRemaining >= InstancePtr->FifoWidth) &&
		    (((UINTPTR)SrcPtr & 3) == 0)) {
			FifoWordsToXfer =
				BytesRemaining / InstancePtr->FifoWidth;

			xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (case 2) TailIndex: %d; BytesRemaining: %d; FifoWidth: %d; SrcPtr: %p;\n InstancePtr: %p; WriteFn: %p ,\nFifoWordsToXfer: %d (BytesRemaining: %d)\n",
				    InstancePtr->TailIndex, BytesRemaining,
				    InstancePtr->FifoWidth, SrcPtr,
				    InstancePtr, InstancePtr->WriteFn,
				    FifoWordsToXfer,
				    BytesRemaining);

			(*InstancePtr->WriteFn) (InstancePtr->FifoInstance,
						 SrcPtr, FifoWordsToXfer);
			SrcPtr += FifoWordsToXfer * InstancePtr->FifoWidth;
			BytesRemaining -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
			xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (end case 2) TailIndex: %d; BytesRemaining: %d; SrcPtr: %p\n",
				    InstancePtr->TailIndex, BytesRemaining, SrcPtr);
		}
		/* Case 3: The alignment of the "galaxies" didn't occur in
		 *         Case 2 above, so we must pump the bytes through the
		 *         holding buffer.
		 *
		 *   1) Write bytes from the source buffer to the holding buffer
		 *   2) Loop back around and handle the rest of the transfer.
		 */
		else {
			i = InstancePtr->TailIndex;

			PartialBytes =
			    min(BytesRemaining,
				InstancePtr->FifoWidth -
				InstancePtr->TailIndex);
			BytesRemaining -= PartialBytes;
			InstancePtr->TailIndex += PartialBytes;
			while (PartialBytes--) {
				xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (case 3) PartialBytes: %d\n",
					    PartialBytes);
				InstancePtr->AlignedBuffer.bytes[i] = *SrcPtr;
				i++;
				SrcPtr++;
			}
		}
	}
}
/*****************************************************************************/
/**
*
* XStrm_Write writes <i>Bytes</i> bytes of the block of memory, referenced by
* <i>BufPtr</i>, to the transmit channel of the FIFO referenced by
* <i>InstancePtr</i>.
*
* Care must be taken to ensure that the number of bytes written with one or
* more calls to XStrm_Write() matches the number of bytes given in the next
* call to XStrm_TxSetLen().
*
* @param    InstancePtr references the FIFO on which to operate.
*
* @param    BufPtr specifies the memory address of data to write.
*
* @param    Bytes specifies the number of bytes to write.
*
* @return   N/A
*
******************************************************************************/
XStrm_Write writes Bytes bytes of the block of memory, referenced by
BufPtr, to the transmit channel of the FIFO referenced by
InstancePtr.

Care must be taken to ensure that the number of bytes written with one or
more calls to XStrm_Write() matches the number of bytes given in the next
call to XStrm_TxSetLen().
XStrm_Write writes Bytes bytes of the block of memory referenced by BufPtr to the transmit channel of the FIFO referenced by InstancePtr . Care must be taken to ensure that the number of bytes written with one or more calls to XStrm_Write () matches the number of bytes given in the next call to XStrm_TxSetLen () .
void XStrm_Write(XStrm_TxFifoStreamer *InstancePtr, void *BufPtr,
		    unsigned Bytes)
{
	u8 *SrcPtr = (u8 *) BufPtr;
	unsigned BytesRemaining = Bytes;
	unsigned FifoWordsToXfer;
	unsigned PartialBytes;
	unsigned i;
	while (BytesRemaining) {
		xdbg_printf(XDBG_DEBUG_FIFO_TX,
			    "XStrm_Write: BytesRemaining: %d\n",
			    BytesRemaining);
		if (InstancePtr->TailIndex == InstancePtr->FifoWidth) {
			xdbg_printf(XDBG_DEBUG_FIFO_TX,
				    "XStrm_Write: (case 1) TailIndex: %d; FifoWidth: %d; WriteFn: %p\n",
				    InstancePtr->TailIndex, InstancePtr->FifoWidth,
				    InstancePtr->WriteFn);
			(*InstancePtr->WriteFn) (InstancePtr->FifoInstance,
						 &(InstancePtr->AlignedBuffer.
						   bytes[0]), 1);
			InstancePtr->TailIndex = 0;
		}
		if ((InstancePtr->TailIndex == 0) &&
		    (BytesRemaining >= InstancePtr->FifoWidth) &&
		    (((UINTPTR)SrcPtr & 3) == 0)) {
			FifoWordsToXfer =
				BytesRemaining / InstancePtr->FifoWidth;
			xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (case 2) TailIndex: %d; BytesRemaining: %d; FifoWidth: %d; SrcPtr: %p;\n InstancePtr: %p; WriteFn: %p ,\nFifoWordsToXfer: %d (BytesRemaining: %d)\n",
				    InstancePtr->TailIndex, BytesRemaining,
				    InstancePtr->FifoWidth, SrcPtr,
				    InstancePtr, InstancePtr->WriteFn,
				    FifoWordsToXfer,
				    BytesRemaining);
			(*InstancePtr->WriteFn) (InstancePtr->FifoInstance,
						 SrcPtr, FifoWordsToXfer);
			SrcPtr += FifoWordsToXfer * InstancePtr->FifoWidth;
			BytesRemaining -=
				FifoWordsToXfer * InstancePtr->FifoWidth;
			xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (end case 2) TailIndex: %d; BytesRemaining: %d; SrcPtr: %p\n",
				    InstancePtr->TailIndex, BytesRemaining, SrcPtr);
		}
		else {
			i = InstancePtr->TailIndex;
			PartialBytes =
			    min(BytesRemaining,
				InstancePtr->FifoWidth -
				InstancePtr->TailIndex);
			BytesRemaining -= PartialBytes;
			InstancePtr->TailIndex += PartialBytes;
			while (PartialBytes--) {
				xdbg_printf(XDBG_DEBUG_FIFO_TX, "XStrm_Write: (case 3) PartialBytes: %d\n",
					    PartialBytes);
				InstancePtr->AlignedBuffer.bytes[i] = *SrcPtr;
				i++;
				SrcPtr++;
			}
		}
	}
}
void XStrm_Write ( XStrm_TxFifoStreamer * InstancePtr , void * BufPtr , unsigned Bytes ) { u8 * SrcPtr = ( u8 * ) BufPtr ; unsigned BytesRemaining = Bytes ; unsigned FifoWordsToXfer ; unsigned PartialBytes ; unsigned i ; while ( BytesRemaining ) { xdbg_printf ( XDBG_DEBUG_FIFO_TX , " \n " , BytesRemaining ) ; if ( InstancePtr -> TailIndex == InstancePtr -> FifoWidth ) { xdbg_printf ( XDBG_DEBUG_FIFO_TX , " \n " , InstancePtr -> TailIndex , InstancePtr -> FifoWidth , InstancePtr -> WriteFn ) ; ( * InstancePtr -> WriteFn ) ( InstancePtr -> FifoInstance , & ( InstancePtr -> AlignedBuffer . bytes [ 0 ] ) , 1 ) ; InstancePtr -> TailIndex = 0 ; } if ( ( InstancePtr -> TailIndex == 0 ) && ( BytesRemaining >= InstancePtr -> FifoWidth ) && ( ( ( UINTPTR ) SrcPtr & 3 ) == 0 ) ) { FifoWordsToXfer = BytesRemaining / InstancePtr -> FifoWidth ; xdbg_printf ( XDBG_DEBUG_FIFO_TX , " \n \n \n " , InstancePtr -> TailIndex , BytesRemaining , InstancePtr -> FifoWidth , SrcPtr , InstancePtr , InstancePtr -> WriteFn , FifoWordsToXfer , BytesRemaining ) ; ( * InstancePtr -> WriteFn ) ( InstancePtr -> FifoInstance , SrcPtr , FifoWordsToXfer ) ; SrcPtr += FifoWordsToXfer * InstancePtr -> FifoWidth ; BytesRemaining -= FifoWordsToXfer * InstancePtr -> FifoWidth ; xdbg_printf ( XDBG_DEBUG_FIFO_TX , " \n " , InstancePtr -> TailIndex , BytesRemaining , SrcPtr ) ; } else { i = InstancePtr -> TailIndex ; PartialBytes = min ( BytesRemaining , InstancePtr -> FifoWidth - InstancePtr -> TailIndex ) ; BytesRemaining -= PartialBytes ; InstancePtr -> TailIndex += PartialBytes ; while ( PartialBytes -- ) { xdbg_printf ( XDBG_DEBUG_FIFO_TX , " \n " , PartialBytes ) ; InstancePtr -> AlignedBuffer . bytes [ i ] = * SrcPtr ; i ++ ; SrcPtr ++ ; } } } }
XStrm_Write writes <i>Bytes</i> bytes of the block of memory, referenced by
<i>BufPtr</i>, to the transmit channel of the FIFO referenced by
<i>InstancePtr</i>.
XStrm_Write writes <i > Bytes< / i > bytes of the block of memory referenced by <i > BufPtr< / i > to the transmit channel of the FIFO referenced by <i > InstancePtr< / i > .
/* Case 1: The holding buffer is full
		 *
		 *   1) Write it to the fifo.
		 *   2) Fall through to transfer more bytes in this iteration.
		 */ /* Case 2: There are no 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 writing a long string of fifo words right out
		 *      of the source buffer into the fifo.
		 *   2) Loop back around to transfer the last few bytes.
		 */ /* Case 3: The alignment of the "galaxies" didn't occur in
		 *         Case 2 above, so we must pump the bytes through the
		 *         holding buffer.
		 *
		 *   1) Write bytes from the source buffer to the holding buffer
		 *   2) Loop back around and handle the rest of the transfer.
		 */