]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/xadcps_v2_0/src/xadcps_selftest.c
FreeRTOS source updates:
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / xadcps_v2_0 / src / xadcps_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2011 - 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 xadcps_selftest.c
36 * @addtogroup xadcps_v2_0
37 * @{
38 *
39 * This file contains a diagnostic self test function for the XAdcPs driver.
40 * The self test function does a simple read/write test of the Alarm Threshold
41 * Register.
42 *
43 * See xadcps.h for more information.
44 *
45 * @note None.
46 *
47 * <pre>
48 *
49 * MODIFICATION HISTORY:
50 *
51 * Ver   Who    Date     Changes
52 * ----- -----  -------- -----------------------------------------------------
53 * 1.00a ssb    12/22/11 First release based on the XPS/AXI xadc driver
54 *
55 * </pre>
56 *
57 *****************************************************************************/
58
59 /***************************** Include Files ********************************/
60
61 #include "xadcps.h"
62
63 /************************** Constant Definitions ****************************/
64
65 /*
66  * The following constant defines the test value to be written
67  * to the Alarm Threshold Register
68  */
69 #define XADCPS_ATR_TEST_VALUE           0x55
70
71 /**************************** Type Definitions ******************************/
72
73 /***************** Macros (Inline Functions) Definitions ********************/
74
75 /************************** Variable Definitions ****************************/
76
77 /************************** Function Prototypes *****************************/
78
79 /*****************************************************************************/
80 /**
81 *
82 * Run a self-test on the driver/device. The test
83 *       - Resets the device,
84 *       - Writes a value into the Alarm Threshold register and reads it back
85 *       for comparison.
86 *       - Resets the device again.
87 *
88 *
89 * @param        InstancePtr is a pointer to the XAdcPs instance.
90 *
91 * @return
92 *               - XST_SUCCESS if the value read from the Alarm Threshold
93 *               register is the same as the value written.
94 *               - XST_FAILURE Otherwise
95 *
96 * @note         This is a destructive test in that resets of the device are
97 *               performed. Refer to the device specification for the
98 *               device status after the reset operation.
99 *
100 ******************************************************************************/
101 int XAdcPs_SelfTest(XAdcPs *InstancePtr)
102 {
103         int Status;
104         u32 RegValue;
105
106         /*
107          * Assert the argument
108          */
109         Xil_AssertNonvoid(InstancePtr != NULL);
110         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
111
112
113         /*
114          * Reset the device to get it back to its default state
115          */
116         XAdcPs_Reset(InstancePtr);
117
118         /*
119          * Write a value into the Alarm Threshold registers, read it back, and
120          * do the comparison
121          */
122         XAdcPs_SetAlarmThreshold(InstancePtr, XADCPS_ATR_VCCINT_UPPER,
123                                   XADCPS_ATR_TEST_VALUE);
124         RegValue = XAdcPs_GetAlarmThreshold(InstancePtr, XADCPS_ATR_VCCINT_UPPER);
125
126         if (RegValue == XADCPS_ATR_TEST_VALUE) {
127                 Status = XST_SUCCESS;
128         } else {
129                 Status = XST_FAILURE;
130         }
131
132         /*
133          * Reset the device again to its default state.
134          */
135         XAdcPs_Reset(InstancePtr);
136         /*
137          * Return the test result.
138          */
139         return Status;
140 }
141 /** @} */