]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/uartlite_v3_2/src/xuartlite_selftest.c
Update the Microblaze hardware design and BSP to the latest IP and tool versions.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / uartlite_v3_2 / src / xuartlite_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2015 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xuartlite_selftest.c
36 * @addtogroup uartlite_v3_1
37 * @{
38 *
39 * This file contains the self-test functions for the UART Lite component
40 * (XUartLite).
41 *
42 * <pre>
43 * MODIFICATION HISTORY:
44 *
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.
55 * </pre>
56 *
57 *****************************************************************************/
58
59 /***************************** Include Files ********************************/
60
61 #include "xil_types.h"
62 #include "xil_assert.h"
63 #include "xstatus.h"
64 #include "xuartlite.h"
65 #include "xuartlite_i.h"
66 #include "xil_io.h"
67
68 /************************** Constant Definitions ****************************/
69
70
71 /**************************** Type Definitions ******************************/
72
73
74 /***************** Macros (Inline Functions) Definitions ********************/
75
76
77 /************************** Variable Definitions ****************************/
78
79
80 /************************** Function Prototypes *****************************/
81
82
83 /****************************************************************************/
84 /**
85 *
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.
91 *
92 * @param        InstancePtr is a pointer to the XUartLite instance.
93 *
94 * @return
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
98 *
99 * @note         None.
100 *
101 ******************************************************************************/
102 int XUartLite_SelfTest(XUartLite *InstancePtr)
103 {
104         u32 StatusRegister;
105
106         /*
107          * Assert validates the input arguments
108          */
109         Xil_AssertNonvoid(InstancePtr != NULL);
110         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
111
112         /*
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.
117          */
118                 XUartLite_ResetFifos(InstancePtr);
119                 
120         /*
121          * Read the Status register value to check if it is the correct value
122          * after a reset
123          */
124         StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
125                                         XUL_STATUS_REG_OFFSET);
126
127         /*
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
131          */
132         if (StatusRegister != XUL_SR_TX_FIFO_EMPTY) {
133                 return XST_FAILURE;
134         }
135
136         return XST_SUCCESS;
137 }
138
139
140 /** @} */