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