1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 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_1
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
105 * 2.1 sk 02/26/15 Modified the code for MISRA-C:2012 compliance.
106 * ms 03/17/17 Added readme.txt file in examples folder for doxygen
110 ******************************************************************************/
111 #ifndef XSCUTIMER_H /* prevent circular inclusions */
112 #define XSCUTIMER_H /* by using protection macros */
114 /***************************** Include Files *********************************/
117 #include "xscutimer_hw.h"
123 /************************** Constant Definitions *****************************/
125 /**************************** Type Definitions *******************************/
128 * This typedef contains configuration information for the device.
131 u16 DeviceId; /**< Unique ID of device */
132 u32 BaseAddr; /**< Base address of the device */
136 * The XScuTimer driver instance data. The user is required to allocate a
137 * variable of this type for every timer device in the system.
138 * A pointer to a variable of this type is then passed to the driver API
142 XScuTimer_Config Config; /**< Hardware Configuration */
143 u32 IsReady; /**< Device is initialized and ready */
144 u32 IsStarted; /**< Device timer is running */
147 /***************** Macros (Inline Functions) Definitions *********************/
149 /****************************************************************************/
152 * Check if the timer has expired.
154 * @param InstancePtr is a pointer to the XScuTimer instance.
157 * - TRUE if the timer has expired.
158 * - FALSE if the timer has not expired.
160 * @note C-style signature:
161 * int XScuTimer_IsExpired(XScuTimer *InstancePtr)
163 ******************************************************************************/
164 #define XScuTimer_IsExpired(InstancePtr) \
165 ((XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
166 XSCUTIMER_ISR_OFFSET) & \
167 XSCUTIMER_ISR_EVENT_FLAG_MASK) == \
168 XSCUTIMER_ISR_EVENT_FLAG_MASK)
170 /****************************************************************************/
173 * Re-start the timer. This macro will read the timer load register
174 * and writes the same value to load register to update the counter register.
176 * @param InstancePtr is a pointer to the XScuTimer instance.
180 * @note C-style signature:
181 * void XScuTimer_RestartTimer(XScuTimer *InstancePtr)
183 ******************************************************************************/
184 #define XScuTimer_RestartTimer(InstancePtr) \
185 XScuTimer_LoadTimer((InstancePtr), \
186 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
187 XSCUTIMER_LOAD_OFFSET))
189 /****************************************************************************/
192 * Write to the timer load register. This will also update the
193 * timer counter register with the new value. This macro can be used to
194 * change the time-out value.
196 * @param InstancePtr is a pointer to the XScuTimer instance.
197 * @param Value is the count to be loaded in to the load register.
201 * @note C-style signature:
202 * void XScuTimer_LoadTimer(XScuTimer *InstancePtr, u32 Value)
204 ******************************************************************************/
205 #define XScuTimer_LoadTimer(InstancePtr, Value) \
206 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
207 XSCUTIMER_LOAD_OFFSET, (Value))
209 /****************************************************************************/
212 * Returns the current timer counter register value. It can be called at any
215 * @param InstancePtr is a pointer to the XScuTimer instance.
217 * @return Contents of the timer counter register.
219 * @note C-style signature:
220 u32 XScuTimer_GetCounterValue(XScuTimer *InstancePtr)
222 ******************************************************************************/
223 #define XScuTimer_GetCounterValue(InstancePtr) \
224 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
225 XSCUTIMER_COUNTER_OFFSET)
227 /****************************************************************************/
230 * Enable auto-reload mode.
232 * @param InstancePtr is a pointer to the XScuTimer instance.
236 * @note C-style signature:
237 * void XScuTimer_EnableAutoReload(XScuTimer *InstancePtr)
239 ******************************************************************************/
240 #define XScuTimer_EnableAutoReload(InstancePtr) \
241 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
242 XSCUTIMER_CONTROL_OFFSET, \
243 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
244 XSCUTIMER_CONTROL_OFFSET) | \
245 XSCUTIMER_CONTROL_AUTO_RELOAD_MASK))
247 /****************************************************************************/
250 * Disable auto-reload mode.
252 * @param InstancePtr is a pointer to the XScuTimer instance.
256 * @note C-style signature:
257 * void XScuTimer_DisableAutoReload(XScuTimer *InstancePtr)
259 ******************************************************************************/
260 #define XScuTimer_DisableAutoReload(InstancePtr) \
261 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
262 XSCUTIMER_CONTROL_OFFSET, \
263 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
264 XSCUTIMER_CONTROL_OFFSET) & \
265 ~(XSCUTIMER_CONTROL_AUTO_RELOAD_MASK)))
267 /****************************************************************************/
270 * Enable the Timer interrupt.
272 * @param InstancePtr is a pointer to the XScuTimer instance.
276 * @note C-style signature:
277 * void XScuTimer_EnableInterrupt(XScuTimer *InstancePtr)
279 ******************************************************************************/
280 #define XScuTimer_EnableInterrupt(InstancePtr) \
281 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
282 XSCUTIMER_CONTROL_OFFSET, \
283 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
284 XSCUTIMER_CONTROL_OFFSET) | \
285 XSCUTIMER_CONTROL_IRQ_ENABLE_MASK))
287 /****************************************************************************/
290 * Disable the Timer interrupt.
292 * @param InstancePtr is a pointer to the XScuTimer instance.
296 * @note C-style signature:
297 * void XScuTimer_DisableInterrupt(XScuTimer *InstancePtr)
299 ******************************************************************************/
300 #define XScuTimer_DisableInterrupt(InstancePtr) \
301 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
302 XSCUTIMER_CONTROL_OFFSET, \
303 (XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
304 XSCUTIMER_CONTROL_OFFSET) & \
305 ~(XSCUTIMER_CONTROL_IRQ_ENABLE_MASK)))
307 /*****************************************************************************/
310 * This function reads the interrupt status.
312 * @param InstancePtr is a pointer to the XScuTimer instance.
316 * @note C-style signature:
317 * void XScuTimer_GetInterruptStatus(XScuTimer *InstancePtr)
319 ******************************************************************************/
320 #define XScuTimer_GetInterruptStatus(InstancePtr) \
321 XScuTimer_ReadReg((InstancePtr)->Config.BaseAddr, \
322 XSCUTIMER_ISR_OFFSET)
324 /*****************************************************************************/
327 * This function clears the interrupt status.
329 * @param InstancePtr is a pointer to the XScuTimer instance.
333 * @note C-style signature:
334 * void XScuTimer_ClearInterruptStatus(XScuTimer *InstancePtr)
336 ******************************************************************************/
337 #define XScuTimer_ClearInterruptStatus(InstancePtr) \
338 XScuTimer_WriteReg((InstancePtr)->Config.BaseAddr, \
339 XSCUTIMER_ISR_OFFSET, XSCUTIMER_ISR_EVENT_FLAG_MASK)
341 /************************** Function Prototypes ******************************/
344 * Lookup configuration in xscutimer_sinit.c
346 XScuTimer_Config *XScuTimer_LookupConfig(u16 DeviceId);
349 * Selftest function in xscutimer_selftest.c
351 s32 XScuTimer_SelfTest(XScuTimer *InstancePtr);
354 * Interface functions in xscutimer.c
356 s32 XScuTimer_CfgInitialize(XScuTimer *InstancePtr,
357 XScuTimer_Config *ConfigPtr, u32 EffectiveAddress);
358 void XScuTimer_Start(XScuTimer *InstancePtr);
359 void XScuTimer_Stop(XScuTimer *InstancePtr);
360 void XScuTimer_SetPrescaler(XScuTimer *InstancePtr, u8 PrescalerValue);
361 u8 XScuTimer_GetPrescaler(XScuTimer *InstancePtr);
367 #endif /* end of protection macro */