1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /****************************************************************************/
35 * @file xwdtps_selftest.c
36 * @addtogroup wdtps_v3_0
39 * Contains diagnostic self-test functions for the XWdtPs driver.
42 * MODIFICATION HISTORY:
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
49 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
52 ******************************************************************************/
54 /***************************** Include Files *********************************/
56 #include "xil_types.h"
57 #include "xil_assert.h"
60 /************************** Constant Definitions *****************************/
63 /**************************** Type Definitions *******************************/
66 /***************** Macros (Inline Functions) Definitions *********************/
69 /************************** Function Prototypes ******************************/
72 /************************** Variable Definitions *****************************/
75 /****************************************************************************/
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
83 * @param InstancePtr is a pointer to the XWdtPs instance.
86 * - XST_SUCCESS if self-test was successful.
87 * - XST_FAILURE if self-test was not successful.
91 ******************************************************************************/
92 s32 XWdtPs_SelfTest(XWdtPs *InstancePtr)
100 * Assert to ensure the inputs are valid and the instance has been
103 Xil_AssertNonvoid(InstancePtr != NULL);
104 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
107 * Read the ZMR register at start the test.
109 ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
113 * EX-OR in the length of the interrupt pulse,
114 * do not set the key value.
116 ZmrValue1 = ZmrOrig ^ (u32)XWDTPS_ZMR_RSTLN_MASK;
120 * Try to write to register w/o key value then read back.
122 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
125 ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
128 if (ZmrValue1 == ZmrValue2) {
130 * If the values match, the hw failed the test,
131 * return orig register value.
133 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
135 (ZmrOrig | (u32)XWDTPS_ZMR_ZKEY_VAL));
136 Status = XST_FAILURE;
141 * Try to write to register with key value then read back.
143 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
144 (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL));
146 ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
149 if (ZmrValue1 != ZmrValue2) {
151 * If the values do not match, the hw failed the test,
152 * return orig register value.
154 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
156 ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
157 Status = XST_FAILURE;
162 * The hardware locking feature is functional, return the original value
163 * and return success.
165 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
166 ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
168 Status = XST_SUCCESS;