1 /******************************************************************************
3 * Copyright (C) 2010 - 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 /****************************************************************************/
36 * @addtogroup scutimer_v2_0
40 * The timer driver supports the Cortex A9 private timer.
42 * The timer driver supports the following features:
43 * - Normal mode and Auto reload mode
44 * - Interrupts (Interrupt handler is not provided in this driver. Application
45 * has to register it's own handler)
47 * <b> Initialization and Configuration </b>
49 * The device driver enables higher layer software (e.g., an application) to
50 * communicate with the Timer.
52 * XScuTimer_CfgInitialize() API is used to initialize the Timer. The
53 * user needs to first call the XScuTimer_LookupConfig() API which returns
54 * the Configuration structure pointer which is passed as a parameter to
55 * the XScuTimer_CfgInitialize() API.
59 * The Timer hardware supports interrupts.
61 * This driver does not provide a Interrupt Service Routine (ISR) for the device.
62 * It is the responsibility of the application to provide one if needed. Refer to
63 * the interrupt example provided with this driver for details on using the
64 * Timer in interrupt mode.
66 * <b> Virtual Memory </b>
68 * This driver supports Virtual Memory. The RTOS is responsible for calculating
69 * the correct device base address in Virtual Memory space.
73 * This driver is not thread safe. Any needs for threads or thread mutual
74 * exclusion must be satisfied by the layer above this driver.
78 * Asserts are used within all Xilinx drivers to enforce constraints on argument
79 * values. Asserts can be turned off on a system-wide basis by defining, at
80 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
81 * is recommended that users leave asserts on during development.
83 * <b> Building the driver </b>
85 * The XScuTimer driver is composed of several source files. This allows the user
86 * to build and link only those parts of the driver that are necessary.
91 * The timer is not a part of the snoop control unit as indicated by the
92 * prefix "scu" in the name of the driver.
93 * It is an independent module in APU.
96 * MODIFICATION HISTORY:
98 * Ver Who Date Changes
99 * ----- --- -------- ---------------------------------------------
100 * 1.00a nm 03/10/10 First release
101 * 1.02a sg 07/17/12 Included xil_assert.h for CR 667947. This is an issue
102 * when the xstatus.h in the common driver overwrites
103 * the xstatus.h of the standalone BSP during the
107 ******************************************************************************/
108 #ifndef XSCUTIMER_H /* prevent circular inclusions */
109 #define XSCUTIMER_H /* by using protection macros */
111 /***************************** Include Files *********************************/
114 #include "xscutimer_hw.h"
120 /************************** Constant Definitions *****************************/
122 /**************************** Type Definitions *******************************/
125 * This typedef contains configuration information for the device.
128 u16 DeviceId; /**< Unique ID of device */
129 u32 BaseAddr; /**< Base address of the device */
133 * The XScuTimer driver instance data. The user is required to allocate a
134 * variable of this type for every timer device in the system.
135 * A pointer to a variable of this type is then passed to the driver API
139 XScuTimer_Config Config; /**< Hardware Configuration */
140 u32 IsReady; /**< Device is initialized and ready */
141 u32 IsStarted; /**< Device timer is running */
144 /***************** Macros (Inline Functions) Definitions *********************/
146 /****************************************************************************/
149 * Check if the timer has expired.
151 * @param InstancePtr is a pointer to the XScuTimer instance.
154 * - TRUE if the timer has expired.
155 * - FALSE if the timer has not expired.
157 * @note C-style signature:
158 * int XScuTimer_IsExpired(XScuTimer *InstancePtr)
160 ******************************************************************************/
161 #define XScuTimer_IsExpired(InstancePtr) \
162 ((XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
163 XSCUTIMER_ISR_OFFSET) & \
164 XSCUTIMER_ISR_EVENT_FLAG_MASK) == \
165 XSCUTIMER_ISR_EVENT_FLAG_MASK)
167 /****************************************************************************/
170 * Re-start the timer. This macro will read the timer load register
171 * and writes the same value to load register to update the counter register.
173 * @param InstancePtr is a pointer to the XScuTimer instance.
177 * @note C-style signature:
178 * void XScuTimer_RestartTimer(XScuTimer *InstancePtr)
180 ******************************************************************************/
181 #define XScuTimer_RestartTimer(InstancePtr) \
182 XScuTimer_LoadTimer(InstancePtr, \
183 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
184 XSCUTIMER_LOAD_OFFSET))
186 /****************************************************************************/
189 * Write to the timer load register. This will also update the
190 * timer counter register with the new value. This macro can be used to
191 * change the time-out value.
193 * @param InstancePtr is a pointer to the XScuTimer instance.
194 * @param Value is the count to be loaded in to the load register.
198 * @note C-style signature:
199 * void XScuTimer_LoadTimer(XScuTimer *InstancePtr, u32 Value)
201 ******************************************************************************/
202 #define XScuTimer_LoadTimer(InstancePtr, Value) \
203 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
204 XSCUTIMER_LOAD_OFFSET, Value)
206 /****************************************************************************/
209 * Returns the current timer counter register value. It can be called at any
212 * @param InstancePtr is a pointer to the XScuTimer instance.
214 * @return Contents of the timer counter register.
216 * @note C-style signature:
217 u32 XScuTimer_GetCounterValue(XScuTimer *InstancePtr)
219 ******************************************************************************/
220 #define XScuTimer_GetCounterValue(InstancePtr) \
221 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
222 XSCUTIMER_COUNTER_OFFSET)
224 /****************************************************************************/
227 * Enable auto-reload mode.
229 * @param InstancePtr is a pointer to the XScuTimer instance.
233 * @note C-style signature:
234 * void XScuTimer_EnableAutoReload(XScuTimer *InstancePtr)
236 ******************************************************************************/
237 #define XScuTimer_EnableAutoReload(InstancePtr) \
238 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
239 XSCUTIMER_CONTROL_OFFSET, \
240 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
241 XSCUTIMER_CONTROL_OFFSET) | \
242 XSCUTIMER_CONTROL_AUTO_RELOAD_MASK))
244 /****************************************************************************/
247 * Disable auto-reload mode.
249 * @param InstancePtr is a pointer to the XScuTimer instance.
253 * @note C-style signature:
254 * void XScuTimer_DisableAutoReload(XScuTimer *InstancePtr)
256 ******************************************************************************/
257 #define XScuTimer_DisableAutoReload(InstancePtr) \
258 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
259 XSCUTIMER_CONTROL_OFFSET, \
260 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
261 XSCUTIMER_CONTROL_OFFSET) & \
262 ~(XSCUTIMER_CONTROL_AUTO_RELOAD_MASK)))
264 /****************************************************************************/
267 * Enable the Timer interrupt.
269 * @param InstancePtr is a pointer to the XScuTimer instance.
273 * @note C-style signature:
274 * void XScuTimer_EnableInterrupt(XScuTimer *InstancePtr)
276 ******************************************************************************/
277 #define XScuTimer_EnableInterrupt(InstancePtr) \
278 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
279 XSCUTIMER_CONTROL_OFFSET, \
280 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
281 XSCUTIMER_CONTROL_OFFSET) | \
282 XSCUTIMER_CONTROL_IRQ_ENABLE_MASK))
284 /****************************************************************************/
287 * Disable the Timer interrupt.
289 * @param InstancePtr is a pointer to the XScuTimer instance.
293 * @note C-style signature:
294 * void XScuTimer_DisableInterrupt(XScuTimer *InstancePtr)
296 ******************************************************************************/
297 #define XScuTimer_DisableInterrupt(InstancePtr) \
298 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
299 XSCUTIMER_CONTROL_OFFSET, \
300 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
301 XSCUTIMER_CONTROL_OFFSET) & \
302 ~(XSCUTIMER_CONTROL_IRQ_ENABLE_MASK)))
304 /*****************************************************************************/
307 * This function reads the interrupt status.
309 * @param InstancePtr is a pointer to the XScuTimer instance.
313 * @note C-style signature:
314 * void XScuTimer_GetInterruptStatus(XScuTimer *InstancePtr)
316 ******************************************************************************/
317 #define XScuTimer_GetInterruptStatus(InstancePtr) \
318 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
319 XSCUTIMER_ISR_OFFSET)
321 /*****************************************************************************/
324 * This function clears the interrupt status.
326 * @param InstancePtr is a pointer to the XScuTimer instance.
330 * @note C-style signature:
331 * void XScuTimer_ClearInterruptStatus(XScuTimer *InstancePtr)
333 ******************************************************************************/
334 #define XScuTimer_ClearInterruptStatus(InstancePtr) \
335 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
336 XSCUTIMER_ISR_OFFSET, XSCUTIMER_ISR_EVENT_FLAG_MASK)
338 /************************** Function Prototypes ******************************/
341 * Lookup configuration in xscutimer_sinit.c
343 XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId);
346 * Selftest function in xscutimer_selftest.c
348 int XScuTimer_SelfTest(XScuTimer *InstancePtr);
351 * Interface functions in xscutimer.c
353 int XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
354 XScuTimer_Config *ConfigPtr, u32 EffectiveAddress);
355 void XScuTimer_Start(XScuTimer *InstancePtr);
356 void XScuTimer_Stop(XScuTimer *InstancePtr);
357 void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue);
358 u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr);
364 #endif /* end of protection macro */