XilinxProcessorIPLib/drivers/uartns550/src/xuartns550.c
unsigned int XUartNs550_SendBuffer(XUartNs550 *InstancePtr)
{
	unsigned int SentCount = 0;
	unsigned int BytesToSend = 0;   /* default to not send anything */
	unsigned int FifoSize;
	u32 LsrRegister;
	u32 IirRegister;
	u32 IerRegister;

	/*
	 * Read the line status register to determine if the transmitter is
	 * empty
	 */
	LsrRegister = XUartNs550_GetLineStatusReg(InstancePtr->BaseAddress);

	/*
	 * If the transmitter is not empty then don't send any data, the empty
	 * room in the FIFO is not available
	 */
	if (LsrRegister & XUN_LSR_TX_BUFFER_EMPTY) {
		/*
		 * Read the interrupt ID register to determine if FIFOs
		 * are enabled
		 */
		IirRegister = XUartNs550_ReadReg(InstancePtr->BaseAddress,
							XUN_IIR_OFFSET);

		/*
		 * When there are FIFOs, send up to the FIFO size. When there
		 * are no FIFOs, only send 1 byte of data
		 */
		if (IirRegister & XUN_INT_ID_FIFOS_ENABLED) {
			/*
			 * Determine how many bytes can be sent depending on if
			 * the transmitter is empty, a FIFO size of N is really
			 * N - 1 plus the transmitter register
			 */
			if (LsrRegister & XUN_LSR_TX_EMPTY) {
				FifoSize = XUN_FIFO_SIZE;
			} else {
				FifoSize = XUN_FIFO_SIZE - 1;
			}

			/*
			 * FIFOs are enabled, if the number of bytes to send
			 * is less than the size of the FIFO, then send all
			 * bytes, otherwise fill the FIFO
			 */
			if (InstancePtr->SendBuffer.RemainingBytes < FifoSize) {
				BytesToSend =
					InstancePtr->SendBuffer.RemainingBytes;
			} else {
				BytesToSend = FifoSize;
			}
		} else if (InstancePtr->SendBuffer.RemainingBytes > 0) {
			/*
			 * Without FIFOs, we can only send 1 byte. We needed to
			 * check for non-zero remaining bytes in case this
			 * routine was called only to kick the transmitter and
			 * enable the UART interrupt
			 */
			BytesToSend = 1;
		}

		/*
		 * Fill the FIFO if it's present or the transmitter only from
		 * the the buffer that was specified
		 */
		for (SentCount = 0; SentCount < BytesToSend; SentCount++) {
			XUartNs550_WriteReg(InstancePtr->BaseAddress,
						XUN_THR_OFFSET,
				InstancePtr->SendBuffer.NextBytePtr[SentCount]);
		}
	}
	/*
	 * Update the buffer to reflect the bytes that were sent from it
	 */
	InstancePtr->SendBuffer.NextBytePtr += SentCount;
	InstancePtr->SendBuffer.RemainingBytes -= SentCount;

	/*
	 * Increment associated counters
	 */
	 InstancePtr->Stats.CharactersTransmitted += SentCount;

	/*
	 * If interrupts are enabled as indicated by the receive interrupt, then
	 * enable the transmit interrupt, it is not enabled continuously because
	 * it causes an interrupt whenever the FIFO is empty
	 */
	IerRegister = XUartNs550_ReadReg(InstancePtr->BaseAddress,
						XUN_IER_OFFSET);
	if (IerRegister & XUN_IER_RX_DATA) {
		XUartNs550_WriteReg(InstancePtr->BaseAddress, XUN_IER_OFFSET,
				 IerRegister | XUN_IER_TX_EMPTY);
	}
	/*
	 * Return the number of bytes that were sent, although they really were
	 * only put into the FIFO, not completely sent yet
	 */
	return SentCount;
}
/****************************************************************************/
/**
*
* This function sends a buffer that has been previously specified by setting
* up the instance variables of the instance. This function is designed to be
* an internal function for the XUartNs550 component such that it may be called
* from a shell function that sets up the buffer or from an interrupt handler.
*
* This function sends the specified buffer of data to the UART in either
* polled or interrupt driven modes. This function is non-blocking such that
* it will return before the data has been sent by the UART.
*
* In a polled mode, this function will only send as much data as the UART can
* buffer, either in the transmitter or in the FIFO if present and enabled.
* The application may need to call it repeatedly to send a buffer.
*
* In interrupt mode, this function will start sending the specified buffer and
* then the interrupt handler of the driver will continue until the buffer
* has been sent. A callback function, as specified by the application, will
* be called to indicate the completion of sending the buffer.
*
* @param	InstancePtr is a pointer to the XUartNs550 instance.
*
* @return	NumBytes is the number of bytes actually sent (put into the
*		UART tranmitter and/or FIFO).
*
* @note		None.
*
*****************************************************************************/
This function sends a buffer that has been previously specified by setting
up the instance variables of the instance. This function is designed to be
an internal function for the XUartNs550 component such that it may be called
from a shell function that sets up the buffer or from an interrupt handler.

