1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /****************************************************************************/
35 * @file xuartlite_selftest.c
37 * This file contains the self-test functions for the UART Lite component
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ---- -------- -----------------------------------------------
45 * 1.00a ecm 08/31/01 First release
46 * 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
47 * 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
48 * renamed to remove _m from the name.
49 * 3.0 adk 17/12/13 Fixed CR:741186,761863 Reset the FIFO's before reading
50 * the status register We don't know the status of the Status
51 * Register in case of if there is more than one uartlite IP
52 * instance in the h/w design.
55 *****************************************************************************/
57 /***************************** Include Files ********************************/
59 #include "xil_types.h"
60 #include "xil_assert.h"
62 #include "xuartlite.h"
63 #include "xuartlite_i.h"
66 /************************** Constant Definitions ****************************/
69 /**************************** Type Definitions ******************************/
72 /***************** Macros (Inline Functions) Definitions ********************/
75 /************************** Variable Definitions ****************************/
78 /************************** Function Prototypes *****************************/
81 /****************************************************************************/
84 * Runs a self-test on the device hardware. Since there is no way to perform a
85 * loopback in the hardware, this test can only check the state of the status
86 * register to verify it is correct. This test assumes that the hardware
87 * device is still in its reset state, but has been initialized with the
88 * Initialize function.
90 * @param InstancePtr is a pointer to the XUartLite instance.
93 * - XST_SUCCESS if the self-test was successful.
94 * - XST_FAILURE if the self-test failed, the status register
95 * value was not correct
99 ******************************************************************************/
100 int XUartLite_SelfTest(XUartLite *InstancePtr)
105 * Assert validates the input arguments
107 Xil_AssertNonvoid(InstancePtr != NULL);
108 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
111 * Reset the FIFO's before reading the status register.
112 * It is likely that the Uartlite IP may not always have an
113 * empty Tx and Rx FIFO when a selftest is performed if more than one
114 * uartlite instance is present in the h/w design.
116 XUartLite_ResetFifos(InstancePtr);
119 * Read the Status register value to check if it is the correct value
122 StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
123 XUL_STATUS_REG_OFFSET);
126 * If the status register is any other value other than
127 * XUL_SR_TX_FIFO_EMPTY then the test is a failure since this is
128 * the not the value after reset
130 if (StatusRegister != XUL_SR_TX_FIFO_EMPTY) {