]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/ttcps_v3_0/src/xttcps.h
Completely re-generate the Zynq 7000 demo using the 2016.1 SDK tools.
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / ttcps_v3_0 / src / xttcps.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xttcps.h
36 *
37 * This is the driver for one 16-bit timer counter in the Triple Timer Counter
38 * (TTC) module in the Ps block.
39 *
40 * The TTC module provides three independent timer/counter modules that can each
41 * be clocked using either the system clock (pclk) or an externally driven
42 * clock (ext_clk). In addition, each counter can independently prescale its
43 * selected clock input (divided by 2 to 65536). Counters can be set to
44 * decrement or increment.
45 *
46 * Each of the counters can be programmed to generate interrupt pulses:
47 *       . At a regular, predefined period, that is on a timed interval
48 *       . When the counter registers overflow
49 *       . When the count matches any one of the three 'match' registers
50 *
51 * Therefore, up to six different events can trigger a timer interrupt: three
52 * match interrupts, an overflow interrupt, an interval interrupt and an event
53 * timer interrupt. Note that the overflow interrupt and the interval interrupt
54 * are mutually exclusive.
55 *
56 * <b>Initialization & Configuration</b>
57 *
58 * An XTtcPs_Config structure is used to configure a driver instance.
59 * Information in the XTtcPs_Config structure is the hardware properties
60 * about the device.
61 *
62 * A driver instance is initialized through
63 * XTtcPs_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr). Where CfgPtr
64 * is a pointer to the XTtcPs_Config structure, it can be looked up statically
65 * through XTtcPs_LookupConfig(DeviceID), or passed in by the caller. The
66 * EffectiveAddr can be the static base address of the device or virtual
67 * mapped address if address translation is supported.
68 *
69 * <b>Interrupts</b>
70 *
71 * Interrupt handler is not provided by the driver, as handling of interrupt
72 * is application specific.
73 *
74 * @note
75 * The default setting for a timer/counter is:
76 *  - Overflow Mode
77 *  - Internal clock (pclk) selected
78 *  - Counter disabled
79 *  - All Interrupts disabled
80 *  - Output waveforms disabled
81 *
82 * <pre>
83 * MODIFICATION HISTORY:
84 *
85 * Ver   Who    Date     Changes
86 * ----- ------ -------- -----------------------------------------------------
87 * 1.00a drg/jz 01/20/10 First release..
88 * 2.0   adk    12/10/13 Updated as per the New Tcl API's
89 * 3.0   pkp    12/09/14 Added support for Zynq Ultrascale Mp.Also code
90 *                       modified for MISRA-C:2012 compliance.
91 * </pre>
92 *
93 ******************************************************************************/
94
95 #ifndef XTTCPS_H                /* prevent circular inclusions */
96 #define XTTCPS_H                /* by using protection macros */
97
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101
102 /***************************** Include Files *********************************/
103
104 #include "xttcps_hw.h"
105 #include "xstatus.h"
106
107 /************************** Constant Definitions *****************************/
108
109 /** @name Configuration options
110  *
111  * Options for the device. Each of the options is bit field, so more than one
112  * options can be specified.
113  *
114  * @{
115  */
116 #define XTTCPS_OPTION_EXTERNAL_CLK      0x00000001U     /**< External clock source */
117 #define XTTCPS_OPTION_CLK_EDGE_NEG      0x00000002U     /**< Clock on trailing edge for
118                                                      external clock*/
119 #define XTTCPS_OPTION_INTERVAL_MODE     0x00000004U     /**< Interval mode */
120 #define XTTCPS_OPTION_DECREMENT         0x00000008U     /**< Decrement the counter */
121 #define XTTCPS_OPTION_MATCH_MODE        0x00000010U     /**< Match mode */
122 #define XTTCPS_OPTION_WAVE_DISABLE      0x00000020U     /**< No waveform output */
123 #define XTTCPS_OPTION_WAVE_POLARITY     0x00000040U     /**< Waveform polarity */
124 /*@}*/
125
126 /**************************** Type Definitions *******************************/
127
128 /**
129  * This typedef contains configuration information for the device.
130  */
131 typedef struct {
132         u16 DeviceId;     /**< Unique ID for device */
133         u32 BaseAddress;  /**< Base address for device */
134         u32 InputClockHz; /**< Input clock frequency */
135 } XTtcPs_Config;
136
137 /**
138  * The XTtcPs driver instance data. The user is required to allocate a
139  * variable of this type for each PS timer/counter device in the system. A
140  * pointer to a variable of this type is then passed to various driver API
141  * functions.
142  */
143 typedef struct {
144         XTtcPs_Config Config;   /**< Configuration structure */
145         u32 IsReady;            /**< Device is initialized and ready */
146 } XTtcPs;
147
148
149 /***************** Macros (Inline Functions) Definitions *********************/
150
151 /*
152  * Internal helper macros
153  */
154 #define InstReadReg(InstancePtr, RegOffset) \
155     (Xil_In32(((InstancePtr)->Config.BaseAddress) + (u32)(RegOffset)))
156
157 #define InstWriteReg(InstancePtr, RegOffset, Data) \
158     (Xil_Out32(((InstancePtr)->Config.BaseAddress) + (u32)(RegOffset), (u32)(Data)))
159
160 /*****************************************************************************/
161 /**
162 *
163 * This function starts the counter/timer without resetting the counter value.
164 *
165 * @param        InstancePtr is a pointer to the XTtcPs instance.
166 *
167 * @return       None
168 *
169 * @note         C-style signature:
170 *               void XTtcPs_Start(XTtcPs *InstancePtr)
171 *
172 ****************************************************************************/
173 #define XTtcPs_Start(InstancePtr)       \
174                 InstWriteReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET,    \
175                 (InstReadReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET) &  \
176                  ~XTTCPS_CNT_CNTRL_DIS_MASK))
177
178 /*****************************************************************************/
179 /**
180 *
181 * This function stops the counter/timer. This macro may be called at any time
182 * to stop the counter. The counter holds the last value until it is reset,
183 * restarted or enabled.
184 *
185 * @param        InstancePtr is a pointer to the XTtcPs instance.
186 *
187 * @return       None
188 *
189 * @note         C-style signature:
190 *               void XTtcPs_Stop(XTtcPs *InstancePtr)
191 *
192 ****************************************************************************/
193 #define XTtcPs_Stop(InstancePtr)                \
194                 InstWriteReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET,    \
195                 (InstReadReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET) |  \
196                  XTTCPS_CNT_CNTRL_DIS_MASK))
197
198 /*****************************************************************************/
199 /**
200 *
201 * This function checks whether the timer counter has already started.
202 *
203 * @param        InstancePtr is a pointer to the XTtcPs instance
204 *
205 * @return       Non-zero if the device has started, '0' otherwise.
206 *
207 * @note         C-style signature:
208 *               int XTtcPs_IsStarted(XTtcPs *InstancePtr)
209 *
210 ****************************************************************************/
211 #define XTtcPs_IsStarted(InstancePtr) \
212      ((InstReadReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET) & \
213        XTTCPS_CNT_CNTRL_DIS_MASK) == 0U)
214
215 /*****************************************************************************/
216 /**
217 *
218 * This function returns the current 16-bit counter value. It may be called at
219 * any time.
220 *
221 * @param        InstancePtr is a pointer to the XTtcPs instance.
222 *
223 * @return       16-bit counter value.
224 *
225 * @note         C-style signature:
226 *               u16 XTtcPs_GetCounterValue(XTtcPs *InstancePtr)
227 *
228 ****************************************************************************/
229 #define XTtcPs_GetCounterValue(InstancePtr) \
230                 (u16)InstReadReg((InstancePtr), XTTCPS_COUNT_VALUE_OFFSET)
231
232 /*****************************************************************************/
233 /**
234 *
235 * This function sets the interval value to be used in interval mode.
236 *
237 * @param        InstancePtr is a pointer to the XTtcPs instance.
238 * @param        Value is the 16-bit value to be set in the interval register.
239 *
240 * @return       None
241 *
242 * @note         C-style signature:
243 *               void XTtcPs_SetInterval(XTtcPs *InstancePtr, u16 Value)
244 *
245 ****************************************************************************/
246 #define XTtcPs_SetInterval(InstancePtr, Value)  \
247                 InstWriteReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET, (Value))
248
249 /*****************************************************************************/
250 /**
251 *
252 * This function gets the interval value from the interval register.
253 *
254 * @param        InstancePtr is a pointer to the XTtcPs instance.
255 *
256 * @return       16-bit interval value
257 *
258 * @note         C-style signature:
259 *               u16 XTtcPs_GetInterval(XTtcPs *InstancePtr)
260 *
261 ****************************************************************************/
262 #define XTtcPs_GetInterval(InstancePtr) \
263                 (u16)InstReadReg((InstancePtr), XTTCPS_INTERVAL_VAL_OFFSET)
264
265 /*****************************************************************************/
266 /**
267 *
268 * This macro resets the count register. It may be called at any time. The
269 * counter is reset to either 0 or 0xFFFF, or the interval value, depending on
270 * the increment/decrement mode. The state of the counter, as started or
271 * stopped, is not affected by calling reset.
272 *
273 * @param        InstancePtr is a pointer to the XTtcPs instance.
274 *
275 * @return       None
276 *
277 * @note         C-style signature:
278 *               void XTtcPs_ResetCounterValue(XTtcPs *InstancePtr)
279 *
280 ****************************************************************************/
281 #define XTtcPs_ResetCounterValue(InstancePtr) \
282                 InstWriteReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET,    \
283                 (InstReadReg((InstancePtr), XTTCPS_CNT_CNTRL_OFFSET) | \
284                  (u32)XTTCPS_CNT_CNTRL_RST_MASK))
285
286 /*****************************************************************************/
287 /**
288 *
289 * This function enables the interrupts.
290 *
291 * @param        InstancePtr is a pointer to the XTtcPs instance.
292 * @param        InterruptMask defines which interrupt should be enabled.
293 *               Constants are defined in xttcps_hw.h as XTTCPS_IXR_*.
294 *               This is a bit mask, all set bits will be enabled, cleared bits
295 *               will not be disabled.
296 *
297 * @return       None.
298 *
299 * @note
300 * C-style signature:
301 *       void XTtcPs_EnableInterrupts(XTtcPs *InstancePtr, u32 InterruptMask)
302 *
303 ******************************************************************************/
304 #define XTtcPs_EnableInterrupts(InstancePtr, InterruptMask)             \
305                 InstWriteReg((InstancePtr), XTTCPS_IER_OFFSET,          \
306                 (InstReadReg((InstancePtr), XTTCPS_IER_OFFSET) |        \
307                  (InterruptMask)))
308
309 /*****************************************************************************/
310 /**
311 *
312 * This function disables the interrupts.
313 *
314 * @param        InstancePtr is a pointer to the XTtcPs instance.
315 * @param        InterruptMask defines which interrupt should be disabled.
316 *               Constants are defined in xttcps_hw.h as XTTCPS_IXR_*.
317 *               This is a bit mask, all set bits will be disabled, cleared bits
318 *               will not be disabled.
319 *
320 * @return       None.
321 *
322 * @note
323 * C-style signature:
324 *       void XTtcPs_DisableInterrupts(XTtcPs *InstancePtr, u32 InterruptMask)
325 *
326 ******************************************************************************/
327 #define XTtcPs_DisableInterrupts(InstancePtr, InterruptMask) \
328                 InstWriteReg((InstancePtr), XTTCPS_IER_OFFSET,  \
329                 (InstReadReg((InstancePtr), XTTCPS_IER_OFFSET) &        \
330                  ~(InterruptMask)))
331
332 /*****************************************************************************/
333 /**
334 *
335 * This function reads the interrupt status.
336 *
337 * @param        InstancePtr is a pointer to the XTtcPs instance.
338 *
339 * @return       None.
340 *
341 * @note         C-style signature:
342 *               u32 XTtcPs_GetInterruptStatus(XTtcPs *InstancePtr)
343 *
344 ******************************************************************************/
345 #define XTtcPs_GetInterruptStatus(InstancePtr)   \
346                 InstReadReg((InstancePtr), XTTCPS_ISR_OFFSET)
347
348 /*****************************************************************************/
349 /**
350 *
351 * This function clears the interrupt status.
352 *
353 * @param        InstancePtr is a pointer to the XTtcPs instance.
354 * @param        InterruptMask defines which interrupt should be cleared.
355 *               Constants are defined in xttcps_hw.h as XTTCPS_IXR_*.
356 *               This is a bit mask, all set bits will be cleared, cleared bits
357 *               will not be cleared.
358 *
359 * @return       None.
360 *
361 * @note
362 * C-style signature:
363 *       void XTtcPs_ClearInterruptStatus(XTtcPs *InstancePtr, u32 InterruptMask)
364 *
365 ******************************************************************************/
366 #define XTtcPs_ClearInterruptStatus(InstancePtr, InterruptMask) \
367                 InstWriteReg((InstancePtr), XTTCPS_ISR_OFFSET, \
368                  (InterruptMask))
369
370
371 /************************** Function Prototypes ******************************/
372
373 /*
374  * Initialization functions in xttcps_sinit.c
375  */
376 XTtcPs_Config *XTtcPs_LookupConfig(u16 DeviceId);
377
378 /*
379  * Required functions, in xttcps.c
380  */
381 s32 XTtcPs_CfgInitialize(XTtcPs *InstancePtr,
382          XTtcPs_Config * ConfigPtr, u32 EffectiveAddr);
383
384 void XTtcPs_SetMatchValue(XTtcPs *InstancePtr, u8 MatchIndex, u16 Value);
385 u16 XTtcPs_GetMatchValue(XTtcPs *InstancePtr, u8 MatchIndex);
386
387 void XTtcPs_SetPrescaler(XTtcPs *InstancePtr, u8 PrescalerValue);
388 u8 XTtcPs_GetPrescaler(XTtcPs *InstancePtr);
389
390 void XTtcPs_CalcIntervalFromFreq(XTtcPs *InstancePtr, u32 Freq,
391         u16 *Interval, u8 *Prescaler);
392
393 /*
394  * Functions for options, in file xttcps_options.c
395  */
396 s32 XTtcPs_SetOptions(XTtcPs *InstancePtr, u32 Options);
397 u32 XTtcPs_GetOptions(XTtcPs *InstancePtr);
398
399 /*
400  * Function for self-test, in file xttcps_selftest.c
401  */
402 s32 XTtcPs_SelfTest(XTtcPs *InstancePtr);
403
404 #ifdef __cplusplus
405 }
406 #endif
407
408 #endif /* end of protection macro */