1 /******************************************************************************
3 * Copyright (C) 2002 - 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 xtmrctr_intr.c
37 * Contains interrupt-related functions for the XTmrCtr component.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00b jhl 02/06/02 First release
45 * 1.10b mta 03/21/07 Updated to new coding style
46 * 2.00a ktn 10/30/09 Updated to use HAL API's. _m is removed from all the macro
48 * 2.03a rvo 11/30/10 Added check to see if interrupt is enabled before further
49 * processing for CR 584557.
52 ******************************************************************************/
54 /***************************** Include Files *********************************/
59 /************************** Constant Definitions *****************************/
62 /**************************** Type Definitions *******************************/
65 /***************** Macros (Inline Functions) Definitions *********************/
68 /************************** Function Prototypes ******************************/
71 /************************** Variable Definitions *****************************/
74 /*****************************************************************************/
77 * Sets the timer callback function, which the driver calls when the specified
80 * @param InstancePtr is a pointer to the XTmrCtr instance .
81 * @param CallBackRef is the upper layer callback reference passed back
82 * when the callback function is invoked.
83 * @param FuncPtr is the pointer to the callback function.
89 * The handler is called within interrupt context so the function that is
90 * called should either be short or pass the more extensive processing off
91 * to another task to allow the interrupt to return and normal processing
94 ******************************************************************************/
95 void XTmrCtr_SetHandler(XTmrCtr * InstancePtr, XTmrCtr_Handler FuncPtr,
98 Xil_AssertVoid(InstancePtr != NULL);
99 Xil_AssertVoid(FuncPtr != NULL);
100 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
102 InstancePtr->Handler = FuncPtr;
103 InstancePtr->CallBackRef = CallBackRef;
106 /*****************************************************************************/
109 * Interrupt Service Routine (ISR) for the driver. This function only performs
110 * processing for the device and does not save and restore the interrupt context.
112 * @param InstancePtr contains a pointer to the timer/counter instance for
119 ******************************************************************************/
120 void XTmrCtr_InterruptHandler(void *InstancePtr)
122 XTmrCtr *TmrCtrPtr = NULL;
124 u32 ControlStatusReg;
127 * Verify that each of the inputs are valid.
129 Xil_AssertVoid(InstancePtr != NULL);
132 * Convert the non-typed pointer to an timer/counter instance pointer
133 * such that there is access to the timer/counter
135 TmrCtrPtr = (XTmrCtr *) InstancePtr;
138 * Loop thru each timer counter in the device and call the callback
139 * function for each timer which has caused an interrupt
141 for (TmrCtrNumber = 0;
142 TmrCtrNumber < XTC_DEVICE_TIMER_COUNT; TmrCtrNumber++) {
144 ControlStatusReg = XTmrCtr_ReadReg(TmrCtrPtr->BaseAddress,
148 * Check if interrupt is enabled
150 if (ControlStatusReg & XTC_CSR_ENABLE_INT_MASK) {
153 * Check if timer expired and interrupt occured
155 if (ControlStatusReg & XTC_CSR_INT_OCCURED_MASK) {
157 * Increment statistics for the number of
158 * interrupts and call the callback to handle
159 * any application specific processing
161 TmrCtrPtr->Stats.Interrupts++;
162 TmrCtrPtr->Handler(TmrCtrPtr->CallBackRef,
165 * Read the new Control/Status Register content.
168 XTmrCtr_ReadReg(TmrCtrPtr->BaseAddress,
172 * If in compare mode and a single shot rather
173 * than auto reload mode then disable the timer
174 * and reset it such so that the interrupt can
175 * be acknowledged, this should be only temporary
176 * till the hardware is fixed
178 if (((ControlStatusReg &
179 XTC_CSR_AUTO_RELOAD_MASK) == 0) &&
181 XTC_CSR_CAPTURE_MODE_MASK)== 0)) {
183 * Disable the timer counter and
184 * reset it such that the timer
185 * counter is loaded with the
186 * reset value allowing the
187 * interrupt to be acknowledged
190 ~XTC_CSR_ENABLE_TMR_MASK;
193 TmrCtrPtr->BaseAddress,
200 * Clear the reset condition,
201 * the reset bit must be
202 * manually cleared by a 2nd write
206 TmrCtrPtr->BaseAddress,
213 * Acknowledge the interrupt by clearing the
214 * interrupt bit in the timer control status
215 * register, this is done after calling the
216 * handler so the application could call
217 * IsExpired, the interrupt is cleared by
218 * writing a 1 to the interrupt bit of the
219 * register without changing any of the other
222 XTmrCtr_WriteReg(TmrCtrPtr->BaseAddress,
226 XTC_CSR_INT_OCCURED_MASK);