]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/uartlite_v3_0/src/xuartlite_selftest.c
4c39a2d332ecf6939060b67459393bec0fee40fc
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / uartlite_v3_0 / src / xuartlite_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 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 *
37 * This file contains the self-test functions for the UART Lite component
38 * (XUartLite).
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
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.
53 * </pre>
54 *
55 *****************************************************************************/
56
57 /***************************** Include Files ********************************/
58
59 #include "xil_types.h"
60 #include "xil_assert.h"
61 #include "xstatus.h"
62 #include "xuartlite.h"
63 #include "xuartlite_i.h"
64 #include "xil_io.h"
65
66 /************************** Constant Definitions ****************************/
67
68
69 /**************************** Type Definitions ******************************/
70
71
72 /***************** Macros (Inline Functions) Definitions ********************/
73
74
75 /************************** Variable Definitions ****************************/
76
77
78 /************************** Function Prototypes *****************************/
79
80
81 /****************************************************************************/
82 /**
83 *
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.
89 *
90 * @param        InstancePtr is a pointer to the XUartLite instance.
91 *
92 * @return
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
96 *
97 * @note         None.
98 *
99 ******************************************************************************/
100 int XUartLite_SelfTest(XUartLite *InstancePtr)
101 {
102         u32 StatusRegister;
103
104         /*
105          * Assert validates the input arguments
106          */
107         Xil_AssertNonvoid(InstancePtr != NULL);
108         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
109
110         /*
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.
115          */
116                 XUartLite_ResetFifos(InstancePtr);
117                 
118         /*
119          * Read the Status register value to check if it is the correct value
120          * after a reset
121          */
122         StatusRegister = XUartLite_ReadReg(InstancePtr->RegBaseAddress,
123                                         XUL_STATUS_REG_OFFSET);
124
125         /*
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
129          */
130         if (StatusRegister != XUL_SR_TX_FIFO_EMPTY) {
131                 return XST_FAILURE;
132         }
133
134         return XST_SUCCESS;
135 }
136
137