]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/gpio_v4_0/src/xgpio_intr.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / gpio_v4_0 / src / xgpio_intr.c
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 * @file xgpio_intr.c
35 *
36 * Implements GPIO interrupt processing functions for the XGpio driver.
37 * See xgpio.h for more information about the driver.
38 *
39 * The functions in this file require the hardware device to be built with
40 * interrupt capabilities. The functions will assert if called using hardware
41 * that does not have interrupt capabilities.
42 *
43 * <pre>
44 * MODIFICATION HISTORY:
45 *
46 * Ver   Who  Date     Changes
47 * ----- ---- -------- -----------------------------------------------
48 * 2.00a jhl  11/26/03 Initial release
49 * 2.11a mta  03/21/07 Updated to new coding style
50 * 2.12a sv   06/05/08 Updated driver to fix the XGpio_InterruptDisable function
51 *                     to properly update the Interrupt Enable register
52 * 3.00a sv   11/21/09 Updated to use HAL Processor APIs. Renamed the macros
53 *                     XGpio_mWriteReg to XGpio_WriteReg, and XGpio_mReadReg
54 *                     to XGpio_ReadReg.
55
56 * </pre>
57 *
58 *****************************************************************************/
59
60 /***************************** Include Files ********************************/
61 #include "xgpio.h"
62
63
64 /************************** Constant Definitions ****************************/
65
66 /**************************** Type Definitions ******************************/
67
68 /***************** Macros (Inline Functions) Definitions ********************/
69
70 /************************** Variable Definitions ****************************/
71
72 /************************** Function Prototypes *****************************/
73
74
75 /****************************************************************************/
76 /**
77 * Enable the interrupt output signal. Interrupts enabled through
78 * XGpio_InterruptEnable() will not be passed through until the global enable
79 * bit is set by this function. This function is designed to allow all
80 * interrupts (both channels) to be enabled easily for exiting a critical
81 * section. This function will assert if the hardware device has not been
82 * built with interrupt capabilities.
83 *
84 * @param        InstancePtr is the GPIO instance to operate on.
85 *
86 * @return       None.
87 *
88 * @note         None.
89 *
90 *****************************************************************************/
91 void XGpio_InterruptGlobalEnable(XGpio * InstancePtr)
92 {
93         Xil_AssertVoid(InstancePtr != NULL);
94         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
95         Xil_AssertVoid(InstancePtr->InterruptPresent == TRUE);
96
97         XGpio_WriteReg(InstancePtr->BaseAddress, XGPIO_GIE_OFFSET,
98                         XGPIO_GIE_GINTR_ENABLE_MASK);
99 }
100
101
102 /****************************************************************************/
103 /**
104 * Disable the interrupt output signal. Interrupts enabled through
105 * XGpio_InterruptEnable() will no longer be passed through until the global
106 * enable bit is set by XGpio_InterruptGlobalEnable(). This function is
107 * designed to allow all interrupts (both channels) to be disabled easily for
108 * entering a critical section. This function will assert if the hardware
109 * device has not been built with interrupt capabilities.
110 *
111 * @param        InstancePtr is the GPIO instance to operate on.
112 *
113 * @return       None.
114 *
115 * @note         None.
116 *
117 *****************************************************************************/
118 void XGpio_InterruptGlobalDisable(XGpio * InstancePtr)
119 {
120         Xil_AssertVoid(InstancePtr != NULL);
121         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
122         Xil_AssertVoid(InstancePtr->InterruptPresent == TRUE);
123
124
125         XGpio_WriteReg(InstancePtr->BaseAddress, XGPIO_GIE_OFFSET, 0x0);
126
127 }
128
129
130 /****************************************************************************/
131 /**
132 * Enable interrupts. The global interrupt must also be enabled by calling
133 * XGpio_InterruptGlobalEnable() for interrupts to occur. This function will
134 * assert if the hardware device has not been built with interrupt capabilities.
135 *
136 * @param        InstancePtr is the GPIO instance to operate on.
137 * @param        Mask is the mask to enable. Bit positions of 1 are enabled.
138 *               This mask is formed by OR'ing bits from XGPIO_IR* bits which
139 *               are contained in xgpio_l.h.
140 *
141 * @return       None.
142 *
143 * @note         None.
144 *
145 *****************************************************************************/
146 void XGpio_InterruptEnable(XGpio * InstancePtr, u32 Mask)
147 {
148         u32 Register;
149
150         Xil_AssertVoid(InstancePtr != NULL);
151         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
152         Xil_AssertVoid(InstancePtr->InterruptPresent == TRUE);
153
154         /*
155          * Read the interrupt enable register and only enable the specified
156          * interrupts without disabling or enabling any others.
157          */
158
159         Register = XGpio_ReadReg(InstancePtr->BaseAddress, XGPIO_IER_OFFSET);
160         XGpio_WriteReg(InstancePtr->BaseAddress, XGPIO_IER_OFFSET,
161                         Register | Mask);
162
163 }
164
165
166 /****************************************************************************/
167 /**
168 * Disable interrupts. This function allows specific interrupts for each
169 * channel to be disabled. This function will assert if the hardware device
170 * has not been built with interrupt capabilities.
171 *
172 * @param        InstancePtr is the GPIO instance to operate on.
173 * @param        Mask is the mask to disable. Bits set to 1 are disabled. This
174 *               mask is formed by OR'ing bits from XGPIO_IR* bits which are
175 *               contained in xgpio_l.h.
176 *
177 * @return       None.
178 *
179 * @note         None.
180 *
181 *****************************************************************************/
182 void XGpio_InterruptDisable(XGpio * InstancePtr, u32 Mask)
183 {
184         u32 Register;
185
186         Xil_AssertVoid(InstancePtr != NULL);
187         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
188         Xil_AssertVoid(InstancePtr->InterruptPresent == TRUE);
189
190         /*
191          * Read the interrupt enable register and only disable the specified
192          * interrupts without enabling or disabling any others.
193          */
194         Register = XGpio_ReadReg(InstancePtr->BaseAddress, XGPIO_IER_OFFSET);
195         XGpio_WriteReg(InstancePtr->BaseAddress, XGPIO_IER_OFFSET,
196                         Register & (~Mask));
197
198 }
199
200 /****************************************************************************/
201 /**
202 * Clear pending interrupts with the provided mask. This function should be
203 * called after the software has serviced the interrupts that are pending.
204 * This function will assert if the hardware device has not been built with
205 * interrupt capabilities.
206 *
207 * @param        InstancePtr is the GPIO instance to operate on.
208 * @param        Mask is the mask to clear pending interrupts for. Bit positions
209 *               of 1 are cleared. This mask is formed by OR'ing bits from
210 *               XGPIO_IR* bits which are contained in xgpio_l.h.
211 *
212 * @return       None.
213 *
214 * @note         None.
215 *
216 *****************************************************************************/
217 void XGpio_InterruptClear(XGpio * InstancePtr, u32 Mask)
218 {
219         u32 Register;
220
221         Xil_AssertVoid(InstancePtr != NULL);
222         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
223         Xil_AssertVoid(InstancePtr->InterruptPresent == TRUE);
224
225         /*
226          * Read the interrupt status register and only clear the interrupts
227          * that are specified without affecting any others.  Since the register
228          * is a toggle on write, make sure any bits to be written are already
229          * set.
230          */
231         Register = XGpio_ReadReg(InstancePtr->BaseAddress, XGPIO_ISR_OFFSET);
232         XGpio_WriteReg(InstancePtr->BaseAddress, XGPIO_ISR_OFFSET,
233                         Register & Mask);
234
235
236 }
237
238
239 /****************************************************************************/
240 /**
241 * Returns the interrupt enable mask. This function will assert if the
242 * hardware device has not been built with interrupt capabilities.
243 *
244 * @param        InstancePtr is the GPIO instance to operate on.
245 *
246 * @return       A mask of bits made from XGPIO_IR* bits which are contained in
247 *               xgpio_l.h.
248 *
249 * @return       None.
250 *
251 * @note         None.
252 *
253 *****************************************************************************/
254 u32 XGpio_InterruptGetEnabled(XGpio * InstancePtr)
255 {
256         Xil_AssertNonvoid(InstancePtr != NULL);
257         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
258         Xil_AssertNonvoid(InstancePtr->InterruptPresent == TRUE);
259
260         return XGpio_ReadReg(InstancePtr->BaseAddress, XGPIO_IER_OFFSET);
261 }
262
263
264 /****************************************************************************/
265 /**
266 * Returns the status of interrupt signals. Any bit in the mask set to 1
267 * indicates that the channel associated with the bit has asserted an interrupt
268 * condition. This function will assert if the hardware device has not been
269 * built with interrupt capabilities.
270 *
271 * @param        InstancePtr is the GPIO instance to operate on.
272 *
273 * @return       A pointer to a mask of bits made from XGPIO_IR* bits which are
274 *                contained in xgpio_l.h.
275 *
276 * @note
277 *
278 * The interrupt status indicates the status of the device irregardless if
279 * the interrupts from the devices have been enabled or not through
280 * XGpio_InterruptEnable().
281 *
282 *****************************************************************************/
283 u32 XGpio_InterruptGetStatus(XGpio * InstancePtr)
284 {
285         Xil_AssertNonvoid(InstancePtr != NULL);
286         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
287         Xil_AssertNonvoid(InstancePtr->InterruptPresent == TRUE);
288
289
290         return XGpio_ReadReg(InstancePtr->BaseAddress, XGPIO_ISR_OFFSET);
291 }