This function sends the specified buffer of data to the UART in either
polled or interrupt driven modes. This function is non-blocking such that
it will return before the data has been sent by the UART.

In a polled mode, this function will only send as much data as the UART can
buffer, either in the transmitter or in the FIFO if present and enabled.
The application may need to call it repeatedly to send a buffer.

In interrupt mode, this function will start sending the specified buffer and
then the interrupt handler of the driver will continue until the buffer
has been sent. A callback function, as specified by the application, will
be called to indicate the completion of sending the buffer.
This function sends a buffer that has been previously specified by setting up the instance variables of the instance . This function is designed to be an internal function for the XUartNs550 component such that it may be called from a shell function that sets up the buffer or from an interrupt handler . This function sends the specified buffer of data to the UART in either polled or interrupt driven modes . This function is non - blocking such that it will return before the data has been sent by the UART . In a polled mode this function will only send as much data as the UART can buffer either in the transmitter or in the FIFO if present and enabled . The application may need to call it repeatedly to send a buffer . In interrupt mode this function will start sending the specified buffer and then the interrupt handler of the driver will continue until the buffer has been sent . A callback function as specified by the application will be called to indicate the completion of sending the buffer .
unsigned int XUartNs550_SendBuffer(XUartNs550 *InstancePtr)
{
	unsigned int SentCount = 0;
	unsigned int BytesToSend = 0;   
	unsigned int FifoSize;
	u32 LsrRegister;
	u32 IirRegister;
	u32 IerRegister;
	LsrRegister = XUartNs550_GetLineStatusReg(InstancePtr->BaseAddress);
	if (LsrRegister & XUN_LSR_TX_BUFFER_EMPTY) {
		IirRegister = XUartNs550_ReadReg(InstancePtr->BaseAddress,
							XUN_IIR_OFFSET);
		if (IirRegister & XUN_INT_ID_FIFOS_ENABLED) {
			if (LsrRegister & XUN_LSR_TX_EMPTY) {
				FifoSize = XUN_FIFO_SIZE;
			} else {
				FifoSize = XUN_FIFO_SIZE - 1;
			}
			if (InstancePtr->SendBuffer.RemainingBytes < FifoSize) {
				BytesToSend =
					InstancePtr->SendBuffer.RemainingBytes;
			} else {
				BytesToSend = FifoSize;
			}
		} else if (InstancePtr->SendBuffer.RemainingBytes > 0) {
			BytesToSend = 1;
		}
		for (SentCount = 0; SentCount < BytesToSend; SentCount++) {
			XUartNs550_WriteReg(InstancePtr->BaseAddress,
						XUN_THR_OFFSET,
				InstancePtr->SendBuffer.NextBytePtr[SentCount]);
		}
	}
	InstancePtr->SendBuffer.NextBytePtr += SentCount;
	InstancePtr->SendBuffer.RemainingBytes -= SentCount;
	 InstancePtr->Stats.CharactersTransmitted += SentCount;
	IerRegister = XUartNs550_ReadReg(InstancePtr->BaseAddress,
						XUN_IER_OFFSET);
	if (IerRegister & XUN_IER_RX_DATA) {
		XUartNs550_WriteReg(InstancePtr->BaseAddress, XUN_IER_OFFSET,
				 IerRegister | XUN_IER_TX_EMPTY);
	}
	return SentCount;
}
unsigned int XUartNs550_SendBuffer ( XUartNs550 * InstancePtr ) { unsigned int SentCount = 0 ; unsigned int BytesToSend = 0 ; unsigned int FifoSize ; u32 LsrRegister ; u32 IirRegister ; u32 IerRegister ; LsrRegister = XUartNs550_GetLineStatusReg ( InstancePtr -> BaseAddress ) ; if ( LsrRegister & XUN_LSR_TX_BUFFER_EMPTY ) { IirRegister = XUartNs550_ReadReg ( InstancePtr -> BaseAddress , XUN_IIR_OFFSET ) ; if ( IirRegister & XUN_INT_ID_FIFOS_ENABLED ) { if ( LsrRegister & XUN_LSR_TX_EMPTY ) { FifoSize = XUN_FIFO_SIZE ; } else { FifoSize = XUN_FIFO_SIZE - 1 ; } if ( InstancePtr -> SendBuffer . RemainingBytes < FifoSize ) { BytesToSend = InstancePtr -> SendBuffer . RemainingBytes ; } else { BytesToSend = FifoSize ; } } else if ( InstancePtr -> SendBuffer . RemainingBytes > 0 ) { BytesToSend = 1 ; } for ( SentCount = 0 ; SentCount < BytesToSend ; SentCount ++ ) { XUartNs550_WriteReg ( InstancePtr -> BaseAddress , XUN_THR_OFFSET , InstancePtr -> SendBuffer . NextBytePtr [ SentCount ] ) ; } } InstancePtr -> SendBuffer . NextBytePtr += SentCount ; InstancePtr -> SendBuffer . RemainingBytes -= SentCount ; InstancePtr -> Stats . CharactersTransmitted += SentCount ; IerRegister = XUartNs550_ReadReg ( InstancePtr -> BaseAddress , XUN_IER_OFFSET ) ; if ( IerRegister & XUN_IER_RX_DATA ) { XUartNs550_WriteReg ( InstancePtr -> BaseAddress , XUN_IER_OFFSET , IerRegister | XUN_IER_TX_EMPTY ) ; } return SentCount ; }
This function sends a buffer that has been previously specified by setting
up the instance variables of the instance.
This function sends a buffer that has been previously specified by setting up the instance variables of the instance .
/* default to not send anything */ /*
	 * Read the line status register to determine if the transmitter is
	 * empty
	 */ /*
	 * If the transmitter is not empty then don't send any data, the empty
	 * room in the FIFO is not available
	 */ /*
		 * Read the interrupt ID register to determine if FIFOs
		 * are enabled
		 */ /*
		 * When there are FIFOs, send up to the FIFO size. When there
		 * are no FIFOs, only send 1 byte of data
		 */ /*
			 * Determine how many bytes can be sent depending on if
			 * the transmitter is empty, a FIFO size of N is really
			 * N - 1 plus the transmitter register
			 */ /*
			 * FIFOs are enabled, if the number of bytes to send
			 * is less than the size of the FIFO, then send all
			 * bytes, otherwise fill the FIFO
			 */ /*
			 * Without FIFOs, we can only send 1 byte. We needed to
			 * check for non-zero remaining bytes in case this
			 * routine was called only to kick the transmitter and
			 * enable the UART interrupt
			 */ /*
		 * Fill the FIFO if it's present or the transmitter only from
		 * the the buffer that was specified
		 */ /*
	 * Update the buffer to reflect the bytes that were sent from it
	 */ /*
	 * Increment associated counters
	 */ /*
	 * If interrupts are enabled as indicated by the receive interrupt, then
	 * enable the transmit interrupt, it is not enabled continuously because
	 * it causes an interrupt whenever the FIFO is empty
	 */ /*
	 * Return the number of bytes that were sent, although they really were
	 * only put into the FIFO, not completely sent yet
	 */