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 xdevcfg_intr.c
37 * Contains the implementation of interrupt related functions of the XDcfg
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- --- -------- ---------------------------------------------
45 * 1.00a hvm 02/07/11 First release
46 * 2.01a nm 07/07/12 Updated the XDcfg_IntrClear function to directly
47 * set the mask instead of oring it with the
48 * value read from the interrupt status register
51 ******************************************************************************/
53 /***************************** Include Files *********************************/
57 /************************** Constant Definitions *****************************/
59 /**************************** Type Definitions *******************************/
61 /***************** Macros (Inline Functions) Definitions *********************/
63 /************************** Function Prototypes ******************************/
65 /************************** Variable Definitions *****************************/
67 /****************************************************************************/
70 * This function enables the specified interrupts in the device.
72 * @param InstancePtr is a pointer to the XDcfg instance.
73 * @param Mask is the bit-mask of the interrupts to be enabled.
74 * Bit positions of 1 will be enabled. Bit positions of 0 will
75 * keep the previous setting. This mask is formed by OR'ing
76 * XDCFG_INT_* bits defined in xdevcfg_hw.h.
82 *****************************************************************************/
83 void XDcfg_IntrEnable(XDcfg *InstancePtr, u32 Mask)
88 * Assert the arguments.
90 Xil_AssertVoid(InstancePtr != NULL);
91 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
94 * Enable the specified interrupts in the Interrupt Mask Register.
96 RegValue = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
97 XDCFG_INT_MASK_OFFSET);
98 RegValue &= ~(Mask & XDCFG_IXR_ALL_MASK);
99 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
100 XDCFG_INT_MASK_OFFSET,
105 /****************************************************************************/
108 * This function disables the specified interrupts in the device.
110 * @param InstancePtr is a pointer to the XDcfg instance.
111 * @param Mask is the bit-mask of the interrupts to be disabled.
112 * Bit positions of 1 will be disabled. Bit positions of 0 will
113 * keep the previous setting. This mask is formed by OR'ing
114 * XDCFG_INT_* bits defined in xdevcfg_hw.h.
120 *****************************************************************************/
121 void XDcfg_IntrDisable(XDcfg *InstancePtr, u32 Mask)
126 * Assert the arguments.
128 Xil_AssertVoid(InstancePtr != NULL);
129 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
132 * Disable the specified interrupts in the Interrupt Mask Register.
134 RegValue = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
135 XDCFG_INT_MASK_OFFSET);
136 RegValue |= (Mask & XDCFG_IXR_ALL_MASK);
137 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
138 XDCFG_INT_MASK_OFFSET,
141 /****************************************************************************/
144 * This function returns the enabled interrupts read from the Interrupt Mask
145 * Register. Use the XDCFG_INT_* constants defined in xdevcfg_hw.h
146 * to interpret the returned value.
148 * @param InstancePtr is a pointer to the XDcfg instance.
150 * @return A 32-bit value representing the contents of the IMR.
154 *****************************************************************************/
155 u32 XDcfg_IntrGetEnabled(XDcfg *InstancePtr)
158 * Assert the arguments.
160 Xil_AssertNonvoid(InstancePtr != NULL);
161 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
164 * Return the value read from the Interrupt Mask Register.
166 return (~ XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
167 XDCFG_INT_MASK_OFFSET));
170 /****************************************************************************/
173 * This function returns the interrupt status read from Interrupt Status
174 * Register. Use the XDCFG_INT_* constants defined in xdevcfg_hw.h
175 * to interpret the returned value.
177 * @param InstancePtr is a pointer to the XDcfg instance.
179 * @return A 32-bit value representing the contents of the Interrupt
184 *****************************************************************************/
185 u32 XDcfg_IntrGetStatus(XDcfg *InstancePtr)
188 * Assert the arguments.
190 Xil_AssertNonvoid(InstancePtr != NULL);
191 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
194 * Return the value read from the Interrupt Status register.
196 return XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
197 XDCFG_INT_STS_OFFSET);
200 /****************************************************************************/
203 * This function clears the specified interrupts in the Interrupt Status
206 * @param InstancePtr is a pointer to the XDcfg instance.
207 * @param Mask is the bit-mask of the interrupts to be cleared.
208 * Bit positions of 1 will be cleared. Bit positions of 0 will not
209 * change the previous interrupt status. This mask is formed by
210 * OR'ing XDCFG_INT_* bits which are defined in xdevcfg_hw.h.
216 *****************************************************************************/
217 void XDcfg_IntrClear(XDcfg *InstancePtr, u32 Mask)
220 * Assert the arguments.
222 Xil_AssertVoid(InstancePtr != NULL);
223 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
225 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
226 XDCFG_INT_STS_OFFSET,
231 /*****************************************************************************/
233 * The interrupt handler for the Device Config Interface.
235 * Events are signaled to upper layer for proper handling.
238 * @param InstancePtr is a pointer to the XDcfg instance.
244 ****************************************************************************/
245 void XDcfg_InterruptHandler(XDcfg *InstancePtr)
250 * Assert validates the input arguments.
252 Xil_AssertVoid(InstancePtr != NULL);
253 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
256 * Read the Interrupt status register.
258 IntrStatusReg = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
259 XDCFG_INT_STS_OFFSET);
262 * Write the status back to clear the interrupts so that no
263 * subsequent interrupts are missed while processing this interrupt.
264 * This also does the DMA acknowledgment automatically.
266 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
267 XDCFG_INT_STS_OFFSET, IntrStatusReg);
270 * Signal application that there are events to handle.
272 InstancePtr->StatusHandler(InstancePtr->CallBackRef,
277 /****************************************************************************/
280 * This function sets the handler that will be called when an event (interrupt)
281 * occurs that needs application's attention.
283 * @param InstancePtr is a pointer to the XDcfg instance
284 * @param CallBackFunc is the address of the callback function.
285 * @param CallBackRef is a user data item that will be passed to the
286 * callback function when it is invoked.
293 *****************************************************************************/
294 void XDcfg_SetHandler(XDcfg *InstancePtr, void *CallBackFunc,
298 * Asserts validate the input arguments
299 * CallBackRef not checked, no way to know what is valid
301 Xil_AssertVoid(InstancePtr != NULL);
302 Xil_AssertVoid(CallBackFunc != NULL);
303 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
305 InstancePtr->StatusHandler = (XDcfg_IntrHandler) CallBackFunc;
306 InstancePtr->CallBackRef = CallBackRef;