]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/wdtps_v3_0/src/xwdtps_selftest.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / wdtps_v3_0 / src / xwdtps_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 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 xwdtps_selftest.c
36 * @addtogroup wdtps_v3_0
37 * @{
38 *
39 * Contains diagnostic self-test functions for the XWdtPs driver.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who    Date     Changes
45 * ----- ------ -------- --------------------------------------------
46 * 1.00a ecm/jz 01/15/10 First release
47 * 1.02a sg     08/01/12 Modified it use the Reset Length mask for the self
48 *                       test for CR 658287
49 * 3.00  kvn    02/13/15 Modified code for MISRA-C:2012 compliance.
50 * </pre>
51 *
52 ******************************************************************************/
53
54 /***************************** Include Files *********************************/
55
56 #include "xil_types.h"
57 #include "xil_assert.h"
58 #include "xwdtps.h"
59
60 /************************** Constant Definitions *****************************/
61
62
63 /**************************** Type Definitions *******************************/
64
65
66 /***************** Macros (Inline Functions) Definitions *********************/
67
68
69 /************************** Function Prototypes ******************************/
70
71
72 /************************** Variable Definitions *****************************/
73
74
75 /****************************************************************************/
76 /**
77 *
78 * Run a self-test on the timebase. This test verifies that the register access
79 * locking functions. This is tested by trying to alter a register without
80 * setting the key value and verifying that the register contents did not
81 * change.
82 *
83 * @param        InstancePtr is a pointer to the XWdtPs instance.
84 *
85 * @return
86 *               - XST_SUCCESS if self-test was successful.
87 *               - XST_FAILURE if self-test was not successful.
88 *
89 * @note         None.
90 *
91 ******************************************************************************/
92 s32 XWdtPs_SelfTest(XWdtPs *InstancePtr)
93 {
94         u32 ZmrOrig;
95         u32 ZmrValue1;
96         u32 ZmrValue2;
97         s32 Status;
98
99         /*
100          * Assert to ensure the inputs are valid and the instance has been
101          * initialized.
102          */
103         Xil_AssertNonvoid(InstancePtr != NULL);
104         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
105
106         /*
107          * Read the ZMR register at start the test.
108          */
109         ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
110                                  XWDTPS_ZMR_OFFSET);
111
112         /*
113          * EX-OR in the length of the interrupt pulse,
114          * do not set the key value.
115          */
116         ZmrValue1 = ZmrOrig ^ (u32)XWDTPS_ZMR_RSTLN_MASK;
117
118
119         /*
120          * Try to write to register w/o key value then read back.
121          */
122         XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
123                           ZmrValue1);
124
125         ZmrValue2 =     XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
126                                  XWDTPS_ZMR_OFFSET);
127
128         if (ZmrValue1 == ZmrValue2) {
129                 /*
130                  * If the values match, the hw failed the test,
131                  * return orig register value.
132                  */
133                 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
134                                   XWDTPS_ZMR_OFFSET,
135                                   (ZmrOrig | (u32)XWDTPS_ZMR_ZKEY_VAL));
136                 Status = XST_FAILURE;
137         } else {
138
139
140                 /*
141                  * Try to write to register with key value then read back.
142                  */
143                 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
144                                   (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL));
145
146                 ZmrValue2 =     XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
147                                          XWDTPS_ZMR_OFFSET);
148
149                 if (ZmrValue1 != ZmrValue2) {
150                         /*
151                          * If the values do not match, the hw failed the test,
152                          * return orig register value.
153                          */
154                         XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
155                                           XWDTPS_ZMR_OFFSET,
156                                           ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
157                         Status = XST_FAILURE;
158
159                 } else {
160
161                         /*
162                          * The hardware locking feature is functional, return the original value
163                          * and return success.
164                          */
165                         XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
166                                           ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
167
168                         Status = XST_SUCCESS;
169                 }
170         }
171         return Status;
172 }
173 /** @} */