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
36 * @addtogroup devcfg_v3_1
39 * Contains the implementation of interrupt related functions of the XDcfg
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- --- -------- ---------------------------------------------
47 * 1.00a hvm 02/07/11 First release
48 * 2.01a nm 07/07/12 Updated the XDcfg_IntrClear function to directly
49 * set the mask instead of oring it with the
50 * value read from the interrupt status register
53 ******************************************************************************/
55 /***************************** Include Files *********************************/
59 /************************** Constant Definitions *****************************/
61 /**************************** Type Definitions *******************************/
63 /***************** Macros (Inline Functions) Definitions *********************/
65 /************************** Function Prototypes ******************************/
67 /************************** Variable Definitions *****************************/
69 /****************************************************************************/
72 * This function enables the specified interrupts in the device.
74 * @param InstancePtr is a pointer to the XDcfg instance.
75 * @param Mask is the bit-mask of the interrupts to be enabled.
76 * Bit positions of 1 will be enabled. Bit positions of 0 will
77 * keep the previous setting. This mask is formed by OR'ing
78 * XDCFG_INT_* bits defined in xdevcfg_hw.h.
84 *****************************************************************************/
85 void XDcfg_IntrEnable(XDcfg *InstancePtr, u32 Mask)
90 * Assert the arguments.
92 Xil_AssertVoid(InstancePtr != NULL);
93 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
96 * Enable the specified interrupts in the Interrupt Mask Register.
98 RegValue = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
99 XDCFG_INT_MASK_OFFSET);
100 RegValue &= ~(Mask & XDCFG_IXR_ALL_MASK);
101 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
102 XDCFG_INT_MASK_OFFSET,
107 /****************************************************************************/
110 * This function disables the specified interrupts in the device.
112 * @param InstancePtr is a pointer to the XDcfg instance.
113 * @param Mask is the bit-mask of the interrupts to be disabled.
114 * Bit positions of 1 will be disabled. Bit positions of 0 will
115 * keep the previous setting. This mask is formed by OR'ing
116 * XDCFG_INT_* bits defined in xdevcfg_hw.h.
122 *****************************************************************************/
123 void XDcfg_IntrDisable(XDcfg *InstancePtr, u32 Mask)
128 * Assert the arguments.
130 Xil_AssertVoid(InstancePtr != NULL);
131 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
134 * Disable the specified interrupts in the Interrupt Mask Register.
136 RegValue = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
137 XDCFG_INT_MASK_OFFSET);
138 RegValue |= (Mask & XDCFG_IXR_ALL_MASK);
139 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
140 XDCFG_INT_MASK_OFFSET,
143 /****************************************************************************/
146 * This function returns the enabled interrupts read from the Interrupt Mask
147 * Register. Use the XDCFG_INT_* constants defined in xdevcfg_hw.h
148 * to interpret the returned value.
150 * @param InstancePtr is a pointer to the XDcfg instance.
152 * @return A 32-bit value representing the contents of the IMR.
156 *****************************************************************************/
157 u32 XDcfg_IntrGetEnabled(XDcfg *InstancePtr)
160 * Assert the arguments.
162 Xil_AssertNonvoid(InstancePtr != NULL);
163 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
166 * Return the value read from the Interrupt Mask Register.
168 return (~ XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
169 XDCFG_INT_MASK_OFFSET));
172 /****************************************************************************/
175 * This function returns the interrupt status read from Interrupt Status
176 * Register. Use the XDCFG_INT_* constants defined in xdevcfg_hw.h
177 * to interpret the returned value.
179 * @param InstancePtr is a pointer to the XDcfg instance.
181 * @return A 32-bit value representing the contents of the Interrupt
186 *****************************************************************************/
187 u32 XDcfg_IntrGetStatus(XDcfg *InstancePtr)
190 * Assert the arguments.
192 Xil_AssertNonvoid(InstancePtr != NULL);
193 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
196 * Return the value read from the Interrupt Status register.
198 return XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
199 XDCFG_INT_STS_OFFSET);
202 /****************************************************************************/
205 * This function clears the specified interrupts in the Interrupt Status
208 * @param InstancePtr is a pointer to the XDcfg instance.
209 * @param Mask is the bit-mask of the interrupts to be cleared.
210 * Bit positions of 1 will be cleared. Bit positions of 0 will not
211 * change the previous interrupt status. This mask is formed by
212 * OR'ing XDCFG_INT_* bits which are defined in xdevcfg_hw.h.
218 *****************************************************************************/
219 void XDcfg_IntrClear(XDcfg *InstancePtr, u32 Mask)
222 * Assert the arguments.
224 Xil_AssertVoid(InstancePtr != NULL);
225 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
227 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
228 XDCFG_INT_STS_OFFSET,
233 /*****************************************************************************/
235 * The interrupt handler for the Device Config Interface.
237 * Events are signaled to upper layer for proper handling.
240 * @param InstancePtr is a pointer to the XDcfg instance.
246 ****************************************************************************/
247 void XDcfg_InterruptHandler(XDcfg *InstancePtr)
252 * Assert validates the input arguments.
254 Xil_AssertVoid(InstancePtr != NULL);
255 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
258 * Read the Interrupt status register.
260 IntrStatusReg = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
261 XDCFG_INT_STS_OFFSET);
264 * Write the status back to clear the interrupts so that no
265 * subsequent interrupts are missed while processing this interrupt.
266 * This also does the DMA acknowledgment automatically.
268 XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
269 XDCFG_INT_STS_OFFSET, IntrStatusReg);
272 * Signal application that there are events to handle.
274 InstancePtr->StatusHandler(InstancePtr->CallBackRef,
279 /****************************************************************************/
282 * This function sets the handler that will be called when an event (interrupt)
283 * occurs that needs application's attention.
285 * @param InstancePtr is a pointer to the XDcfg instance
286 * @param CallBackFunc is the address of the callback function.
287 * @param CallBackRef is a user data item that will be passed to the
288 * callback function when it is invoked.
295 *****************************************************************************/
296 void XDcfg_SetHandler(XDcfg *InstancePtr, void *CallBackFunc,
300 * Asserts validate the input arguments
301 * CallBackRef not checked, no way to know what is valid
303 Xil_AssertVoid(InstancePtr != NULL);
304 Xil_AssertVoid(CallBackFunc != NULL);
305 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
307 InstancePtr->StatusHandler = (XDcfg_IntrHandler) CallBackFunc;
308 InstancePtr->CallBackRef = CallBackRef;