示例#1
0
/**
*
* Initialize a XUartLite instance.  The receive and transmit FIFOs of the
* UART are not flushed, so the user may want to flush them. The hardware
* device does not have any way to disable the receiver such that any valid
* data may be present in the receive FIFO.  This function disables the UART
* interrupt. The baudrate and format of the data are fixed in the hardware
* at hardware build time.
*
* @param    InstancePtr is a pointer to the XUartLite instance to be worked on.
* @param    DeviceId is the unique id of the device controlled by this
*           XUartLite instance.  Passing in a device id associates the
*           generic XUartLite instance to a specific device, as chosen by
*           the caller or application developer.
*
* @return
*
* - XST_SUCCESS if everything starts up as expected.
* - XST_DEVICE_NOT_FOUND if the device is not found in the configuration table.
*
* @note
*
* None.
*
*****************************************************************************/
XStatus
XUartLite_Initialize(XUartLite * InstancePtr, u16 DeviceId)
{
	XUartLite_Config *UartLiteConfigPtr;

	/*
	 * Assert validates the input arguments
	 */
	XASSERT_NONVOID(InstancePtr != NULL);

	/*
	 * Lookup the device configuration in the configuration table. Use this
	 * configuration info when initializing this component.
	 */
	UartLiteConfigPtr = XUartLite_LookupConfig(DeviceId);

	if (UartLiteConfigPtr == (XUartLite_Config *) NULL) {
		return XST_DEVICE_NOT_FOUND;
	}

	/*
	 * Set some default values, including setting the callback
	 * handlers to stubs.
	 */

	InstancePtr->SendBuffer.NextBytePtr = NULL;
	InstancePtr->SendBuffer.RemainingBytes = 0;
	InstancePtr->SendBuffer.RequestedBytes = 0;

	InstancePtr->ReceiveBuffer.NextBytePtr = NULL;
	InstancePtr->ReceiveBuffer.RemainingBytes = 0;
	InstancePtr->ReceiveBuffer.RequestedBytes = 0;

	InstancePtr->IsReady = XCOMPONENT_IS_READY;
	InstancePtr->RegBaseAddress = UartLiteConfigPtr->RegBaseAddr;
	InstancePtr->RecvHandler = StubHandler;
	InstancePtr->SendHandler = StubHandler;

	/* Write to the control register to disable the interrupts, don't
	 * reset the FIFOs are the user may want the data that's present
	 */
	XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, 0);

	/*
	 * Clear the statistics for this driver
	 */
	XUartLite_mClearStats(InstancePtr);

	return XST_SUCCESS;
}
/**
*
* Initialize a XUartLite instance.  The receive and transmit FIFOs of the
* UART are not flushed, so the user may want to flush them. The hardware
* device does not have any way to disable the receiver such that any valid
* data may be present in the receive FIFO.  This function disables the UART
* interrupt. The baudrate and format of the data are fixed in the hardware
* at hardware build time.
*
* @param InstancePtr is a pointer to the XUartLite instance to be worked on.
* @param Config is a reference to a structure containing information about
*        a specific UART Lite device. This function initializes an
*        InstancePtr object for a specific device specified by the contents
*        of Config. This function can initialize multiple instance objects
*        with the use of multiple calls giving different Config information
*        on each call.
* @param EffectiveAddr is the device base address in the virtual memory address
*        space. The caller is responsible for keeping the address mapping
*        from EffectiveAddr to the device physical base address unchanged
*        once this function is invoked. Unexpected errors may occur if the
*        address mapping changes after this function is called. If address
*        translation is not used, use Config->BaseAddress for this parameters,
*        passing the physical address instead.
*
* @return
*
* - XST_SUCCESS if everything starts up as expected.
*
* @note
*
* The Config pointer argument is not used by this function, but is provided
* to keep the function signature consistent with other drivers.
*
*****************************************************************************/
XStatus XUartLite_CfgInitialize(XUartLite *InstancePtr, XUartLite_Config *Config,
                                Xuint32 EffectiveAddr)
{
    /*
     * Assert validates the input arguments
     */
    XASSERT_NONVOID(InstancePtr != XNULL);

    /*
     * Set some default values, including setting the callback
     * handlers to stubs.
     */

    InstancePtr->SendBuffer.NextBytePtr = XNULL;
    InstancePtr->SendBuffer.RemainingBytes = 0;
    InstancePtr->SendBuffer.RequestedBytes = 0;

    InstancePtr->ReceiveBuffer.NextBytePtr = XNULL;
    InstancePtr->ReceiveBuffer.RemainingBytes = 0;
    InstancePtr->ReceiveBuffer.RequestedBytes = 0;

    InstancePtr->IsReady = XCOMPONENT_IS_READY;
    InstancePtr->RegBaseAddress = EffectiveAddr;
    InstancePtr->RecvHandler = StubHandler;
    InstancePtr->SendHandler = StubHandler;

    /* Write to the control register to disable the interrupts, don't
     * reset the FIFOs are the user may want the data that's present
     */
    XIo_Out32(InstancePtr->RegBaseAddress + XUL_CONTROL_REG_OFFSET, 0);

    /*
     * Clear the statistics for this driver
     */
    XUartLite_mClearStats(InstancePtr);

    return XST_SUCCESS;
}