]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/tmrctr_v3_0/src/xtmrctr.h
Common scheduler code:
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / tmrctr_v3_0 / src / xtmrctr.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 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 xtmrctr.h
36 *
37 * The Xilinx timer/counter component. This component supports the Xilinx
38 * timer/counter. More detailed description of the driver operation can
39 * be found in the xtmrctr.c file.
40 *
41 * The Xilinx timer/counter supports the following features:
42 *   - Polled mode.
43 *   - Interrupt driven mode
44 *   - enabling and disabling specific timers
45 *   - PWM operation
46 *   - Cascade Operation (This is to be used for getting a 64 bit timer and this
47 *     feature is present in the latest versions of the axi_timer IP)
48 *
49 * The driver does not currently support the PWM operation of the device.
50 *
51 * The timer counter operates in 2 primary modes, compare and capture. In
52 * either mode, the timer counter may count up or down, with up being the
53 * default.
54 *
55 * Compare mode is typically used for creating a single time period or multiple
56 * repeating time periods in the auto reload mode, such as a periodic interrupt.
57 * When started, the timer counter loads an initial value, referred to as the
58 * compare value, into the timer counter and starts counting down or up. The
59 * timer counter expires when it rolls over/under depending upon the mode of
60 * counting. An external compare output signal may be configured such that a
61 * pulse is generated with this signal when it hits the compare value.
62 *
63 * Capture mode is typically used for measuring the time period between
64 * external events. This mode uses an external capture input signal to cause
65 * the value of the timer counter to be captured. When started, the timer
66 * counter loads an initial value, referred to as the compare value,
67
68 * The timer can be configured to either cause an interrupt when the count
69 * reaches the compare value in compare mode or latch the current count
70 * value in the capture register when an external input is asserted
71 * in capture mode. The external capture input can be enabled/disabled using the
72 * XTmrCtr_SetOptions function. While in compare mode, it is also possible to
73 * drive an external output when the compare value is reached in the count
74 * register The external compare output can be enabled/disabled using the
75 * XTmrCtr_SetOptions function.
76 *
77 * <b>Interrupts</b>
78 *
79 * It is the responsibility of the application to connect the interrupt
80 * handler of the timer/counter to the interrupt source. The interrupt
81 * handler function, XTmrCtr_InterruptHandler, is visible such that the user
82 * can connect it to the interrupt source. Note that this interrupt handler
83 * does not provide interrupt context save and restore processing, the user
84 * must perform this processing.
85 *
86 * The driver services interrupts and passes timeouts to the upper layer
87 * software through callback functions. The upper layer software must register
88 * its callback functions during initialization. The driver requires callback
89 * functions for timers.
90 *
91 * @note
92 * The default settings for the timers are:
93 *   - Interrupt generation disabled
94 *   - Count up mode
95 *   - Compare mode
96 *   - Hold counter (will not reload the timer)
97 *   - External compare output disabled
98 *   - External capture input disabled
99 *   - Pulse width modulation disabled
100 *   - Timer disabled, waits for Start function to be called
101 * <br><br>
102 * A timer counter device may contain multiple timer counters. The symbol
103 * XTC_DEVICE_TIMER_COUNT defines the number of timer counters in the device.
104 * The device currently contains 2 timer counters.
105 * <br><br>
106 * This driver is intended to be RTOS and processor independent. It works with
107 * physical addresses only. Any needs for dynamic memory management, threads
108 * or thread mutual exclusion, virtual memory, or cache control must be
109 * satisfied by the layer above this driver.
110 *
111 * <pre>
112 * MODIFICATION HISTORY:
113 *
114 * Ver   Who  Date     Changes
115 * ----- ---- -------- -----------------------------------------------
116 * 1.00a ecm  08/16/01 First release
117 * 1.00b jhl  02/21/02 Repartitioned the driver for smaller files
118 * 1.10b mta  03/21/07 Updated to new coding style.
119 * 1.11a sdm  08/22/08 Removed support for static interrupt handlers from the MDD
120 *                     file
121 * 2.00a ktn  10/30/09 Updated to use HAL API's. _m is removed from all the macro
122 *                     definitions.
123 * 2.01a ktn  07/12/10 Renamed the macro XTimerCtr_ReadReg as XTmrCtr_ReadReg
124 *                     for naming consistency (CR 559142).
125 * 2.02a sdm  09/28/10 Updated the driver tcl to generate the xparameters
126 *                     for the timer clock frequency (CR 572679).
127 * 2.03a rvo  11/30/10 Added check to see if interrupt is enabled before further
128 *                     processing for CR 584557.
129 * 2.04a sdm  07/12/11 Added support for cascade mode operation.
130 *                     The cascade mode of operation is present in the latest
131 *                     versions of the axi_timer IP. Please check the HW
132 *                     Datasheet to see whether this feature is present in the
133 *                     version of the IP that you are using.
134 * 2.05a adk  15/05/13 Fixed the CR:693066
135 *                     Added the IsStartedTmrCtr0/IsStartedTmrCtr1 members to the
136 *                     XTmrCtr instance structure.
137 *                     The IsStartedTmrCtrX will be assigned XIL_COMPONENT_IS_STARTED in
138 *                     the XTmrCtr_Start function.
139 *                     The IsStartedTmrCtrX will be cleared in the XTmrCtr_Stop function.
140 *                     There will be no Initialization done in the
141 *                     XTmrCtr_Initialize if both the timers have already started and
142 *                     the XST_DEVICE_IS_STARTED Status is returned.
143 *                     Removed the logic in the XTmrCtr_Initialize function
144 *                     which was checking the Register Value to know whether
145 *                     a timer has started or not.
146 * 3.0   adk  19/12/13 Updated as per the New Tcl API's
147 * </pre>
148 *
149 ******************************************************************************/
150
151 #ifndef XTMRCTR_H               /* prevent circular inclusions */
152 #define XTMRCTR_H               /* by using protection macros */
153
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157
158 /***************************** Include Files *********************************/
159
160 #include "xil_types.h"
161 #include "xil_assert.h"
162 #include "xstatus.h"
163 #include "xtmrctr_l.h"
164
165 /************************** Constant Definitions *****************************/
166
167 /**
168  * @name Configuration options
169  * These options are used in XTmrCtr_SetOptions() and XTmrCtr_GetOptions()
170  * @{
171  */
172 /**
173  * Used to configure the timer counter device.
174  * <pre>
175  * XTC_CASCADE_MODE_OPTION      Enables the Cascade Mode only valid for TCSRO.
176  * XTC_ENABLE_ALL_OPTION        Enables all timer counters at once.
177  * XTC_DOWN_COUNT_OPTION        Configures the timer counter to count down from
178  *                              start value, the default is to count up.
179  * XTC_CAPTURE_MODE_OPTION      Configures the timer to capture the timer
180  *                              counter value when the external capture line is
181  *                              asserted. The default mode is compare mode.
182  * XTC_INT_MODE_OPTION          Enables the timer counter interrupt output.
183  * XTC_AUTO_RELOAD_OPTION       In compare mode, configures the timer counter to
184  *                              reload from the compare value. The default mode
185  *                              causes the timer counter to hold when the
186  *                              compare value is hit.
187  *                              In capture mode, configures the timer counter to
188  *                              not hold the previous capture value if a new
189  *                              event occurs. The default mode cause the timer
190  *                              counter to hold the capture value until
191  *                              recognized.
192  * XTC_EXT_COMPARE_OPTION       Enables the external compare output signal.
193  * </pre>
194  */
195 #define XTC_CASCADE_MODE_OPTION         0x00000080UL
196 #define XTC_ENABLE_ALL_OPTION           0x00000040UL
197 #define XTC_DOWN_COUNT_OPTION           0x00000020UL
198 #define XTC_CAPTURE_MODE_OPTION         0x00000010UL
199 #define XTC_INT_MODE_OPTION             0x00000008UL
200 #define XTC_AUTO_RELOAD_OPTION          0x00000004UL
201 #define XTC_EXT_COMPARE_OPTION          0x00000002UL
202 /*@}*/
203
204 /**************************** Type Definitions *******************************/
205
206 /**
207  * This typedef contains configuration information for the device.
208  */
209 typedef struct {
210         u16 DeviceId;   /**< Unique ID  of device */
211         u32 BaseAddress;/**< Register base address */
212 } XTmrCtr_Config;
213
214 /**
215  * Signature for the callback function.
216  *
217  * @param       CallBackRef is a callback reference passed in by the upper layer
218  *              when setting the callback functions, and passed back to the
219  *              upper layer when the callback is invoked. Its type is
220  *               unimportant to the driver, so it is a void pointer.
221  * @param       TmrCtrNumber is the number of the timer/counter within the
222  *              device. The device typically contains at least two
223  *              timer/counters. The timer number is a zero based number with a
224  *              range of 0 to (XTC_DEVICE_TIMER_COUNT - 1).
225  */
226 typedef void (*XTmrCtr_Handler) (void *CallBackRef, u8 TmrCtrNumber);
227
228
229 /**
230  * Timer/Counter statistics
231  */
232 typedef struct {
233         u32 Interrupts;  /**< The number of interrupts that have occurred */
234 } XTmrCtrStats;
235
236 /**
237  * The XTmrCtr driver instance data. The user is required to allocate a
238  * variable of this type for every timer/counter device in the system. A
239  * pointer to a variable of this type is then passed to the driver API
240  * functions.
241  */
242 typedef struct {
243         XTmrCtrStats Stats;      /**< Component Statistics */
244         u32 BaseAddress;         /**< Base address of registers */
245         u32 IsReady;             /**< Device is initialized and ready */
246         u32 IsStartedTmrCtr0;    /**< Is Timer Counter 0 started */
247         u32 IsStartedTmrCtr1;    /**< Is Timer Counter 1 started */
248
249         XTmrCtr_Handler Handler; /**< Callback function */
250         void *CallBackRef;       /**< Callback reference for handler */
251 } XTmrCtr;
252
253
254 /***************** Macros (Inline Functions) Definitions *********************/
255
256
257 /************************** Function Prototypes ******************************/
258
259 /*
260  * Required functions, in file xtmrctr.c
261  */
262 int XTmrCtr_Initialize(XTmrCtr * InstancePtr, u16 DeviceId);
263 void XTmrCtr_Start(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
264 void XTmrCtr_Stop(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
265 u32 XTmrCtr_GetValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
266 void XTmrCtr_SetResetValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber,
267                            u32 ResetValue);
268 u32 XTmrCtr_GetCaptureValue(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
269 int XTmrCtr_IsExpired(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
270 void XTmrCtr_Reset(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
271 XTmrCtr_Config *XTmrCtr_LookupConfig(u16 DeviceId);
272
273 /*
274  * Functions for options, in file xtmrctr_options.c
275  */
276 void XTmrCtr_SetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber, u32 Options);
277 u32 XTmrCtr_GetOptions(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
278
279 /*
280  * Functions for statistics, in file xtmrctr_stats.c
281  */
282 void XTmrCtr_GetStats(XTmrCtr * InstancePtr, XTmrCtrStats * StatsPtr);
283 void XTmrCtr_ClearStats(XTmrCtr * InstancePtr);
284
285 /*
286  * Functions for self-test, in file xtmrctr_selftest.c
287  */
288 int XTmrCtr_SelfTest(XTmrCtr * InstancePtr, u8 TmrCtrNumber);
289
290 /*
291  * Functions for interrupts, in file xtmrctr_intr.c
292  */
293 void XTmrCtr_SetHandler(XTmrCtr * InstancePtr, XTmrCtr_Handler FuncPtr,
294                         void *CallBackRef);
295 void XTmrCtr_InterruptHandler(void *InstancePtr);
296
297 #ifdef __cplusplus
298 }
299 #endif
300
301 #endif /* end of protection macro */