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