예제 #1
0
/**
*
* 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 XUartLite 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 XUartLite instance to be worked on.
*
* @return
*
* NumBytes is the number of bytes actually sent (put into the UART transmitter
* and/or FIFO).
*
* @note
*
* None.
*
*****************************************************************************/
unsigned int XUartLite_SendBuffer(XUartLite *InstancePtr)
{
    unsigned int SentCount = 0;
    Xuint8 StatusRegister;

    /* Read the line status register to determine if the transmitter is
     * full
     */

    StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

    /*
     * Fill the FIFO from the the buffer that was specified
     */

    while (((StatusRegister & XUL_SR_TX_FIFO_FULL) == 0) &&
           (SentCount < InstancePtr->SendBuffer.RemainingBytes))
    {
        XIo_Out32(InstancePtr->RegBaseAddress + XUL_TX_FIFO_OFFSET,
                  InstancePtr->SendBuffer.NextBytePtr[SentCount]);

        SentCount++;

        StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

    }

    /* Enter a critical region by disabling all the UART interrupts to allow
     * this call to stop a previous operation that may be interrupt driven
     */
    StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);
    XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, 0);

    /*
     * 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;

    /* Restore the interrupt enable register to it's previous value such
     * that the critical region is exited
     */
    StatusRegister &= XUL_CR_ENABLE_INTR;
    XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, StatusRegister);

    /*
     * Return the number of bytes that were sent, althought they really were
     * only put into the FIFO, not completely sent yet
     */
    return SentCount;
}
예제 #2
0
/**
*
* 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 XUartLite 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 XUartLite instance to be worked on.
*
* @return
*
* NumBytes is the number of bytes actually sent (put into the UART transmitter
* and/or FIFO).
*
* @note
*
* None.
*
*****************************************************************************/
unsigned int
XUartLite_SendBuffer(XUartLite * InstancePtr)
{
	unsigned int SentCount = 0;
	u32 StatusRegister;

	/* Read the line status register to determine if the transmitter is
	 * full
	 */

	StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

	/*
	 * Fill the FIFO from the the buffer that was specified
	 */

	SentCount = 0;

	while (((StatusRegister & XUL_SR_TX_FIFO_FULL) == 0) &&
	       (SentCount < InstancePtr->SendBuffer.RemainingBytes)) {
		XIo_Out32(InstancePtr->RegBaseAddress + XUL_TX_FIFO_OFFSET,
			  InstancePtr->SendBuffer.NextBytePtr[SentCount]);

		SentCount++;

		StatusRegister =
		    XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

	}

	/*
	 * 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;

	/*
	 * Return the number of bytes that were sent, althought they really were
	 * only put into the FIFO, not completely sent yet
	 */
	return SentCount;
}
예제 #3
0
/**
*
* This function receives 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 XUartLite component such that it may be called
* from a shell function that sets up the buffer or from an interrupt handler.
*
* This function will attempt to receive a specified number of bytes of data
* from the UART and store it into the specified buffer. This function is
* designed for either polled or interrupt driven modes. It is non-blocking
* such that it will return if there is no data has already received by the
* UART.
*
* In a polled mode, this function will only receive as much data as the UART
* can buffer, either in the receiver or in the FIFO if present and enabled.
* The application may need to call it repeatedly to receive a buffer. Polled
* mode is the default mode of operation for the driver.
*
* In interrupt mode, this function will start receiving and then the interrupt
* handler of the driver will continue until the buffer has been received. A
* callback function, as specified by the application, will be called to indicate
* the completion of receiving the buffer or when any receive errors or timeouts
* occur. Interrupt mode must be enabled using the SetOptions function.
*
* @param    InstancePtr is a pointer to the XUartLite instance to be worked on.
*
* @return
*
* The number of bytes received.
*
* @note
*
* None.
*
*****************************************************************************/
unsigned int
XUartLite_ReceiveBuffer(XUartLite * InstancePtr)
{
	u8 StatusRegister;
	unsigned int ReceivedCount = 0;

	/* Loop until there is not more data buffered by the UART or the specified
	 * number of bytes is received
	 */

	while (ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes) {
		/* Read the Status Register to determine if there is any data in
		 * the receiver/FIFO
		 */
		StatusRegister =
		    XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

		/* If there is data ready to be removed, then put the next byte
		 * received into the specified buffer and update the stats to reflect
		 * any receive errors for the byte
		 */
		if (StatusRegister & XUL_SR_RX_FIFO_VALID_DATA) {
			InstancePtr->ReceiveBuffer.
			    NextBytePtr[ReceivedCount++] =
			    XIo_In32(InstancePtr->RegBaseAddress +
				     XUL_RX_FIFO_OFFSET);

			XUartLite_mUpdateStats(InstancePtr, StatusRegister);
		}

		/* There's no more data buffered, so exit such that this function does
		 * not block waiting for data
		 */
		else {
			break;
		}
	}

	/* Update the receive buffer to reflect the number of bytes that was
	 * received
	 */
	InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount;
	InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount;

	/*
	 * Increment associated counters in the statistics
	 */
	InstancePtr->Stats.CharactersReceived += ReceivedCount;

	return ReceivedCount;
}
예제 #4
0
/**
*
* This function will attempt to receive a specified number of bytes of data
* from the UART and store it into the specified buffer. This function is
* designed for either polled or interrupt driven modes. It is non-blocking
* such that it will return if no data has already received by the UART.
*
* In a polled mode, this function will only receive as much data as the UART
* can buffer in the FIFO. The application may need to call it repeatedly to
* receive a buffer. Polled mode is the default mode of operation for the driver.
*
* In interrupt mode, this function will start receiving and then the interrupt
* handler of the driver will continue receiving data until the buffer has been
* received. A callback function, as specified by the application, will be called
* to indicate the completion of receiving the buffer or when any receive errors
* or timeouts occur. Interrupt mode must be enabled using the SetOptions function.
*
* @param    InstancePtr is a pointer to the XUartLite instance to be worked on.
* @param    BufferPtr is pointer to buffer for data to be received into
* @param    NumBytes is the number of bytes to be received. A value of zero will
*           stop a previous receive operation that is in progress in interrupt mode.
*
* @return
*
* The number of bytes received.
*
* @note
*
* The number of bytes is not asserted so that this function may be called with
* a value of zero to stop an operation that is already in progress.
*
*****************************************************************************/
unsigned int
XUartLite_Recv(XUartLite * InstancePtr, u8 * DataBufferPtr,
	       unsigned int NumBytes)
{
	unsigned int ReceivedCount;
	u32 StatusRegister;

	/*
	 * Assert validates the input arguments
	 */
	XASSERT_NONVOID(InstancePtr != NULL);
	XASSERT_NONVOID(DataBufferPtr != NULL);
	XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);

	/* Enter a critical region by disabling all the UART interrupts to allow
	 * this call to stop a previous operation that may be interrupt driven
	 */
	StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);
	XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, 0);

	/* Setup the specified buffer to be received by setting the instance
	 * variables so it can be received with polled or interrupt mode
	 */
	InstancePtr->ReceiveBuffer.RequestedBytes = NumBytes;
	InstancePtr->ReceiveBuffer.RemainingBytes = NumBytes;
	InstancePtr->ReceiveBuffer.NextBytePtr = DataBufferPtr;

	/* Restore the interrupt enable register to it's previous value such
	 * that the critical region is exited
	 */
	StatusRegister &= XUL_CR_ENABLE_INTR;
	XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET,
		  StatusRegister);

	/* Receive the data from the UART and return the number of bytes
	 * received
	 * This is done here to minimize the amount of time the interrupt is
	 * disabled since there is only one interrupt and the transmit could
	 * be emptying out while interrupts are blocked.
	 */

	ReceivedCount = XUartLite_ReceiveBuffer(InstancePtr);

	return ReceivedCount;

}
예제 #5
0
/**
*
* This function receives 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 XUartLite component such that it may be called
* from a shell function that sets up the buffer or from an interrupt handler.
*
* This function will attempt to receive a specified number of bytes of data
* from the UART and store it into the specified buffer. This function is
* designed for either polled or interrupt driven modes. It is non-blocking
* such that it will return if there is no data has already received by the
* UART.
*
* In a polled mode, this function will only receive as much data as the UART
* can buffer, either in the receiver or in the FIFO if present and enabled.
* The application may need to call it repeatedly to receive a buffer. Polled
* mode is the default mode of operation for the driver.
*
* In interrupt mode, this function will start receiving and then the interrupt
* handler of the driver will continue until the buffer has been received. A
* callback function, as specified by the application, will be called to indicate
* the completion of receiving the buffer or when any receive errors or timeouts
* occur. Interrupt mode must be enabled using the SetOptions function.
*
* @param    InstancePtr is a pointer to the XUartLite instance to be worked on.
*
* @return
*
* The number of bytes received.
*
* @note
*
* None.
*
*****************************************************************************/
unsigned int XUartLite_ReceiveBuffer(XUartLite *InstancePtr)
{
    Xuint8 StatusRegister;
    unsigned int ReceivedCount = 0;

    /* Loop until there is not more data buffered by the UART or the specified
     * number of bytes is received
     */

    while (ReceivedCount < InstancePtr->ReceiveBuffer.RemainingBytes)
    {
        /* Read the Status Register to determine if there is any data in
         * the receiver/FIFO
         */
        StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);

        /* If there is data ready to be removed, then put the next byte
         * received into the specified buffer and update the stats to reflect
         * any receive errors for the byte
         */
        if (StatusRegister & XUL_SR_RX_FIFO_VALID_DATA)
        {
            InstancePtr->ReceiveBuffer.NextBytePtr[ReceivedCount++] =
                XIo_In32(InstancePtr->RegBaseAddress + XUL_RX_FIFO_OFFSET);

            XUartLite_mUpdateStats(InstancePtr, StatusRegister);
        }

        /* There's no more data buffered, so exit such that this function does
         * not block waiting for data
         */
        else
        {
            break;
        }
    }

    /* Enter a critical region by disabling all the UART interrupts to allow
     * this call to stop a previous operation that may be interrupt driven
     */
    StatusRegister = XUartLite_mGetStatusReg(InstancePtr->RegBaseAddress);
    XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, 0);

    /* Update the receive buffer to reflect the number of bytes that was
     * received
     */
    InstancePtr->ReceiveBuffer.NextBytePtr += ReceivedCount;
    InstancePtr->ReceiveBuffer.RemainingBytes -= ReceivedCount;

    /*
     * Increment associated counters in the statistics
     */
    InstancePtr->Stats.CharactersReceived += ReceivedCount;

    /* Restore the interrupt enable register to it's previous value such
     * that the critical region is exited
     */
    StatusRegister &= XUL_CR_ENABLE_INTR;
    XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, StatusRegister);

    return ReceivedCount;
}