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 /****************************************************************************/
35 * @file xscutimer_hw.h
36 * @addtogroup scutimer_v2_0
39 * This file contains the hardware interface to the Timer.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- --- -------- ---------------------------------------------
46 * 1.00a nm 03/10/10 First release
47 * 1.01a sdm 02/02/12 Added low level macros to read/write load, counter, control
48 * and interrupt registers
49 * 1.02a sg 07/17/12 Included xil_assert.h for CR 667947. This is an issue
50 * when the xstatus.h in the common driver overwrites
51 * the xstatus.h of the standalone BSP during the
55 ******************************************************************************/
56 #ifndef XSCUTIMER_HW_H /* prevent circular inclusions */
57 #define XSCUTIMER_HW_H /* by using protection macros */
63 /***************************** Include Files *********************************/
64 #include "xil_types.h"
66 #include "xil_assert.h"
67 /************************** Constant Definitions *****************************/
69 /** @name Register Map
70 * Offsets of registers from the start of the device
74 #define XSCUTIMER_LOAD_OFFSET 0x00 /**< Timer Load Register */
75 #define XSCUTIMER_COUNTER_OFFSET 0x04 /**< Timer Counter Register */
76 #define XSCUTIMER_CONTROL_OFFSET 0x08 /**< Timer Control Register */
77 #define XSCUTIMER_ISR_OFFSET 0x0C /**< Timer Interrupt
81 /** @name Timer Control register
82 * This register bits control the prescaler, Intr enable,
83 * auto-reload and timer enable.
87 #define XSCUTIMER_CONTROL_PRESCALER_MASK 0x0000FF00 /**< Prescaler */
88 #define XSCUTIMER_CONTROL_PRESCALER_SHIFT 8
89 #define XSCUTIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004 /**< Intr enable */
90 #define XSCUTIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002 /**< Auto-reload */
91 #define XSCUTIMER_CONTROL_ENABLE_MASK 0x00000001 /**< Timer enable */
94 /** @name Interrupt Status register
95 * This register indicates the Timer counter register has reached zero.
99 #define XSCUTIMER_ISR_EVENT_FLAG_MASK 0x00000001 /**< Event flag */
102 /**************************** Type Definitions *******************************/
104 /***************** Macros (Inline Functions) Definitions *********************/
106 /****************************************************************************/
109 * Write to the timer load register. This will also update the
110 * timer counter register with the new value. This macro can be used to
111 * change the time-out value.
113 * @param BaseAddr is the base address of the scu timer.
114 * @param Value is the count to be loaded in to the load register.
118 * @note C-style signature:
119 * void XScuTimer_SetLoadReg(u32 BaseAddr, u32 Value)
121 ******************************************************************************/
122 #define XScuTimer_SetLoadReg(BaseAddr, Value) \
123 XScuTimer_WriteReg(BaseAddr, XSCUTIMER_LOAD_OFFSET, Value)
125 /****************************************************************************/
128 * Returns the current timer load register value.
130 * @param BaseAddr is the base address of the scu timer.
132 * @return Contents of the timer load register.
134 * @note C-style signature:
135 * u32 XScuTimer_GetLoadReg(u32 BaseAddr)
137 ******************************************************************************/
138 #define XScuTimer_GetLoadReg(BaseAddr) \
139 XScuTimer_ReadReg(BaseAddr, XSCUTIMER_LOAD_OFFSET)
141 /****************************************************************************/
144 * Write to the timer counter register.
146 * @param BaseAddr is the base address of the scu timer.
147 * @param Value is the count to be loaded in to the counter register.
151 * @note C-style signature:
152 * void XScuTimer_SetCounterReg(u32 BaseAddr, u32 Value)
154 ******************************************************************************/
155 #define XScuTimer_SetCounterReg(BaseAddr, Value) \
156 XScuTimer_WriteReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET, Value)
158 /****************************************************************************/
161 * Returns the current timer counter register value.
163 * @param BaseAddr is the base address of the scu timer.
165 * @return Contents of the timer counter register.
167 * @note C-style signature:
168 u32 XScuTimer_GetCounterReg(u32 BaseAddr)
170 ******************************************************************************/
171 #define XScuTimer_GetCounterReg(BaseAddr) \
172 XScuTimer_ReadReg(BaseAddr, XSCUTIMER_COUNTER_OFFSET)
174 /****************************************************************************/
177 * Write to the timer load register. This will also update the
178 * timer counter register with the new value. This macro can be used to
179 * change the time-out value.
181 * @param BaseAddr is the base address of the scu timer.
182 * @param Value is the count to be loaded in to the load register.
186 * @note C-style signature:
187 * void XScuTimer_SetControlReg(u32 BaseAddr, u32 Value)
189 ******************************************************************************/
190 #define XScuTimer_SetControlReg(BaseAddr, Value) \
191 XScuTimer_WriteReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET, Value)
193 /****************************************************************************/
196 * Returns the current timer load register value.
198 * @param BaseAddr is the base address of the scu timer.
200 * @return Contents of the timer load register.
202 * @note C-style signature:
203 u32 XScuTimer_GetControlReg(u32 BaseAddr)
205 ******************************************************************************/
206 #define XScuTimer_GetControlReg(BaseAddr) \
207 XScuTimer_ReadReg(BaseAddr, XSCUTIMER_CONTROL_OFFSET)
209 /****************************************************************************/
212 * Write to the timer counter register.
214 * @param BaseAddr is the base address of the scu timer.
215 * @param Value is the count to be loaded in to the counter register.
219 * @note C-style signature:
220 * void XScuTimer_SetIntrReg(u32 BaseAddr, u32 Value)
222 ******************************************************************************/
223 #define XScuTimer_SetIntrReg(BaseAddr, Value) \
224 XScuTimer_WriteReg(BaseAddr, XSCUTIMER_ISR_OFFSET, Value)
226 /****************************************************************************/
229 * Returns the current timer counter register value.
231 * @param BaseAddr is the base address of the scu timer.
233 * @return Contents of the timer counter register.
235 * @note C-style signature:
236 u32 XScuTimer_GetIntrReg(u32 BaseAddr)
238 ******************************************************************************/
239 #define XScuTimer_GetIntrReg(BaseAddr) \
240 XScuTimer_ReadReg(BaseAddr, XSCUTIMER_ISR_OFFSET)
242 /****************************************************************************/
245 * Read from the given Timer register.
247 * @param BaseAddr is the base address of the device
248 * @param RegOffset is the register offset to be read
250 * @return The 32-bit value of the register
252 * @note C-style signature:
253 * u32 XScuTimer_ReadReg(u32 BaseAddr, u32 RegOffset)
255 *****************************************************************************/
256 #define XScuTimer_ReadReg(BaseAddr, RegOffset) \
257 Xil_In32((BaseAddr) + (RegOffset))
259 /****************************************************************************/
262 * Write to the given Timer register.
264 * @param BaseAddr is the base address of the device
265 * @param RegOffset is the register offset to be written
266 * @param Data is the 32-bit value to write to the register
270 * @note C-style signature:
271 * void XScuTimer_WriteReg(u32 BaseAddr, u32 RegOffset, u32 Data)
273 *****************************************************************************/
274 #define XScuTimer_WriteReg(BaseAddr, RegOffset, Data) \
275 Xil_Out32((BaseAddr) + (RegOffset), (Data))
277 /************************** Function Prototypes ******************************/
279 /************************** Variable Definitions *****************************/
285 #endif /* end of protection macro */