]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/devcfg_v3_1/src/xdevcfg_intr.c
FreeRTOS source updates:
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / devcfg_v3_1 / src / xdevcfg_intr.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 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 xdevcfg_intr.c
36 * @addtogroup devcfg_v3_1
37 * @{
38 *
39 * Contains the implementation of interrupt related functions of the XDcfg
40 * driver.
41 *
42 * <pre>
43 * MODIFICATION HISTORY:
44 *
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
51 * </pre>
52 *
53 ******************************************************************************/
54
55 /***************************** Include Files *********************************/
56
57 #include "xdevcfg.h"
58
59 /************************** Constant Definitions *****************************/
60
61 /**************************** Type Definitions *******************************/
62
63 /***************** Macros (Inline Functions) Definitions *********************/
64
65 /************************** Function Prototypes ******************************/
66
67 /************************** Variable Definitions *****************************/
68
69 /****************************************************************************/
70 /**
71 *
72 * This function enables the specified interrupts in the device.
73 *
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.
79 *
80 * @return       None.
81 *
82 * @note         None.
83 *
84 *****************************************************************************/
85 void XDcfg_IntrEnable(XDcfg *InstancePtr, u32 Mask)
86 {
87         u32 RegValue;
88
89         /*
90          * Assert the arguments.
91          */
92         Xil_AssertVoid(InstancePtr != NULL);
93         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
94
95         /*
96          * Enable the specified interrupts in the Interrupt Mask Register.
97          */
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,
103                                 RegValue);
104 }
105
106
107 /****************************************************************************/
108 /**
109 *
110 * This function disables the specified interrupts in the device.
111 *
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.
117 *
118 * @return       None.
119 *
120 * @note         None.
121 *
122 *****************************************************************************/
123 void XDcfg_IntrDisable(XDcfg *InstancePtr, u32 Mask)
124 {
125         u32 RegValue;
126
127         /*
128          * Assert the arguments.
129          */
130         Xil_AssertVoid(InstancePtr != NULL);
131         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
132
133         /*
134          * Disable the specified interrupts in the Interrupt Mask Register.
135          */
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,
141                                 RegValue);
142 }
143 /****************************************************************************/
144 /**
145 *
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.
149 *
150 * @param        InstancePtr is a pointer to the XDcfg instance.
151 *
152 * @return       A 32-bit value representing the contents of the IMR.
153 *
154 * @note         None.
155 *
156 *****************************************************************************/
157 u32 XDcfg_IntrGetEnabled(XDcfg *InstancePtr)
158 {
159         /*
160          * Assert the arguments.
161          */
162         Xil_AssertNonvoid(InstancePtr != NULL);
163         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
164
165         /*
166          * Return the value read from the Interrupt Mask Register.
167          */
168         return (~ XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
169                                 XDCFG_INT_MASK_OFFSET));
170 }
171
172 /****************************************************************************/
173 /**
174 *
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.
178 *
179 * @param        InstancePtr is a pointer to the XDcfg instance.
180 *
181 * @return       A 32-bit value representing the contents of the Interrupt
182 *               Status register.
183 *
184 * @note         None.
185 *
186 *****************************************************************************/
187 u32 XDcfg_IntrGetStatus(XDcfg *InstancePtr)
188 {
189         /*
190          * Assert the arguments.
191          */
192         Xil_AssertNonvoid(InstancePtr != NULL);
193         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
194
195         /*
196          * Return the value read from the Interrupt Status register.
197          */
198         return XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
199                                 XDCFG_INT_STS_OFFSET);
200 }
201
202 /****************************************************************************/
203 /**
204 *
205 * This function clears the specified interrupts in the Interrupt Status
206 * Register.
207 *
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.
213 *
214 * @return       None.
215 *
216 * @note         None.
217 *
218 *****************************************************************************/
219 void XDcfg_IntrClear(XDcfg *InstancePtr, u32 Mask)
220 {
221         /*
222          * Assert the arguments.
223          */
224         Xil_AssertVoid(InstancePtr != NULL);
225         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
226
227         XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
228                                 XDCFG_INT_STS_OFFSET,
229                                 Mask);
230
231 }
232
233 /*****************************************************************************/
234 /**
235 * The interrupt handler for the Device Config Interface.
236 *
237 * Events are signaled to upper layer for proper handling.
238 *
239 *
240 * @param        InstancePtr is a pointer to the XDcfg instance.
241 *
242 * @return       None.
243 *
244 * @note         None.
245 *
246 ****************************************************************************/
247 void XDcfg_InterruptHandler(XDcfg *InstancePtr)
248 {
249         u32 IntrStatusReg;
250
251         /*
252          * Assert validates the input arguments.
253          */
254         Xil_AssertVoid(InstancePtr != NULL);
255         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
256
257         /*
258          * Read the Interrupt status register.
259          */
260         IntrStatusReg = XDcfg_ReadReg(InstancePtr->Config.BaseAddr,
261                                          XDCFG_INT_STS_OFFSET);
262
263         /*
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.
267          */
268         XDcfg_WriteReg(InstancePtr->Config.BaseAddr,
269                                 XDCFG_INT_STS_OFFSET, IntrStatusReg);
270
271         /*
272          * Signal application that there are events to handle.
273          */
274         InstancePtr->StatusHandler(InstancePtr->CallBackRef,
275                                            IntrStatusReg);
276
277 }
278
279 /****************************************************************************/
280 /**
281 *
282 * This function sets the handler that will be called when an event (interrupt)
283 * occurs that needs application's attention.
284 *
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.
289 *
290 * @return       None.
291 *
292 * @note         None.
293 *
294 *
295 *****************************************************************************/
296 void XDcfg_SetHandler(XDcfg *InstancePtr, void *CallBackFunc,
297                                 void *CallBackRef)
298 {
299         /*
300          * Asserts validate the input arguments
301          * CallBackRef not checked, no way to know what is valid
302          */
303         Xil_AssertVoid(InstancePtr != NULL);
304         Xil_AssertVoid(CallBackFunc != NULL);
305         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
306
307         InstancePtr->StatusHandler = (XDcfg_IntrHandler) CallBackFunc;
308         InstancePtr->CallBackRef = CallBackRef;
309 }
310 /** @} */