]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v6_6/src/xl2cc_counter.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v6_6 / src / xl2cc_counter.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2011 - 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 xl2cc_counter.c
36 *
37 * This file contains APIs for configuring and controlling the event counters
38 * in PL310 L2 cache controller. For more information about the event counters,
39 * see xl2cc_counter.h.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who  Date     Changes
45 * ----- ---- -------- -----------------------------------------------
46 * 1.00a sdm  07/11/11 First release
47 * 3.07a asa  08/30/12 Updated for CR 675636 to provide the L2 Base Address
48 *                     inside the APIs
49 * </pre>
50 *
51 ******************************************************************************/
52
53 /***************************** Include Files *********************************/
54
55 #include <stdint.h>
56 #include "xparameters_ps.h"
57 #include "xl2cc_counter.h"
58 #include "xl2cc.h"
59
60 /************************** Constant Definitions ****************************/
61
62 /**************************** Type Definitions ******************************/
63
64 /***************** Macros (Inline Functions) Definitions ********************/
65
66 /************************** Variable Definitions *****************************/
67
68 /************************** Function Prototypes ******************************/
69
70 void XL2cc_EventCtrReset(void);
71
72 /******************************************************************************/
73
74 /****************************************************************************/
75 /**
76 *
77 * @brief        This function initializes the event counters in L2 Cache controller
78 *                       with a set of event codes specified by the user.
79 *
80 * @param        Event0: Event code for counter 0.
81 * @param        Event1: Event code for counter 1.
82 *
83 * @return       None.
84 *
85 * @note         The definitions for event codes XL2CC_* can be found in
86 *                       xl2cc_counter.h.
87 *
88 *****************************************************************************/
89 void XL2cc_EventCtrInit(s32 Event0, s32 Event1)
90 {
91
92         /* Write event code into cnt1 cfg reg */
93         *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT1_CTRL_OFFSET)) = (((u32)Event1) << 2);
94
95         /* Write event code into cnt0 cfg reg */
96         *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT0_CTRL_OFFSET)) = (((u32)Event0) << 2);
97
98         /* Reset counters */
99         XL2cc_EventCtrReset();
100 }
101
102
103 /****************************************************************************/
104 /**
105 *
106 * @brief        This function starts the event counters in L2 Cache controller.
107 *
108 * @param        None.
109 *
110 * @return       None.
111 *
112 * @note         None.
113 *
114 *****************************************************************************/
115 void XL2cc_EventCtrStart(void)
116 {
117         u32 *LocalPtr;
118         LocalPtr = (u32 *)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET);
119         XL2cc_EventCtrReset();
120
121         /* Enable counter */
122         /* *((volatile u32*)((void *)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET))) = 1 */
123         *LocalPtr = (u32)1;
124 }
125
126 /****************************************************************************/
127 /**
128 *
129 * @brief        This function disables the event counters in L2 Cache controller,
130 *                       saves the counter values and resets the counters.
131 *
132 * @param        EveCtr0: Output parameter which is used to return the value
133 *                       in event counter 0.
134 *                       EveCtr1: Output parameter which is used to return the value
135 *                       in event counter 1.
136 *
137 * @return       None.
138 *
139 * @note         None.
140 *
141 *****************************************************************************/
142 void XL2cc_EventCtrStop(u32 *EveCtr0, u32 *EveCtr1)
143 {
144         /* Disable counter */
145         *((volatile u32*) (XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET)) = 0U;
146
147         /* Save counter values */
148         *EveCtr1 = *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT1_VAL_OFFSET));
149         *EveCtr0 = *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNT0_VAL_OFFSET));
150
151         XL2cc_EventCtrReset();
152 }
153
154 /****************************************************************************/
155 /**
156 *
157 * @brief        This function resets the event counters in L2 Cache controller.
158 *
159 * @param        None.
160 *
161 * @return       None.
162 *
163 * @note         None.
164 *
165 *****************************************************************************/
166 void XL2cc_EventCtrReset(void)
167 {
168         *((volatile u32*)(XPS_L2CC_BASEADDR + XPS_L2CC_EVNT_CNTRL_OFFSET)) = 0x6U;
169 }