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 /****************************************************************************/
37 * The timer driver supports the Cortex A9 private timer.
39 * The timer driver supports the following features:
40 * - Normal mode and Auto reload mode
41 * - Interrupts (Interrupt handler is not provided in this driver. Application
42 * has to register it's own handler)
44 * <b> Initialization and Configuration </b>
46 * The device driver enables higher layer software (e.g., an application) to
47 * communicate with the Timer.
49 * XScuTimer_CfgInitialize() API is used to initialize the Timer. The
50 * user needs to first call the XScuTimer_LookupConfig() API which returns
51 * the Configuration structure pointer which is passed as a parameter to
52 * the XScuTimer_CfgInitialize() API.
56 * The Timer hardware supports interrupts.
58 * This driver does not provide a Interrupt Service Routine (ISR) for the device.
59 * It is the responsibility of the application to provide one if needed. Refer to
60 * the interrupt example provided with this driver for details on using the
61 * Timer in interrupt mode.
63 * <b> Virtual Memory </b>
65 * This driver supports Virtual Memory. The RTOS is responsible for calculating
66 * the correct device base address in Virtual Memory space.
70 * This driver is not thread safe. Any needs for threads or thread mutual
71 * exclusion must be satisfied by the layer above this driver.
75 * Asserts are used within all Xilinx drivers to enforce constraints on argument
76 * values. Asserts can be turned off on a system-wide basis by defining, at
77 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
78 * is recommended that users leave asserts on during development.
80 * <b> Building the driver </b>
82 * The XScuTimer driver is composed of several source files. This allows the user
83 * to build and link only those parts of the driver that are necessary.
88 * The timer is not a part of the snoop control unit as indicated by the
89 * prefix "scu" in the name of the driver.
90 * It is an independent module in APU.
93 * MODIFICATION HISTORY:
95 * Ver Who Date Changes
96 * ----- --- -------- ---------------------------------------------
97 * 1.00a nm 03/10/10 First release
98 * 1.02a sg 07/17/12 Included xil_assert.h for CR 667947. This is an issue
99 * when the xstatus.h in the common driver overwrites
100 * the xstatus.h of the standalone BSP during the
104 ******************************************************************************/
105 #ifndef XSCUTIMER_H /* prevent circular inclusions */
106 #define XSCUTIMER_H /* by using protection macros */
108 /***************************** Include Files *********************************/
111 #include "xscutimer_hw.h"
117 /************************** Constant Definitions *****************************/
119 /**************************** Type Definitions *******************************/
122 * This typedef contains configuration information for the device.
125 u16 DeviceId; /**< Unique ID of device */
126 u32 BaseAddr; /**< Base address of the device */
130 * The XScuTimer driver instance data. The user is required to allocate a
131 * variable of this type for every timer device in the system.
132 * A pointer to a variable of this type is then passed to the driver API
136 XScuTimer_Config Config; /**< Hardware Configuration */
137 u32 IsReady; /**< Device is initialized and ready */
138 u32 IsStarted; /**< Device timer is running */
141 /***************** Macros (Inline Functions) Definitions *********************/
143 /****************************************************************************/
146 * Check if the timer has expired.
148 * @param InstancePtr is a pointer to the XScuTimer instance.
151 * - TRUE if the timer has expired.
152 * - FALSE if the timer has not expired.
154 * @note C-style signature:
155 * int XScuTimer_IsExpired(XScuTimer *InstancePtr)
157 ******************************************************************************/
158 #define XScuTimer_IsExpired(InstancePtr) \
159 ((XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
160 XSCUTIMER_ISR_OFFSET) & \
161 XSCUTIMER_ISR_EVENT_FLAG_MASK) == \
162 XSCUTIMER_ISR_EVENT_FLAG_MASK)
164 /****************************************************************************/
167 * Re-start the timer. This macro will read the timer load register
168 * and writes the same value to load register to update the counter register.
170 * @param InstancePtr is a pointer to the XScuTimer instance.
174 * @note C-style signature:
175 * void XScuTimer_RestartTimer(XScuTimer *InstancePtr)
177 ******************************************************************************/
178 #define XScuTimer_RestartTimer(InstancePtr) \
179 XScuTimer_LoadTimer(InstancePtr, \
180 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
181 XSCUTIMER_LOAD_OFFSET))
183 /****************************************************************************/
186 * Write to the timer load register. This will also update the
187 * timer counter register with the new value. This macro can be used to
188 * change the time-out value.
190 * @param InstancePtr is a pointer to the XScuTimer instance.
191 * @param Value is the count to be loaded in to the load register.
195 * @note C-style signature:
196 * void XScuTimer_LoadTimer(XScuTimer *InstancePtr, u32 Value)
198 ******************************************************************************/
199 #define XScuTimer_LoadTimer(InstancePtr, Value) \
200 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
201 XSCUTIMER_LOAD_OFFSET, Value)
203 /****************************************************************************/
206 * Returns the current timer counter register value. It can be called at any
209 * @param InstancePtr is a pointer to the XScuTimer instance.
211 * @return Contents of the timer counter register.
213 * @note C-style signature:
214 u32 XScuTimer_GetCounterValue(XScuTimer *InstancePtr)
216 ******************************************************************************/
217 #define XScuTimer_GetCounterValue(InstancePtr) \
218 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
219 XSCUTIMER_COUNTER_OFFSET)
221 /****************************************************************************/
224 * Enable auto-reload mode.
226 * @param InstancePtr is a pointer to the XScuTimer instance.
230 * @note C-style signature:
231 * void XScuTimer_EnableAutoReload(XScuTimer *InstancePtr)
233 ******************************************************************************/
234 #define XScuTimer_EnableAutoReload(InstancePtr) \
235 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
236 XSCUTIMER_CONTROL_OFFSET, \
237 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
238 XSCUTIMER_CONTROL_OFFSET) | \
239 XSCUTIMER_CONTROL_AUTO_RELOAD_MASK))
241 /****************************************************************************/
244 * Disable auto-reload mode.
246 * @param InstancePtr is a pointer to the XScuTimer instance.
250 * @note C-style signature:
251 * void XScuTimer_DisableAutoReload(XScuTimer *InstancePtr)
253 ******************************************************************************/
254 #define XScuTimer_DisableAutoReload(InstancePtr) \
255 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
256 XSCUTIMER_CONTROL_OFFSET, \
257 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
258 XSCUTIMER_CONTROL_OFFSET) & \
259 ~(XSCUTIMER_CONTROL_AUTO_RELOAD_MASK)))
261 /****************************************************************************/
264 * Enable the Timer interrupt.
266 * @param InstancePtr is a pointer to the XScuTimer instance.
270 * @note C-style signature:
271 * void XScuTimer_EnableInterrupt(XScuTimer *InstancePtr)
273 ******************************************************************************/
274 #define XScuTimer_EnableInterrupt(InstancePtr) \
275 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
276 XSCUTIMER_CONTROL_OFFSET, \
277 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
278 XSCUTIMER_CONTROL_OFFSET) | \
279 XSCUTIMER_CONTROL_IRQ_ENABLE_MASK))
281 /****************************************************************************/
284 * Disable the Timer interrupt.
286 * @param InstancePtr is a pointer to the XScuTimer instance.
290 * @note C-style signature:
291 * void XScuTimer_DisableInterrupt(XScuTimer *InstancePtr)
293 ******************************************************************************/
294 #define XScuTimer_DisableInterrupt(InstancePtr) \
295 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
296 XSCUTIMER_CONTROL_OFFSET, \
297 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
298 XSCUTIMER_CONTROL_OFFSET) & \
299 ~(XSCUTIMER_CONTROL_IRQ_ENABLE_MASK)))
301 /*****************************************************************************/
304 * This function reads the interrupt status.
306 * @param InstancePtr is a pointer to the XScuTimer instance.
310 * @note C-style signature:
311 * void XScuTimer_GetInterruptStatus(XScuTimer *InstancePtr)
313 ******************************************************************************/
314 #define XScuTimer_GetInterruptStatus(InstancePtr) \
315 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
316 XSCUTIMER_ISR_OFFSET)
318 /*****************************************************************************/
321 * This function clears the interrupt status.
323 * @param InstancePtr is a pointer to the XScuTimer instance.
327 * @note C-style signature:
328 * void XScuTimer_ClearInterruptStatus(XScuTimer *InstancePtr)
330 ******************************************************************************/
331 #define XScuTimer_ClearInterruptStatus(InstancePtr) \
332 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
333 XSCUTIMER_ISR_OFFSET, XSCUTIMER_ISR_EVENT_FLAG_MASK)
335 /************************** Function Prototypes ******************************/
338 * Lookup configuration in xscutimer_sinit.c
340 XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId);
343 * Selftest function in xscutimer_selftest.c
345 int XScuTimer_SelfTest(XScuTimer *InstancePtr);
348 * Interface functions in xscutimer.c
350 int XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
351 XScuTimer_Config *ConfigPtr, u32 EffectiveAddress);
352 void XScuTimer_Start(XScuTimer *InstancePtr);
353 void XScuTimer_Stop(XScuTimer *InstancePtr);
354 void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue);
355 u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr);
361 #endif /* end of protection macro */