1 // $Id: _profile_timer_hw.h,v 1.1.2.2 2011/05/30 06:46:18 svemula Exp $
2 /******************************************************************************
4 * Copyright (C) 2004 - 2014 Xilinx, Inc. All rights reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * Use of the Software is limited solely to applications:
17 * (a) running on a Xilinx device, or
18 * (b) that interact with a Xilinx device through a bus or interconnect.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * Except as contained in this notice, the name of the Xilinx shall not be used
29 * in advertising or otherwise to promote the sale, use or other dealings in
30 * this Software without prior written authorization from Xilinx.
32 ******************************************************************************
34 * _program_timer_hw.h:
35 * Timer related functions
37 ******************************************************************************/
39 #ifndef _PROFILE_TIMER_HW_H
40 #define _PROFILE_TIMER_HW_H
46 # define SYNCHRONIZE_IO __asm__ volatile ("eieio")
48 # define SYNCHRONIZE_IO __asm volatile(" eieio")
50 # define SYNCHRONIZE_IO
55 #define ProfIo_In32(InputPtr) (*(volatile u32 *)(InputPtr)); SYNCHRONIZE_IO;
56 #define ProfIo_Out32(OutputPtr, Value) { (*(volatile u32 *)(OutputPtr) = Value); SYNCHRONIZE_IO; }
58 #define ProfIo_In32(InputPtr) (*(volatile u32 *)(InputPtr));
59 #define ProfIo_Out32(OutputPtr, Value) { (*(volatile u32 *)(OutputPtr) = Value); }
62 #define ProfTmrCtr_mWriteReg(BaseAddress, TmrCtrNumber, RegOffset, ValueToWrite)\
63 ProfIo_Out32(((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + \
64 (RegOffset)), (ValueToWrite))
66 #define ProfTimerCtr_mReadReg(BaseAddress, TmrCtrNumber, RegOffset) \
67 ProfIo_In32((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + (RegOffset))
69 #define ProfTmrCtr_mSetControlStatusReg(BaseAddress, TmrCtrNumber, RegisterValue)\
70 ProfTmrCtr_mWriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
73 #define ProfTmrCtr_mGetControlStatusReg(BaseAddress, TmrCtrNumber) \
74 ProfTimerCtr_mReadReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET)
83 #include "xexception_l.h"
85 #include "xpseudo_asm.h"
88 #ifdef TIMER_CONNECT_INTC
91 #endif // TIMER_CONNECT_INTC
93 #if (!defined PPC_PIT_INTERRUPT && !defined PROC_CORTEXA9)
94 #include "xtmrctr_l.h"
98 #include "xscutimer_hw.h"
102 extern unsigned int timer_clk_ticks ;
104 //--------------------------------------------------------------------
105 // PowerPC Target - Timer related functions
106 //--------------------------------------------------------------------
109 #ifdef PPC_PIT_INTERRUPT
110 unsigned long timer_lo_clk_ticks ; // Clk ticks when Timer is disabled in CG
114 #define XREG_TCR_PIT_INTERRUPT_ENABLE XREG_TCR_DEC_INTERRUPT_ENABLE
115 #define XREG_TSR_PIT_INTERRUPT_STATUS XREG_TSR_DEC_INTERRUPT_STATUS
116 #define XREG_SPR_PIT XREG_SPR_DEC
117 #define XEXC_ID_PIT_INT XEXC_ID_DEC_INT
120 //--------------------------------------------------------------------
121 // Disable the Timer - During Profiling
124 // 1. XTime_PITDisableInterrupt() ;
125 // 2. Store the remaining timer clk tick
126 // 3. Stop the PIT Timer
127 //--------------------------------------------------------------------
129 #ifdef PPC_PIT_INTERRUPT
130 #define disable_timer() \
133 val=mfspr(XREG_SPR_TCR); \
134 mtspr(XREG_SPR_TCR, val & ~XREG_TCR_PIT_INTERRUPT_ENABLE); \
135 timer_lo_clk_ticks = mfspr(XREG_SPR_PIT); \
136 mtspr(XREG_SPR_PIT, 0); \
139 #define disable_timer() \
141 u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
142 u32 tmp_v = ProfIo_In32(addr); \
143 tmp_v = tmp_v & ~XTC_CSR_ENABLE_TMR_MASK; \
144 ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
150 //--------------------------------------------------------------------
154 // 1. Load the remaining timer clk ticks
155 // 2. XTime_PITEnableInterrupt() ;
156 //--------------------------------------------------------------------
157 #ifdef PPC_PIT_INTERRUPT
158 #define enable_timer() \
161 val=mfspr(XREG_SPR_TCR); \
162 mtspr(XREG_SPR_PIT, timer_lo_clk_ticks); \
163 mtspr(XREG_SPR_TCR, val | XREG_TCR_PIT_INTERRUPT_ENABLE); \
166 #define enable_timer() \
168 u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
169 u32 tmp_v = ProfIo_In32(addr); \
170 tmp_v = tmp_v | XTC_CSR_ENABLE_TMR_MASK; \
171 ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
177 //--------------------------------------------------------------------
178 // Send Ack to Timer Interrupt
181 // 1. Load the timer clk ticks
182 // 2. Enable AutoReload and Interrupt
183 // 3. Clear PIT Timer Status bits
184 //--------------------------------------------------------------------
185 #ifdef PPC_PIT_INTERRUPT
186 #define timer_ack() \
189 mtspr(XREG_SPR_PIT, timer_clk_ticks); \
190 mtspr(XREG_SPR_TSR, XREG_TSR_PIT_INTERRUPT_STATUS); \
191 val=mfspr(XREG_SPR_TCR); \
192 mtspr(XREG_SPR_TCR, val| XREG_TCR_PIT_INTERRUPT_ENABLE| XREG_TCR_AUTORELOAD_ENABLE); \
195 #define timer_ack() \
198 csr = ProfTmrCtr_mGetControlStatusReg(PROFILE_TIMER_BASEADDR, 0); \
199 ProfTmrCtr_mSetControlStatusReg(PROFILE_TIMER_BASEADDR, 0, csr); \
203 //--------------------------------------------------------------------
205 //--------------------------------------------------------------------
210 //--------------------------------------------------------------------
211 // MicroBlaze Target - Timer related functions
212 //--------------------------------------------------------------------
213 #ifdef PROC_MICROBLAZE
215 //--------------------------------------------------------------------
216 // Disable the Timer during Call-Graph Data collection
218 //--------------------------------------------------------------------
219 #define disable_timer() \
221 u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
222 u32 tmp_v = ProfIo_In32(addr); \
223 tmp_v = tmp_v & ~XTC_CSR_ENABLE_TMR_MASK; \
224 ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
228 //--------------------------------------------------------------------
229 // Enable the Timer after Call-Graph Data collection
231 //--------------------------------------------------------------------
232 #define enable_timer() \
234 u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
235 u32 tmp_v = ProfIo_In32(addr); \
236 tmp_v = tmp_v | XTC_CSR_ENABLE_TMR_MASK; \
237 ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
241 //--------------------------------------------------------------------
242 // Send Ack to Timer Interrupt
244 //--------------------------------------------------------------------
245 #define timer_ack() \
248 csr = ProfTmrCtr_mGetControlStatusReg(PROFILE_TIMER_BASEADDR, 0); \
249 ProfTmrCtr_mSetControlStatusReg(PROFILE_TIMER_BASEADDR, 0, csr); \
252 //--------------------------------------------------------------------
253 #endif // PROC_MICROBLAZE
254 //--------------------------------------------------------------------
256 //--------------------------------------------------------------------
257 // Cortex A9 Target - Timer related functions
258 //--------------------------------------------------------------------
261 //--------------------------------------------------------------------
262 // Disable the Timer during Call-Graph Data collection
264 //--------------------------------------------------------------------
265 #define disable_timer() \
268 Reg = Xil_In32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET); \
269 Reg &= ~XSCUTIMER_CONTROL_ENABLE_MASK;\
270 Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET, Reg);\
274 //--------------------------------------------------------------------
275 // Enable the Timer after Call-Graph Data collection
277 //--------------------------------------------------------------------
278 #define enable_timer() \
281 Reg = Xil_In32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET); \
282 Reg |= XSCUTIMER_CONTROL_ENABLE_MASK; \
283 Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET, Reg);\
287 //--------------------------------------------------------------------
288 // Send Ack to Timer Interrupt
290 //--------------------------------------------------------------------
291 #define timer_ack() \
293 Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_ISR_OFFSET, \
294 XSCUTIMER_ISR_EVENT_FLAG_MASK);\
297 //--------------------------------------------------------------------
298 #endif // PROC_CORTEXA9
299 //--------------------------------------------------------------------