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
37 * Contains diagnostic self-test functions for the XWdtPs driver.
40 * MODIFICATION HISTORY:
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
47 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
50 ******************************************************************************/
52 /***************************** Include Files *********************************/
54 #include "xil_types.h"
55 #include "xil_assert.h"
58 /************************** Constant Definitions *****************************/
61 /**************************** Type Definitions *******************************/
64 /***************** Macros (Inline Functions) Definitions *********************/
67 /************************** Function Prototypes ******************************/
70 /************************** Variable Definitions *****************************/
73 /****************************************************************************/
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
81 * @param InstancePtr is a pointer to the XWdtPs instance.
84 * - XST_SUCCESS if self-test was successful.
85 * - XST_FAILURE if self-test was not successful.
89 ******************************************************************************/
90 s32 XWdtPs_SelfTest(XWdtPs *InstancePtr)
98 * Assert to ensure the inputs are valid and the instance has been
101 Xil_AssertNonvoid(InstancePtr != NULL);
102 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
105 * Read the ZMR register at start the test.
107 ZmrOrig = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
111 * EX-OR in the length of the interrupt pulse,
112 * do not set the key value.
114 ZmrValue1 = ZmrOrig ^ (u32)XWDTPS_ZMR_RSTLN_MASK;
118 * Try to write to register w/o key value then read back.
120 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
123 ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
126 if (ZmrValue1 == ZmrValue2) {
128 * If the values match, the hw failed the test,
129 * return orig register value.
131 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
133 (ZmrOrig | (u32)XWDTPS_ZMR_ZKEY_VAL));
134 Status = XST_FAILURE;
139 * Try to write to register with key value then read back.
141 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
142 (ZmrValue1 | XWDTPS_ZMR_ZKEY_VAL));
144 ZmrValue2 = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
147 if (ZmrValue1 != ZmrValue2) {
149 * If the values do not match, the hw failed the test,
150 * return orig register value.
152 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress,
154 ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
155 Status = XST_FAILURE;
160 * The hardware locking feature is functional, return the original value
161 * and return success.
163 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
164 ZmrOrig | XWDTPS_ZMR_ZKEY_VAL);
166 Status = XST_SUCCESS;