]> git.sur5r.net Git - freertos/blob
19499f7c5b33e404a6548723db1e165b8bd8db31
[freertos] /
1 //////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2004-11 Xilinx, Inc.  All rights reserved.
4 // Xilinx, Inc.
5 //
6 // XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
7 // COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
8 // ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
9 // STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
10 // IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
11 // FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
12 // XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
13 // THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
14 // ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
15 // FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
16 // AND FITNESS FOR A PARTICULAR PURPOSE.
17 //
18 // $Id: _profile_timer_hw.h,v 1.1.2.2 2011/05/30 06:46:18 svemula Exp $
19 //
20 // _program_timer_hw.h:
21 //      Timer related functions
22 //
23 //////////////////////////////////////////////////////////////////////
24
25 #ifndef _PROFILE_TIMER_HW_H
26 #define _PROFILE_TIMER_HW_H
27
28 #include "profile.h"
29
30 #ifdef PROC_PPC
31 #if defined __GNUC__
32 #  define SYNCHRONIZE_IO __asm__ volatile ("eieio")
33 #elif defined __DCC__
34 #  define SYNCHRONIZE_IO __asm volatile(" eieio")
35 #else
36 #  define SYNCHRONIZE_IO
37 #endif
38 #endif
39
40 #ifdef PROC_PPC
41 #define ProfIo_In32(InputPtr) (*(volatile u32 *)(InputPtr)); SYNCHRONIZE_IO;
42 #define ProfIo_Out32(OutputPtr, Value) { (*(volatile u32 *)(OutputPtr) = Value); SYNCHRONIZE_IO; }
43 #else
44 #define ProfIo_In32(InputPtr) (*(volatile u32 *)(InputPtr));
45 #define ProfIo_Out32(OutputPtr, Value) { (*(volatile u32 *)(OutputPtr) = Value); }
46 #endif
47
48 #define ProfTmrCtr_mWriteReg(BaseAddress, TmrCtrNumber, RegOffset, ValueToWrite)\
49         ProfIo_Out32(((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + \
50                            (RegOffset)), (ValueToWrite))
51
52 #define ProfTimerCtr_mReadReg(BaseAddress, TmrCtrNumber, RegOffset)     \
53         ProfIo_In32((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + (RegOffset))
54
55 #define ProfTmrCtr_mSetControlStatusReg(BaseAddress, TmrCtrNumber, RegisterValue)\
56         ProfTmrCtr_mWriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET,     \
57                                            (RegisterValue))
58
59 #define ProfTmrCtr_mGetControlStatusReg(BaseAddress, TmrCtrNumber)              \
60         ProfTimerCtr_mReadReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET)
61
62
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 #ifdef PROC_PPC
69 #include "xexception_l.h"
70 #include "xtime_l.h"
71 #include "xpseudo_asm.h"
72 #endif
73
74 #ifdef TIMER_CONNECT_INTC
75 #include "xintc_l.h"
76 #include "xintc.h"
77 #endif  // TIMER_CONNECT_INTC
78
79 #if (!defined PPC_PIT_INTERRUPT && !defined PROC_CORTEXA9)
80 #include "xtmrctr_l.h"
81 #endif
82
83 #ifdef PROC_CORTEXA9
84 #include "xscutimer_hw.h"
85 #include "xscugic.h"
86 #endif
87
88 extern unsigned int timer_clk_ticks ;
89
90 //--------------------------------------------------------------------
91 // PowerPC Target - Timer related functions
92 //--------------------------------------------------------------------
93 #ifdef PROC_PPC
94
95 #ifdef PPC_PIT_INTERRUPT
96 unsigned long timer_lo_clk_ticks ;      // Clk ticks when Timer is disabled in CG
97 #endif
98
99 #ifdef PROC_PPC440
100 #define XREG_TCR_PIT_INTERRUPT_ENABLE XREG_TCR_DEC_INTERRUPT_ENABLE
101 #define XREG_TSR_PIT_INTERRUPT_STATUS XREG_TSR_DEC_INTERRUPT_STATUS
102 #define XREG_SPR_PIT XREG_SPR_DEC
103 #define XEXC_ID_PIT_INT XEXC_ID_DEC_INT
104 #endif
105
106 //--------------------------------------------------------------------
107 // Disable the Timer - During Profiling
108 //
109 // For PIT Timer -
110 //      1. XTime_PITDisableInterrupt() ;
111 //      2. Store the remaining timer clk tick
112 //      3. Stop the PIT Timer
113 //--------------------------------------------------------------------
114
115 #ifdef PPC_PIT_INTERRUPT
116 #define disable_timer()                 \
117         {                               \
118                 unsigned long val;      \
119                 val=mfspr(XREG_SPR_TCR);        \
120                 mtspr(XREG_SPR_TCR, val & ~XREG_TCR_PIT_INTERRUPT_ENABLE);      \
121                 timer_lo_clk_ticks = mfspr(XREG_SPR_PIT);                       \
122                 mtspr(XREG_SPR_PIT, 0); \
123         }
124 #else
125 #define disable_timer()         \
126    { \
127       u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
128       u32 tmp_v = ProfIo_In32(addr); \
129       tmp_v = tmp_v & ~XTC_CSR_ENABLE_TMR_MASK; \
130       ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
131    }
132 #endif
133
134
135
136 //--------------------------------------------------------------------
137 // Enable the Timer
138 //
139 // For PIT Timer -
140 //      1. Load the remaining timer clk ticks
141 //      2. XTime_PITEnableInterrupt() ;
142 //--------------------------------------------------------------------
143 #ifdef PPC_PIT_INTERRUPT
144 #define enable_timer()                          \
145         {                                       \
146                 unsigned long val;              \
147                 val=mfspr(XREG_SPR_TCR);        \
148                 mtspr(XREG_SPR_PIT, timer_lo_clk_ticks);        \
149                 mtspr(XREG_SPR_TCR, val | XREG_TCR_PIT_INTERRUPT_ENABLE); \
150         }
151 #else
152 #define enable_timer()                                          \
153         {                                                       \
154       u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
155       u32 tmp_v = ProfIo_In32(addr); \
156       tmp_v = tmp_v |  XTC_CSR_ENABLE_TMR_MASK; \
157       ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
158         }
159 #endif
160
161
162
163 //--------------------------------------------------------------------
164 // Send Ack to Timer Interrupt
165 //
166 // For PIT Timer -
167 //      1. Load the timer clk ticks
168 //      2. Enable AutoReload and Interrupt
169 //      3. Clear PIT Timer Status bits
170 //--------------------------------------------------------------------
171 #ifdef PPC_PIT_INTERRUPT
172 #define timer_ack()                                                     \
173         {                                                               \
174                 unsigned long val;                                      \
175                 mtspr(XREG_SPR_PIT, timer_clk_ticks);                   \
176                 mtspr(XREG_SPR_TSR, XREG_TSR_PIT_INTERRUPT_STATUS);     \
177                 val=mfspr(XREG_SPR_TCR);                                \
178                 mtspr(XREG_SPR_TCR, val| XREG_TCR_PIT_INTERRUPT_ENABLE| XREG_TCR_AUTORELOAD_ENABLE); \
179         }
180 #else
181 #define timer_ack()                             \
182         {                                               \
183                 unsigned int csr;                       \
184                 csr = ProfTmrCtr_mGetControlStatusReg(PROFILE_TIMER_BASEADDR, 0);       \
185                 ProfTmrCtr_mSetControlStatusReg(PROFILE_TIMER_BASEADDR, 0, csr);        \
186         }
187 #endif
188
189 //--------------------------------------------------------------------
190 #endif  // PROC_PPC
191 //--------------------------------------------------------------------
192
193
194
195
196 //--------------------------------------------------------------------
197 // MicroBlaze Target - Timer related functions
198 //--------------------------------------------------------------------
199 #ifdef PROC_MICROBLAZE
200
201 //--------------------------------------------------------------------
202 // Disable the Timer during Call-Graph Data collection
203 //
204 //--------------------------------------------------------------------
205 #define disable_timer()                                 \
206         {                                               \
207       u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
208       u32 tmp_v = ProfIo_In32(addr); \
209       tmp_v = tmp_v & ~XTC_CSR_ENABLE_TMR_MASK; \
210       ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
211     }
212
213
214 //--------------------------------------------------------------------
215 // Enable the Timer after Call-Graph Data collection
216 //
217 //--------------------------------------------------------------------
218 #define enable_timer()                                  \
219         {                                               \
220       u32 addr = (PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET; \
221       u32 tmp_v = ProfIo_In32(addr); \
222       tmp_v = tmp_v |  XTC_CSR_ENABLE_TMR_MASK; \
223       ProfIo_Out32((PROFILE_TIMER_BASEADDR) + XTmrCtr_Offsets[(0)] + XTC_TCSR_OFFSET, tmp_v); \
224         }
225
226
227 //--------------------------------------------------------------------
228 // Send Ack to Timer Interrupt
229 //
230 //--------------------------------------------------------------------
231 #define timer_ack()                             \
232         {                                               \
233                 unsigned int csr;                       \
234                 csr = ProfTmrCtr_mGetControlStatusReg(PROFILE_TIMER_BASEADDR, 0);       \
235                 ProfTmrCtr_mSetControlStatusReg(PROFILE_TIMER_BASEADDR, 0, csr);        \
236         }
237
238 //--------------------------------------------------------------------
239 #endif  // PROC_MICROBLAZE
240 //--------------------------------------------------------------------
241
242 //--------------------------------------------------------------------
243 // Cortex A9 Target - Timer related functions
244 //--------------------------------------------------------------------
245 #ifdef PROC_CORTEXA9
246
247 //--------------------------------------------------------------------
248 // Disable the Timer during Call-Graph Data collection
249 //
250 //--------------------------------------------------------------------
251 #define disable_timer()                                                 \
252 {                                                               \
253         u32 Reg;                                                        \
254         Reg = Xil_In32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET); \
255         Reg &= ~XSCUTIMER_CONTROL_ENABLE_MASK;\
256         Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET, Reg);\
257 }                                                               \
258
259
260 //--------------------------------------------------------------------
261 // Enable the Timer after Call-Graph Data collection
262 //
263 //--------------------------------------------------------------------
264 #define enable_timer()                                                  \
265 {                                                               \
266         u32 Reg;                                                        \
267         Reg = Xil_In32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET); \
268         Reg |= XSCUTIMER_CONTROL_ENABLE_MASK; \
269         Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_CONTROL_OFFSET, Reg);\
270 }                                                               \
271
272
273 //--------------------------------------------------------------------
274 // Send Ack to Timer Interrupt
275 //
276 //--------------------------------------------------------------------
277 #define timer_ack()                                             \
278 {                                                       \
279         Xil_Out32(PROFILE_TIMER_BASEADDR + XSCUTIMER_ISR_OFFSET, \
280                 XSCUTIMER_ISR_EVENT_FLAG_MASK);\
281 }
282
283 //--------------------------------------------------------------------
284 #endif  // PROC_CORTEXA9
285 //--------------------------------------------------------------------
286
287
288 #ifdef __cplusplus
289 }
290 #endif
291
292 #endif