1 /******************************************************************************
3 * Copyright (C) 2002 - 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 /*****************************************************************************/
37 * This header file contains identifiers and low-level driver functions (or
38 * macros) that can be used to access the device. The user should refer to the
39 * hardware device specification for more details of the device operation.
40 * High-level driver functions are defined in xtmrctr.h.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ---- -------- -----------------------------------------------
47 * 1.00b jhl 04/24/02 First release
48 * 1.10b mta 03/21/07 Updated to new coding style
49 * 2.00a ktn 10/30/09 Updated to use HAL API's. _m is removed from all the macro
51 * 2.01a ktn 07/12/10 Renamed the macro XTimerCtr_ReadReg as XTmrCtr_ReadReg
52 * for naming consistency (CR 559142).
53 * 2.04a sdm 07/12/11 Added the CASC mode bit in the TCSRO register for the
54 * cascade mode operation.
55 * The cascade mode of operation is present in the latest
56 * versions of the axi_timer IP. Please check the HW
57 * Datasheet to see whether this feature is present in the
58 * version of the IP that you are using.
61 ******************************************************************************/
63 #ifndef XTMRCTR_L_H /* prevent circular inclusions */
64 #define XTMRCTR_L_H /* by using protection macros */
70 /***************************** Include Files *********************************/
72 #include "xil_types.h"
75 /************************** Constant Definitions *****************************/
78 * Defines the number of timer counters within a single hardware device. This
79 * number is not currently parameterized in the hardware but may be in the
82 #define XTC_DEVICE_TIMER_COUNT 2
84 /* Each timer counter consumes 16 bytes of address space */
86 #define XTC_TIMER_COUNTER_OFFSET 16
88 /** @name Register Offset Definitions
89 * Register offsets within a timer counter, there are multiple
90 * timer counters within a single device
94 #define XTC_TCSR_OFFSET 0 /**< Control/Status register */
95 #define XTC_TLR_OFFSET 4 /**< Load register */
96 #define XTC_TCR_OFFSET 8 /**< Timer counter register */
100 /** @name Control Status Register Bit Definitions
101 * Control Status Register bit masks
102 * Used to configure the timer counter device.
106 #define XTC_CSR_CASC_MASK 0x00000800 /**< Cascade Mode */
107 #define XTC_CSR_ENABLE_ALL_MASK 0x00000400 /**< Enables all timer
109 #define XTC_CSR_ENABLE_PWM_MASK 0x00000200 /**< Enables the Pulse Width
111 #define XTC_CSR_INT_OCCURED_MASK 0x00000100 /**< If bit is set, an
112 interrupt has occured.
117 #define XTC_CSR_ENABLE_TMR_MASK 0x00000080 /**< Enables only the
119 #define XTC_CSR_ENABLE_INT_MASK 0x00000040 /**< Enables the interrupt
121 #define XTC_CSR_LOAD_MASK 0x00000020 /**< Loads the timer using
122 the load value provided
126 #define XTC_CSR_AUTO_RELOAD_MASK 0x00000010 /**< In compare mode,
132 causes the timer counter
133 to hold when the compare
134 value is hit. In capture
138 capture value if a new
140 default mode cause the
141 timer counter to hold
142 the capture value until
144 #define XTC_CSR_EXT_CAPTURE_MASK 0x00000008 /**< Enables the
146 to the timer counter. */
147 #define XTC_CSR_EXT_GENERATE_MASK 0x00000004 /**< Enables the
148 external generate output
150 #define XTC_CSR_DOWN_COUNT_MASK 0x00000002 /**< Configures the timer
151 counter to count down
152 from start value, the
155 #define XTC_CSR_CAPTURE_MODE_MASK 0x00000001 /**< Enables the timer to
157 counter value when the
158 external capture line is
159 asserted. The default
160 mode is compare mode.*/
163 /**************************** Type Definitions *******************************/
165 extern u8 XTmrCtr_Offsets[];
167 /***************** Macros (Inline Functions) Definitions *********************/
169 /*****************************************************************************/
171 * Read one of the timer counter registers.
173 * @param BaseAddress contains the base address of the timer counter
175 * @param TmrCtrNumber contains the specific timer counter within the
176 * device, a zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
177 * @param RegOffset contains the offset from the 1st register of the timer
178 * counter to select the specific register of the timer counter.
180 * @return The value read from the register, a 32 bit value.
182 * @note C-Style signature:
183 * u32 XTmrCtr_ReadReg(u32 BaseAddress, u8 TimerNumber,
185 ******************************************************************************/
186 #define XTmrCtr_ReadReg(BaseAddress, TmrCtrNumber, RegOffset) \
187 Xil_In32((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + \
190 #ifndef XTimerCtr_ReadReg
191 #define XTimerCtr_ReadReg XTmrCtr_ReadReg
194 /*****************************************************************************/
196 * Write a specified value to a register of a timer counter.
198 * @param BaseAddress is the base address of the timer counter device.
199 * @param TmrCtrNumber is the specific timer counter within the device, a
200 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
201 * @param RegOffset contain the offset from the 1st register of the timer
202 * counter to select the specific register of the timer counter.
203 * @param ValueToWrite is the 32 bit value to be written to the register.
205 * @note C-Style signature:
206 * void XTmrCtr_WriteReg(u32 BaseAddress, u8 TimerNumber,
207 * unsigned RegOffset, u32 ValueToWrite);
208 ******************************************************************************/
209 #define XTmrCtr_WriteReg(BaseAddress, TmrCtrNumber, RegOffset, ValueToWrite)\
210 Xil_Out32(((BaseAddress) + XTmrCtr_Offsets[(TmrCtrNumber)] + \
211 (RegOffset)), (ValueToWrite))
213 /****************************************************************************/
216 * Set the Control Status Register of a timer counter to the specified value.
218 * @param BaseAddress is the base address of the device.
219 * @param TmrCtrNumber is the specific timer counter within the device, a
220 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
221 * @param RegisterValue is the 32 bit value to be written to the register.
225 * @note C-Style signature:
226 * void XTmrCtr_SetControlStatusReg(u32 BaseAddress,
227 * u8 TmrCtrNumber,u32 RegisterValue);
228 *****************************************************************************/
229 #define XTmrCtr_SetControlStatusReg(BaseAddress, TmrCtrNumber, RegisterValue)\
230 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
233 /****************************************************************************/
236 * Get the Control Status Register of a timer counter.
238 * @param BaseAddress is the base address of the device.
239 * @param TmrCtrNumber is the specific timer counter within the device,
240 * a zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
242 * @return The value read from the register, a 32 bit value.
244 * @note C-Style signature:
245 * u32 XTmrCtr_GetControlStatusReg(u32 BaseAddress,
247 *****************************************************************************/
248 #define XTmrCtr_GetControlStatusReg(BaseAddress, TmrCtrNumber) \
249 XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET)
251 /****************************************************************************/
254 * Get the Timer Counter Register of a timer counter.
256 * @param BaseAddress is the base address of the device.
257 * @param TmrCtrNumber is the specific timer counter within the device,
258 * a zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
260 * @return The value read from the register, a 32 bit value.
262 * @note C-Style signature:
263 * u32 XTmrCtr_GetTimerCounterReg(u32 BaseAddress,
265 *****************************************************************************/
266 #define XTmrCtr_GetTimerCounterReg(BaseAddress, TmrCtrNumber) \
267 XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), XTC_TCR_OFFSET) \
269 /****************************************************************************/
272 * Set the Load Register of a timer counter to the specified value.
274 * @param BaseAddress is the base address of the device.
275 * @param TmrCtrNumber is the specific timer counter within the device, a
276 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
277 * @param RegisterValue is the 32 bit value to be written to the register.
281 * @note C-Style signature:
282 * void XTmrCtr_SetLoadReg(u32 BaseAddress, u8 TmrCtrNumber,
283 * u32 RegisterValue);
284 *****************************************************************************/
285 #define XTmrCtr_SetLoadReg(BaseAddress, TmrCtrNumber, RegisterValue) \
286 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TLR_OFFSET, \
289 /****************************************************************************/
292 * Get the Load Register of a timer counter.
294 * @param BaseAddress is the base address of the device.
295 * @param TmrCtrNumber is the specific timer counter within the device, a
296 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
298 * @return The value read from the register, a 32 bit value.
300 * @note C-Style signature:
301 * u32 XTmrCtr_GetLoadReg(u32 BaseAddress, u8 TmrCtrNumber);
302 *****************************************************************************/
303 #define XTmrCtr_GetLoadReg(BaseAddress, TmrCtrNumber) \
304 XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), XTC_TLR_OFFSET)
306 /****************************************************************************/
309 * Enable a timer counter such that it starts running.
311 * @param BaseAddress is the base address of the device.
312 * @param TmrCtrNumber is the specific timer counter within the device, a
313 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
317 * @note C-Style signature:
318 * void XTmrCtr_Enable(u32 BaseAddress, u8 TmrCtrNumber);
319 *****************************************************************************/
320 #define XTmrCtr_Enable(BaseAddress, TmrCtrNumber) \
321 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
322 (XTmrCtr_ReadReg((BaseAddress), ( TmrCtrNumber), \
323 XTC_TCSR_OFFSET) | XTC_CSR_ENABLE_TMR_MASK))
325 /****************************************************************************/
328 * Disable a timer counter such that it stops running.
330 * @param BaseAddress is the base address of the device.
331 * @param TmrCtrNumber is the specific timer counter within the device,
332 * a zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
336 * @note C-Style signature:
337 * void XTmrCtr_Disable(u32 BaseAddress, u8 TmrCtrNumber);
338 *****************************************************************************/
339 #define XTmrCtr_Disable(BaseAddress, TmrCtrNumber) \
340 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
341 (XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber),\
342 XTC_TCSR_OFFSET) & ~ XTC_CSR_ENABLE_TMR_MASK))
344 /****************************************************************************/
347 * Enable the interrupt for a timer counter.
349 * @param BaseAddress is the base address of the device.
350 * @param TmrCtrNumber is the specific timer counter within the device, a
351 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
355 * @note C-Style signature:
356 * void XTmrCtr_EnableIntr(u32 BaseAddress, u8 TmrCtrNumber);
357 *****************************************************************************/
358 #define XTmrCtr_EnableIntr(BaseAddress, TmrCtrNumber) \
359 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
360 (XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), \
361 XTC_TCSR_OFFSET) | XTC_CSR_ENABLE_INT_MASK))
363 /****************************************************************************/
366 * Disable the interrupt for a timer counter.
368 * @param BaseAddress is the base address of the device.
369 * @param TmrCtrNumber is the specific timer counter within the device, a
370 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
374 * @note C-Style signature:
375 * void XTmrCtr_DisableIntr(u32 BaseAddress, u8 TmrCtrNumber);
376 *****************************************************************************/
377 #define XTmrCtr_DisableIntr(BaseAddress, TmrCtrNumber) \
378 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
379 (XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), \
380 XTC_TCSR_OFFSET) & ~ XTC_CSR_ENABLE_INT_MASK))
382 /****************************************************************************/
385 * Cause the timer counter to load it's Timer Counter Register with the value
386 * in the Load Register.
388 * @param BaseAddress is the base address of the device.
389 * @param TmrCtrNumber is the specific timer counter within the device, a
390 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
394 * @note C-Style signature:
395 * void XTmrCtr_LoadTimerCounterReg(u32 BaseAddress,
397 *****************************************************************************/
398 #define XTmrCtr_LoadTimerCounterReg(BaseAddress, TmrCtrNumber) \
399 XTmrCtr_WriteReg((BaseAddress), (TmrCtrNumber), XTC_TCSR_OFFSET, \
400 (XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber),\
401 XTC_TCSR_OFFSET) | XTC_CSR_LOAD_MASK))
403 /****************************************************************************/
406 * Determine if a timer counter event has occurred. Events are defined to be
407 * when a capture has occurred or the counter has roller over.
409 * @param BaseAddress is the base address of the device.
410 * @param TmrCtrNumber is the specific timer counter within the device, a
411 * zero based number, 0 - (XTC_DEVICE_TIMER_COUNT - 1).
413 * @note C-Style signature:
414 * int XTmrCtr_HasEventOccurred(u32 BaseAddress, u8 TmrCtrNumber);
415 *****************************************************************************/
416 #define XTmrCtr_HasEventOccurred(BaseAddress, TmrCtrNumber) \
417 ((XTmrCtr_ReadReg((BaseAddress), (TmrCtrNumber), \
418 XTC_TCSR_OFFSET) & XTC_CSR_INT_OCCURED_MASK) == \
419 XTC_CSR_INT_OCCURED_MASK)
421 /************************** Function Prototypes ******************************/
422 /************************** Variable Definitions *****************************/
426 #endif /* end of protection macro */