1 /******************************************************************************
3 * Copyright (C) 2002 - 2015 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
36 * @addtogroup uartlite_v3_1
39 * This file contains the self-test functions for the UART Lite component
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ---- -------- -----------------------------------------------
47 * 1.00a ecm 08/31/01 First release
48 * 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
49 * 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
50 * renamed to remove _m from the name.
51 * 3.0 adk 17/12/13 Fixed CR:741186,761863 Reset the FIFO's before reading
52 * the status register We don't know the status of the Status
53 * Register in case of if there is more than one uartlite IP
54 * instance in the h/w design.
57 *****************************************************************************/
59 /***************************** Include Files ********************************/
61 #include "xil_types.h"
62 #include "xil_assert.h"
64 #include "xuartlite.h"
65 #include "xuartlite_i.h"
68 /************************** Constant Definitions ****************************/
71 /**************************** Type Definitions ******************************/
74 /***************** Macros (Inline Functions) Definitions ********************/
77 /************************** Variable Definitions ****************************/
80 /************************** Function Prototypes *****************************/
83 /****************************************************************************/
86 * Runs a self-test on the device hardware. Since there is no way to perform a
87 * loopback in the hardware, this test can only check the state of the status
88 * register to verify it is correct. This test assumes that the hardware
89 * device is still in its reset state, but has been initialized with the
90 * Initialize function.
92 * @param InstancePtr is a pointer to the XUartLite instance.
95 * - XST_SUCCESS if the self-test was successful.
96 * - XST_FAILURE if the self-test failed, the status register
97 * value was not correct
101 ******************************************************************************/
102 int XUartLite_SelfTest(XUartLite *InstancePtr)
107 * Assert validates the input arguments
109 Xil_AssertNonvoid(InstancePtr != NULL);
110 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
113 * Reset the FIFO's before reading the status register.
114 * It is likely that the Uartlite IP may not always have an
115 * empty Tx and Rx FIFO when a selftest is performed if more than one
116 * uartlite instance is present in the h/w design.
118 XUartLite_ResetFifos(InstancePtr);
121 * Read the Status register value to check if it is the correct value
124 StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
125 XUL_STATUS_REG_OFFSET);
128 * If the status register is any other value other than
129 * XUL_SR_TX_FIFO_EMPTY then the test is a failure since this is
130 * the not the value after reset
132 if (StatusRegister != XUL_SR_TX_FIFO_EMPTY) {