]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/axipmon_v6_4/src/xaxipmon_selftest.c
Update the Xilinx UltraScale+ 64-bit demo to use the hardware definition and BSP...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / axipmon_v6_4 / src / xaxipmon_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 - 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 xaxipmon_selftest.c
36 * @addtogroup axipmon_v6_3
37 * @{
38 *
39 * This file contains a diagnostic self test function for the XAxiPmon driver.
40 * The self test function does a simple read/write test of the Alarm Threshold
41 * Register.
42 *
43 * See XAxiPmon.h for more information.
44 *
45 * @note None.
46 *
47 * <pre>
48 *
49 * MODIFICATION HISTORY:
50 *
51 * Ver   Who    Date     Changes
52 * ----- -----  -------- -----------------------------------------------------
53 * 1.00a bss  02/24/12 First release
54 * 2.00a bss  06/23/12 Updated to support v2_00a version of IP.
55 * 6.3   kvn  07/02/15 Modified code according to MISRA-C:2012 guidelines.
56 * </pre>
57 *
58 *****************************************************************************/
59
60 /***************************** Include Files ********************************/
61
62 #include "xaxipmon.h"
63
64 /************************** Constant Definitions ****************************/
65
66 /*
67  * The following constant defines the test value to be written
68  * to the Range Registers of Incrementers
69  */
70
71 #define XAPM_TEST_RANGEUPPER_VALUE      16U /**< Test Value for Upper Range */
72 #define XAPM_TEST_RANGELOWER_VALUE       8U /**< Test Value for Lower Range */
73
74 /**************************** Type Definitions ******************************/
75
76 /***************** Macros (Inline Functions) Definitions ********************/
77
78 /************************** Variable Definitions ****************************/
79
80 /************************** Function Prototypes *****************************/
81
82 /*****************************************************************************/
83 /**
84 *
85 * Run a self-test on the driver/device. The test
86 *       - Resets the device,
87 *       - Writes a value into the Range Registers of Incrementer 0 and reads
88 *         it back for comparison.
89 *       - Resets the device again.
90 *
91 *
92 * @param        InstancePtr is a pointer to the XAxiPmon instance.
93 *
94 * @return
95 *               - XST_SUCCESS if the value read from the Range Register of
96 *                 Incrementer 0 is the same as the value written.
97 *               - XST_FAILURE Otherwise
98 *
99 * @note         This is a destructive test in that resets of the device are
100 *               performed. Refer to the device specification for the
101 *               device status after the reset operation.
102 *
103 ******************************************************************************/
104 s32 XAxiPmon_SelfTest(XAxiPmon *InstancePtr)
105 {
106         s32 Status;
107         u16 RangeUpper = 0U;
108         u16 RangeLower = 0U;
109
110         /*
111          * Assert the argument
112          */
113         Xil_AssertNonvoid(InstancePtr != NULL);
114         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
115
116
117         /*
118          * Reset the device to get it back to its default state
119          */
120         (void)XAxiPmon_ResetMetricCounter(InstancePtr);
121         XAxiPmon_ResetGlobalClkCounter(InstancePtr);
122
123         /*
124          * Write a value into the Incrementer register and
125          * read it back, and do the comparison
126          */
127         XAxiPmon_SetIncrementerRange(InstancePtr, XAPM_INCREMENTER_0,
128                                         XAPM_TEST_RANGEUPPER_VALUE,
129                                         XAPM_TEST_RANGELOWER_VALUE);
130
131         XAxiPmon_GetIncrementerRange(InstancePtr, XAPM_INCREMENTER_0,
132                                         &RangeUpper, &RangeLower);
133
134         if ((RangeUpper == XAPM_TEST_RANGEUPPER_VALUE) &&
135                         (RangeLower == XAPM_TEST_RANGELOWER_VALUE)) {
136                 Status = XST_SUCCESS;
137         } else {
138                 Status = XST_FAILURE;
139         }
140
141         /*
142          * Reset the device again to its default state.
143          */
144         (void)XAxiPmon_ResetMetricCounter(InstancePtr);
145         XAxiPmon_ResetGlobalClkCounter(InstancePtr);
146
147         /*
148          * Return the test result.
149          */
150         return Status;
151 }
152 /** @} */