1 /******************************************************************************
3 * Copyright (C) 2012 - 2014 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 xaxipmon_selftest.c
37 * This file contains a diagnostic self test function for the XAxiPmon driver.
38 * The self test function does a simple read/write test of the Alarm Threshold
41 * See XAxiPmon.h for more information.
47 * MODIFICATION HISTORY:
49 * Ver Who Date Changes
50 * ----- ----- -------- -----------------------------------------------------
51 * 1.00a bss 02/24/12 First release
52 * 2.00a bss 06/23/12 Updated to support v2_00a version of IP.
55 *****************************************************************************/
57 /***************************** Include Files ********************************/
61 /************************** Constant Definitions ****************************/
64 * The following constant defines the test value to be written
65 * to the Range Registers of Incrementers
68 #define XAPM_TEST_RANGEUPPER_VALUE 16 /**< Test Value for Upper Range */
69 #define XAPM_TEST_RANGELOWER_VALUE 8 /**< Test Value for Lower Range */
71 /**************************** Type Definitions ******************************/
73 /***************** Macros (Inline Functions) Definitions ********************/
75 /************************** Variable Definitions ****************************/
77 /************************** Function Prototypes *****************************/
79 /*****************************************************************************/
82 * Run a self-test on the driver/device. The test
83 * - Resets the device,
84 * - Writes a value into the Range Registers of Incrementer 0 and reads
85 * it back for comparison.
86 * - Resets the device again.
89 * @param InstancePtr is a pointer to the XAxiPmon instance.
92 * - XST_SUCCESS if the value read from the Range Register of
93 * Incrementer 0 is the same as the value written.
94 * - XST_FAILURE Otherwise
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.
100 ******************************************************************************/
101 int XAxiPmon_SelfTest(XAxiPmon *InstancePtr)
108 * Assert the argument
110 Xil_AssertNonvoid(InstancePtr != NULL);
111 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
115 * Reset the device to get it back to its default state
117 XAxiPmon_ResetMetricCounter(InstancePtr);
118 XAxiPmon_ResetGlobalClkCounter(InstancePtr);
121 * Write a value into the Incrementer register and
122 * read it back, and do the comparison
124 XAxiPmon_SetIncrementerRange(InstancePtr, XAPM_INCREMENTER_0,
125 XAPM_TEST_RANGEUPPER_VALUE,
126 XAPM_TEST_RANGELOWER_VALUE);
128 XAxiPmon_GetIncrementerRange(InstancePtr, XAPM_INCREMENTER_0,
129 &RangeUpper, &RangeLower);
131 if ((RangeUpper == XAPM_TEST_RANGEUPPER_VALUE) &&
132 (RangeLower == XAPM_TEST_RANGELOWER_VALUE)) {
133 Status = XST_SUCCESS;
135 Status = XST_FAILURE;
139 * Reset the device again to its default state.
141 XAxiPmon_ResetMetricCounter(InstancePtr);
142 XAxiPmon_ResetGlobalClkCounter(InstancePtr);
145 * Return the test result.