1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 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 xgpiops_intr.c
37 * This file contains functions related to GPIO interrupt handling.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00a sv 01/18/10 First Release
45 * 2.2 sk 10/13/14 Used Pin number in Bank instead of pin number
46 * passed to API's. CR# 822636
47 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
50 ******************************************************************************/
52 /***************************** Include Files *********************************/
56 /************************** Constant Definitions *****************************/
58 /**************************** Type Definitions *******************************/
60 /***************** Macros (Inline Functions) Definitions *********************/
62 /************************** Variable Definitions *****************************/
64 /************************** Function Prototypes ******************************/
66 void StubHandler(void *CallBackRef, u32 Bank, u32 Status);
68 /****************************************************************************/
71 * This function enables the interrupts for the specified pins in the specified
74 * @param InstancePtr is a pointer to the XGpioPs instance.
75 * @param Bank is the bank number of the GPIO to operate on.
76 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
77 * @param Mask is the bit mask of the pins for which interrupts are to
78 * be enabled. Bit positions of 1 will be enabled. Bit positions
79 * of 0 will keep the previous setting.
85 *****************************************************************************/
86 void XGpioPs_IntrEnable(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
88 Xil_AssertVoid(InstancePtr != NULL);
89 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
90 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
92 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
93 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
94 XGPIOPS_INTEN_OFFSET, Mask);
97 /****************************************************************************/
100 * This function enables the interrupt for the specified pin.
102 * @param InstancePtr is a pointer to the XGpioPs instance.
103 * @param Pin is the pin number for which the interrupt is to be enabled.
104 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
110 *****************************************************************************/
111 void XGpioPs_IntrEnablePin(XGpioPs *InstancePtr, u32 Pin)
117 Xil_AssertVoid(InstancePtr != NULL);
118 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
119 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
122 * Get the Bank number and Pin number within the bank.
124 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
126 IntrReg = ((u32)1 << (u32)PinNumber);
127 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
128 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
129 XGPIOPS_INTEN_OFFSET, IntrReg);
132 /****************************************************************************/
135 * This function disables the interrupts for the specified pins in the specified
138 * @param InstancePtr is a pointer to the XGpioPs instance.
139 * @param Bank is the bank number of the GPIO to operate on.
140 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
141 * @param Mask is the bit mask of the pins for which interrupts are
142 * to be disabled. Bit positions of 1 will be disabled. Bit
143 * positions of 0 will keep the previous setting.
149 *****************************************************************************/
150 void XGpioPs_IntrDisable(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
152 Xil_AssertVoid(InstancePtr != NULL);
153 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
154 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
156 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
157 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
158 XGPIOPS_INTDIS_OFFSET, Mask);
161 /****************************************************************************/
164 * This function disables the interrupts for the specified pin.
166 * @param InstancePtr is a pointer to the XGpioPs instance.
167 * @param Pin is the pin number for which the interrupt is to be disabled.
168 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
174 *****************************************************************************/
175 void XGpioPs_IntrDisablePin(XGpioPs *InstancePtr, u32 Pin)
181 Xil_AssertVoid(InstancePtr != NULL);
182 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
183 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
186 * Get the Bank number and Pin number within the bank.
188 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
190 IntrReg = ((u32)1 << (u32)PinNumber);
191 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
192 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
193 XGPIOPS_INTDIS_OFFSET, IntrReg);
196 /****************************************************************************/
199 * This function returns the interrupt enable status for a bank.
201 * @param InstancePtr is a pointer to the XGpioPs instance.
202 * @param Bank is the bank number of the GPIO to operate on.
203 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
205 * @return Enabled interrupt(s) in a 32-bit format. Bit positions with 1
206 * indicate that the interrupt for that pin is enabled, bit
207 * positions with 0 indicate that the interrupt for that pin is
212 *****************************************************************************/
213 u32 XGpioPs_IntrGetEnabled(XGpioPs *InstancePtr, u8 Bank)
217 Xil_AssertNonvoid(InstancePtr != NULL);
218 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
219 Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
221 IntrMask = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
222 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
223 XGPIOPS_INTMASK_OFFSET);
227 /****************************************************************************/
230 * This function returns whether interrupts are enabled for the specified pin.
232 * @param InstancePtr is a pointer to the XGpioPs instance.
233 * @param Pin is the pin number for which the interrupt enable status
235 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
238 * - TRUE if the interrupt is enabled.
239 * - FALSE if the interrupt is disabled.
243 *****************************************************************************/
244 u32 XGpioPs_IntrGetEnabledPin(XGpioPs *InstancePtr, u32 Pin)
250 Xil_AssertNonvoid(InstancePtr != NULL);
251 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
252 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
255 * Get the Bank number and Pin number within the bank.
257 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
259 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
260 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
261 XGPIOPS_INTMASK_OFFSET);
263 return (((IntrReg & ((u32)1 << PinNumber)) != (u32)0)? FALSE : TRUE);
266 /****************************************************************************/
269 * This function returns interrupt status read from Interrupt Status Register.
271 * @param InstancePtr is a pointer to the XGpioPs instance.
272 * @param Bank is the bank number of the GPIO to operate on.
273 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
275 * @return The value read from Interrupt Status Register.
279 *****************************************************************************/
280 u32 XGpioPs_IntrGetStatus(XGpioPs *InstancePtr, u8 Bank)
282 Xil_AssertNonvoid(InstancePtr != NULL);
283 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
284 Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
286 return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
287 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
288 XGPIOPS_INTSTS_OFFSET);
291 /****************************************************************************/
294 * This function returns interrupt enable status of the specified pin.
296 * @param InstancePtr is a pointer to the XGpioPs instance.
297 * @param Pin is the pin number for which the interrupt enable status
299 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
302 * - TRUE if the interrupt has occurred.
303 * - FALSE if the interrupt has not occurred.
307 *****************************************************************************/
308 u32 XGpioPs_IntrGetStatusPin(XGpioPs *InstancePtr, u32 Pin)
314 Xil_AssertNonvoid(InstancePtr != NULL);
315 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
316 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
319 * Get the Bank number and Pin number within the bank.
321 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
323 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
324 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
325 XGPIOPS_INTSTS_OFFSET);
327 return (((IntrReg & ((u32)1 << PinNumber)) != (u32)0)? TRUE : FALSE);
330 /****************************************************************************/
333 * This function clears pending interrupt(s) with the provided mask. This
334 * function should be called after the software has serviced the interrupts
337 * @param InstancePtr is a pointer to the XGpioPs instance.
338 * @param Bank is the bank number of the GPIO to operate on.
339 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
340 * @param Mask is the mask of the interrupts to be cleared. Bit positions
341 * of 1 will be cleared. Bit positions of 0 will not change the
342 * previous interrupt status.
346 *****************************************************************************/
347 void XGpioPs_IntrClear(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
349 Xil_AssertVoid(InstancePtr != NULL);
350 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
351 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
354 * Clear the currently pending interrupts.
356 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
357 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
358 XGPIOPS_INTSTS_OFFSET, Mask);
361 /****************************************************************************/
364 * This function clears the specified pending interrupt. This function should be
365 * called after the software has serviced the interrupts that are pending.
367 * @param InstancePtr is a pointer to the XGpioPs instance.
368 * @param Pin is the pin number for which the interrupt status is to be
369 * cleared. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
373 *****************************************************************************/
374 void XGpioPs_IntrClearPin(XGpioPs *InstancePtr, u32 Pin)
380 Xil_AssertVoid(InstancePtr != NULL);
381 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
382 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
385 * Get the Bank number and Pin number within the bank.
387 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
390 * Clear the specified pending interrupts.
392 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
393 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
394 XGPIOPS_INTSTS_OFFSET);
396 IntrReg &= ((u32)1 << PinNumber);
397 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
398 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
399 XGPIOPS_INTSTS_OFFSET, IntrReg);
402 /****************************************************************************/
405 * This function is used for setting the Interrupt Type, Interrupt Polarity and
406 * Interrupt On Any for the specified GPIO Bank pins.
408 * @param InstancePtr is a pointer to an XGpioPs instance.
409 * @param Bank is the bank number of the GPIO to operate on.
410 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
411 * @param IntrType is the 32 bit mask of the interrupt type.
412 * 0 means Level Sensitive and 1 means Edge Sensitive.
413 * @param IntrPolarity is the 32 bit mask of the interrupt polarity.
414 * 0 means Active Low or Falling Edge and 1 means Active High or
416 * @param IntrOnAny is the 32 bit mask of the interrupt trigger for
417 * edge triggered interrupts. 0 means trigger on single edge using
418 * the configured interrupt polarity and 1 means trigger on both
423 * @note This function is used for setting the interrupt related
424 * properties of all the pins in the specified bank. The previous
425 * state of the pins is not maintained.
426 * To change the Interrupt properties of a single GPIO pin, use the
427 * function XGpioPs_SetPinIntrType().
429 *****************************************************************************/
430 void XGpioPs_SetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 IntrType,
431 u32 IntrPolarity, u32 IntrOnAny)
433 Xil_AssertVoid(InstancePtr != NULL);
434 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
435 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
437 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
438 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
439 XGPIOPS_INTTYPE_OFFSET, IntrType);
441 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
442 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
443 XGPIOPS_INTPOL_OFFSET, IntrPolarity);
445 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
446 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
447 XGPIOPS_INTANY_OFFSET, IntrOnAny);
450 /****************************************************************************/
453 * This function is used for getting the Interrupt Type, Interrupt Polarity and
454 * Interrupt On Any for the specified GPIO Bank pins.
456 * @param InstancePtr is a pointer to an XGpioPs instance.
457 * @param Bank is the bank number of the GPIO to operate on.
458 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
459 * @param IntrType returns the 32 bit mask of the interrupt type.
460 * 0 means Level Sensitive and 1 means Edge Sensitive.
461 * @param IntrPolarity returns the 32 bit mask of the interrupt
462 * polarity. 0 means Active Low or Falling Edge and 1 means
463 * Active High or Rising Edge.
464 * @param IntrOnAny returns the 32 bit mask of the interrupt trigger for
465 * edge triggered interrupts. 0 means trigger on single edge using
466 * the configured interrupt polarity and 1 means trigger on both
473 *****************************************************************************/
474 void XGpioPs_GetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 *IntrType,
475 u32 *IntrPolarity, u32 *IntrOnAny)
478 Xil_AssertVoid(InstancePtr != NULL);
479 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
480 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
482 *IntrType = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
483 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
484 XGPIOPS_INTTYPE_OFFSET);
486 *IntrPolarity = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
487 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
488 XGPIOPS_INTPOL_OFFSET);
490 *IntrOnAny = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
491 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
492 XGPIOPS_INTANY_OFFSET);
495 /****************************************************************************/
498 * This function is used for setting the IRQ Type of a single GPIO pin.
500 * @param InstancePtr is a pointer to an XGpioPs instance.
501 * @param Pin is the pin number whose IRQ type is to be set.
502 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
503 * @param IrqType is the IRQ type for GPIO Pin. Use XGPIOPS_IRQ_TYPE_*
504 * defined in xgpiops.h to specify the IRQ type.
510 *****************************************************************************/
511 void XGpioPs_SetIntrTypePin(XGpioPs *InstancePtr, u32 Pin, u8 IrqType)
519 Xil_AssertVoid(InstancePtr != NULL);
520 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
521 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
522 Xil_AssertVoid(IrqType <= XGPIOPS_IRQ_TYPE_LEVEL_LOW);
525 * Get the Bank number and Pin number within the bank.
527 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
529 IntrTypeReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
530 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
531 XGPIOPS_INTTYPE_OFFSET);
533 IntrPolReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
534 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
535 XGPIOPS_INTPOL_OFFSET);
537 IntrOnAnyReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
538 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
539 XGPIOPS_INTANY_OFFSET);
542 case XGPIOPS_IRQ_TYPE_EDGE_RISING:
543 IntrTypeReg |= ((u32)1 << (u32)PinNumber);
544 IntrPolReg |= ((u32)1 << (u32)PinNumber);
545 IntrOnAnyReg &= ~((u32)1 << (u32)PinNumber);
547 case XGPIOPS_IRQ_TYPE_EDGE_FALLING:
548 IntrTypeReg |= ((u32)1 << (u32)PinNumber);
549 IntrPolReg &= ~((u32)1 << (u32)PinNumber);
550 IntrOnAnyReg &= ~((u32)1 << (u32)PinNumber);
552 case XGPIOPS_IRQ_TYPE_EDGE_BOTH:
553 IntrTypeReg |= ((u32)1 << (u32)PinNumber);
554 IntrOnAnyReg |= ((u32)1 << (u32)PinNumber);
556 case XGPIOPS_IRQ_TYPE_LEVEL_HIGH:
557 IntrTypeReg &= ~((u32)1 << (u32)PinNumber);
558 IntrPolReg |= ((u32)1 << (u32)PinNumber);
560 case XGPIOPS_IRQ_TYPE_LEVEL_LOW:
561 IntrTypeReg &= ~((u32)1 << (u32)PinNumber);
562 IntrPolReg &= ~((u32)1 << (u32)PinNumber);
565 /**< Default statement is added for MISRA C compliance. */
569 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
570 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
571 XGPIOPS_INTTYPE_OFFSET, IntrTypeReg);
573 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
574 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
575 XGPIOPS_INTPOL_OFFSET, IntrPolReg);
577 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
578 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
579 XGPIOPS_INTANY_OFFSET, IntrOnAnyReg);
582 /****************************************************************************/
585 * This function returns the IRQ Type of a given GPIO pin.
587 * @param InstancePtr is a pointer to an XGpioPs instance.
588 * @param Pin is the pin number whose IRQ type is to be obtained.
589 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
593 * @note Use XGPIOPS_IRQ_TYPE_* defined in xgpiops.h for the IRQ type
594 * returned by this function.
596 *****************************************************************************/
597 u8 XGpioPs_GetIntrTypePin(XGpioPs *InstancePtr, u32 Pin)
606 Xil_AssertNonvoid(InstancePtr != NULL);
607 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
608 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
611 * Get the Bank number and Pin number within the bank.
613 XGpioPs_GetBankPin((u8)Pin, &Bank, &PinNumber);
615 IntrType = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
616 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
617 XGPIOPS_INTTYPE_OFFSET) & ((u32)1 << PinNumber);
619 if (IntrType == ((u32)1 << PinNumber)) {
621 IntrOnAny = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
622 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
623 XGPIOPS_INTANY_OFFSET) & ((u32)1 << PinNumber);
625 IntrPol = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
626 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
627 XGPIOPS_INTPOL_OFFSET) & ((u32)1 << PinNumber);
630 if (IntrOnAny == ((u32)1 << PinNumber)) {
631 IrqType = XGPIOPS_IRQ_TYPE_EDGE_BOTH;
632 } else if (IntrPol == ((u32)1 << PinNumber)) {
633 IrqType = XGPIOPS_IRQ_TYPE_EDGE_RISING;
635 IrqType = XGPIOPS_IRQ_TYPE_EDGE_FALLING;
639 IntrPol = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
640 ((u32)(Bank) * XGPIOPS_REG_MASK_OFFSET) +
641 XGPIOPS_INTPOL_OFFSET) & ((u32)1 << PinNumber);
643 if (IntrPol == ((u32)1 << PinNumber)) {
644 IrqType = XGPIOPS_IRQ_TYPE_LEVEL_HIGH;
646 IrqType = XGPIOPS_IRQ_TYPE_LEVEL_LOW;
653 /*****************************************************************************/
656 * This function sets the status callback function. The callback function is
657 * called by the XGpioPs_IntrHandler when an interrupt occurs.
659 * @param InstancePtr is a pointer to the XGpioPs instance.
660 * @param CallBackRef is the upper layer callback reference passed back
661 * when the callback function is invoked.
662 * @param FuncPtr is the pointer to the callback function.
667 * @note The handler is called within interrupt context, so it should do
668 * its work quickly and queue potentially time-consuming work to a
671 ******************************************************************************/
672 void XGpioPs_SetCallbackHandler(XGpioPs *InstancePtr, void *CallBackRef,
673 XGpioPs_Handler FuncPointer)
675 Xil_AssertVoid(InstancePtr != NULL);
676 Xil_AssertVoid(FuncPointer != NULL);
677 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
679 InstancePtr->Handler = FuncPointer;
680 InstancePtr->CallBackRef = CallBackRef;
683 /*****************************************************************************/
686 * This function is the interrupt handler for GPIO interrupts.It checks the
687 * interrupt status registers of all the banks to determine the actual bank in
688 * which an interrupt has been triggered. It then calls the upper layer callback
689 * handler set by the function XGpioPs_SetBankHandler(). The callback is called
692 * @param InstancePtr is a pointer to the XGpioPs instance.
696 * @note This function does not save and restore the processor context
697 * such that the user must provide this processing.
699 ******************************************************************************/
700 void XGpioPs_IntrHandler(XGpioPs *InstancePtr)
706 Xil_AssertVoid(InstancePtr != NULL);
707 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
709 for (Bank = 0U; Bank < XGPIOPS_MAX_BANKS; Bank++) {
710 IntrStatus = XGpioPs_IntrGetStatus(InstancePtr, Bank);
711 if (IntrStatus != (u32)0) {
712 IntrEnabled = XGpioPs_IntrGetEnabled(InstancePtr,
714 XGpioPs_IntrClear((XGpioPs *)InstancePtr, Bank,
715 (IntrStatus & IntrEnabled));
716 InstancePtr->Handler(InstancePtr->
718 (IntrStatus & IntrEnabled));
723 /*****************************************************************************/
726 * This is a stub for the status callback. The stub is here in case the upper
727 * layers do not set the handler.
729 * @param CallBackRef is a pointer to the upper layer callback reference
730 * @param Bank is the GPIO Bank in which an interrupt occurred.
731 * @param Status is the Interrupt status of the GPIO bank.
737 ******************************************************************************/
738 void StubHandler(void *CallBackRef, u32 Bank, u32 Status)
744 Xil_AssertVoidAlways();