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 xgpiops_intr.c
36 * @addtogroup gpiops_v2_1
39 * This file contains functions related to GPIO interrupt handling.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -----------------------------------------------
46 * 1.00a sv 01/18/10 First Release
49 ******************************************************************************/
51 /***************************** Include Files *********************************/
55 /************************** Constant Definitions *****************************/
57 /**************************** Type Definitions *******************************/
59 /***************** Macros (Inline Functions) Definitions *********************/
61 /************************** Variable Definitions *****************************/
63 /************************** Function Prototypes ******************************/
65 void StubHandler(void *CallBackRef, int Bank, u32 Status);
67 /****************************************************************************/
70 * This function enables the interrupts for the specified pins in the specified
73 * @param InstancePtr is a pointer to the XGpioPs instance.
74 * @param Bank is the bank number of the GPIO to operate on.
75 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
76 * @param Mask is the bit mask of the pins for which interrupts are to
77 * be enabled. Bit positions of 1 will be enabled. Bit positions
78 * of 0 will keep the previous setting.
84 *****************************************************************************/
85 void XGpioPs_IntrEnable(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
87 Xil_AssertVoid(InstancePtr != NULL);
88 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
89 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
91 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
92 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
93 XGPIOPS_INTEN_OFFSET, Mask);
96 /****************************************************************************/
99 * This function enables the interrupt for the specified pin.
101 * @param InstancePtr is a pointer to the XGpioPs instance.
102 * @param Pin is the pin number for which the interrupt is to be enabled.
103 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
109 *****************************************************************************/
110 void XGpioPs_IntrEnablePin(XGpioPs *InstancePtr, int Pin)
116 Xil_AssertVoid(InstancePtr != NULL);
117 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
118 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
121 * Get the Bank number and Pin number within the bank.
123 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
125 IntrReg = 1 << PinNumber;
126 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
127 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
128 XGPIOPS_INTEN_OFFSET, IntrReg);
131 /****************************************************************************/
134 * This function disables the interrupts for the specified pins in the specified
137 * @param InstancePtr is a pointer to the XGpioPs instance.
138 * @param Bank is the bank number of the GPIO to operate on.
139 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
140 * @param Mask is the bit mask of the pins for which interrupts are
141 * to be disabled. Bit positions of 1 will be disabled. Bit
142 * positions of 0 will keep the previous setting.
148 *****************************************************************************/
149 void XGpioPs_IntrDisable(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
151 Xil_AssertVoid(InstancePtr != NULL);
152 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
153 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
155 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
156 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
157 XGPIOPS_INTDIS_OFFSET, Mask);
160 /****************************************************************************/
163 * This function disables the interrupts for the specified pin.
165 * @param InstancePtr is a pointer to the XGpioPs instance.
166 * @param Pin is the pin number for which the interrupt is to be disabled.
167 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
173 *****************************************************************************/
174 void XGpioPs_IntrDisablePin(XGpioPs *InstancePtr, int Pin)
180 Xil_AssertVoid(InstancePtr != NULL);
181 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
182 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
185 * Get the Bank number and Pin number within the bank.
187 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
189 IntrReg = 1 << PinNumber;
190 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
191 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
192 XGPIOPS_INTDIS_OFFSET, IntrReg);
195 /****************************************************************************/
198 * This function returns the interrupt enable status for a bank.
200 * @param InstancePtr is a pointer to the XGpioPs instance.
201 * @param Bank is the bank number of the GPIO to operate on.
202 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
204 * @return Enabled interrupt(s) in a 32-bit format. Bit positions with 1
205 * indicate that the interrupt for that pin is enabled, bit
206 * positions with 0 indicate that the interrupt for that pin is
211 *****************************************************************************/
212 u32 XGpioPs_IntrGetEnabled(XGpioPs *InstancePtr, u8 Bank)
216 Xil_AssertNonvoid(InstancePtr != NULL);
217 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
218 Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
220 IntrMask = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
221 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
222 XGPIOPS_INTMASK_OFFSET);
226 /****************************************************************************/
229 * This function returns whether interrupts are enabled for the specified pin.
231 * @param InstancePtr is a pointer to the XGpioPs instance.
232 * @param Pin is the pin number for which the interrupt enable status
234 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
237 * - TRUE if the interrupt is enabled.
238 * - FALSE if the interrupt is disabled.
242 *****************************************************************************/
243 int XGpioPs_IntrGetEnabledPin(XGpioPs *InstancePtr, int Pin)
249 Xil_AssertNonvoid(InstancePtr != NULL);
250 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
251 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
254 * Get the Bank number and Pin number within the bank.
256 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
258 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
259 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
260 XGPIOPS_INTMASK_OFFSET);
262 return (IntrReg & (1 << Pin)) ? TRUE : FALSE;
265 /****************************************************************************/
268 * This function returns interrupt status read from Interrupt Status Register.
270 * @param InstancePtr is a pointer to the XGpioPs instance.
271 * @param Bank is the bank number of the GPIO to operate on.
272 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
274 * @return The value read from Interrupt Status Register.
278 *****************************************************************************/
279 u32 XGpioPs_IntrGetStatus(XGpioPs *InstancePtr, u8 Bank)
281 Xil_AssertNonvoid(InstancePtr != NULL);
282 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
283 Xil_AssertNonvoid(Bank < XGPIOPS_MAX_BANKS);
285 return XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
286 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
287 XGPIOPS_INTSTS_OFFSET);
290 /****************************************************************************/
293 * This function returns interrupt enable status of the specified pin.
295 * @param InstancePtr is a pointer to the XGpioPs instance.
296 * @param Pin is the pin number for which the interrupt enable status
298 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
301 * - TRUE if the interrupt has occurred.
302 * - FALSE if the interrupt has not occurred.
306 *****************************************************************************/
307 int XGpioPs_IntrGetStatusPin(XGpioPs *InstancePtr, int Pin)
313 Xil_AssertNonvoid(InstancePtr != NULL);
314 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
315 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
318 * Get the Bank number and Pin number within the bank.
320 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
322 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
323 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
324 XGPIOPS_INTSTS_OFFSET);
326 return (IntrReg & (1 << Pin)) ? TRUE : FALSE;
329 /****************************************************************************/
332 * This function clears pending interrupt(s) with the provided mask. This
333 * function should be called after the software has serviced the interrupts
336 * @param InstancePtr is a pointer to the XGpioPs instance.
337 * @param Bank is the bank number of the GPIO to operate on.
338 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
339 * @param Mask is the mask of the interrupts to be cleared. Bit positions
340 * of 1 will be cleared. Bit positions of 0 will not change the
341 * previous interrupt status.
345 *****************************************************************************/
346 void XGpioPs_IntrClear(XGpioPs *InstancePtr, u8 Bank, u32 Mask)
348 Xil_AssertVoid(InstancePtr != NULL);
349 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
350 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
353 * Clear the currently pending interrupts.
355 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
356 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
357 XGPIOPS_INTSTS_OFFSET, Mask);
360 /****************************************************************************/
363 * This function clears the specified pending interrupt. This function should be
364 * called after the software has serviced the interrupts that are pending.
366 * @param InstancePtr is a pointer to the XGpioPs instance.
367 * @param Pin is the pin number for which the interrupt status is to be
368 * cleared. Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
372 *****************************************************************************/
373 void XGpioPs_IntrClearPin(XGpioPs *InstancePtr, int Pin)
379 Xil_AssertVoid(InstancePtr != NULL);
380 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
381 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
384 * Get the Bank number and Pin number within the bank.
386 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
389 * Clear the specified pending interrupts.
391 IntrReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
392 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
393 XGPIOPS_INTSTS_OFFSET);
395 IntrReg &= (1 << Pin);
396 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
397 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
398 XGPIOPS_INTSTS_OFFSET, IntrReg);
401 /****************************************************************************/
404 * This function is used for setting the Interrupt Type, Interrupt Polarity and
405 * Interrupt On Any for the specified GPIO Bank pins.
407 * @param InstancePtr is a pointer to an XGpioPs instance.
408 * @param Bank is the bank number of the GPIO to operate on.
409 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
410 * @param IntrType is the 32 bit mask of the interrupt type.
411 * 0 means Level Sensitive and 1 means Edge Sensitive.
412 * @param IntrPolarity is the 32 bit mask of the interrupt polarity.
413 * 0 means Active Low or Falling Edge and 1 means Active High or
415 * @param IntrOnAny is the 32 bit mask of the interrupt trigger for
416 * edge triggered interrupts. 0 means trigger on single edge using
417 * the configured interrupt polarity and 1 means trigger on both
422 * @note This function is used for setting the interrupt related
423 * properties of all the pins in the specified bank. The previous
424 * state of the pins is not maintained.
425 * To change the Interrupt properties of a single GPIO pin, use the
426 * function XGpioPs_SetPinIntrType().
428 *****************************************************************************/
429 void XGpioPs_SetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 IntrType,
430 u32 IntrPolarity, u32 IntrOnAny)
432 Xil_AssertVoid(InstancePtr != NULL);
433 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
434 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
436 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
437 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
438 XGPIOPS_INTTYPE_OFFSET, IntrType);
440 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
441 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
442 XGPIOPS_INTPOL_OFFSET, IntrPolarity);
444 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
445 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
446 XGPIOPS_INTANY_OFFSET, IntrOnAny);
449 /****************************************************************************/
452 * This function is used for getting the Interrupt Type, Interrupt Polarity and
453 * Interrupt On Any for the specified GPIO Bank pins.
455 * @param InstancePtr is a pointer to an XGpioPs instance.
456 * @param Bank is the bank number of the GPIO to operate on.
457 * Valid values are 0 to XGPIOPS_MAX_BANKS - 1.
458 * @param IntrType returns the 32 bit mask of the interrupt type.
459 * 0 means Level Sensitive and 1 means Edge Sensitive.
460 * @param IntrPolarity returns the 32 bit mask of the interrupt
461 * polarity. 0 means Active Low or Falling Edge and 1 means
462 * Active High or Rising Edge.
463 * @param IntrOnAny returns the 32 bit mask of the interrupt trigger for
464 * edge triggered interrupts. 0 means trigger on single edge using
465 * the configured interrupt polarity and 1 means trigger on both
472 *****************************************************************************/
473 void XGpioPs_GetIntrType(XGpioPs *InstancePtr, u8 Bank, u32 *IntrType,
474 u32 *IntrPolarity, u32 *IntrOnAny)
477 Xil_AssertVoid(InstancePtr != NULL);
478 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
479 Xil_AssertVoid(Bank < XGPIOPS_MAX_BANKS);
481 *IntrType = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
482 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
483 XGPIOPS_INTTYPE_OFFSET);
485 *IntrPolarity = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
486 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
487 XGPIOPS_INTPOL_OFFSET);
489 *IntrOnAny = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
490 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
491 XGPIOPS_INTANY_OFFSET);
494 /****************************************************************************/
497 * This function is used for setting the IRQ Type of a single GPIO pin.
499 * @param InstancePtr is a pointer to an XGpioPs instance.
500 * @param Pin is the pin number whose IRQ type is to be set.
501 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
502 * @param IrqType is the IRQ type for GPIO Pin. Use XGPIOPS_IRQ_TYPE_*
503 * defined in xgpiops.h to specify the IRQ type.
509 *****************************************************************************/
510 void XGpioPs_SetIntrTypePin(XGpioPs *InstancePtr, int Pin, u8 IrqType)
518 Xil_AssertVoid(InstancePtr != NULL);
519 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
520 Xil_AssertVoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
521 Xil_AssertVoid(IrqType <= XGPIOPS_IRQ_TYPE_LEVEL_LOW);
524 * Get the Bank number and Pin number within the bank.
526 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
528 IntrTypeReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
529 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
530 XGPIOPS_INTTYPE_OFFSET);
532 IntrPolReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
533 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
534 XGPIOPS_INTPOL_OFFSET);
536 IntrOnAnyReg = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
537 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
538 XGPIOPS_INTANY_OFFSET);
541 case XGPIOPS_IRQ_TYPE_EDGE_RISING:
542 IntrTypeReg |= (1 << PinNumber);
543 IntrPolReg |= (1 << PinNumber);
544 IntrOnAnyReg &= ~(1 << PinNumber);
546 case XGPIOPS_IRQ_TYPE_EDGE_FALLING:
547 IntrTypeReg |= (1 << PinNumber);
548 IntrPolReg &= ~(1 << PinNumber);
549 IntrOnAnyReg &= ~(1 << PinNumber);
551 case XGPIOPS_IRQ_TYPE_EDGE_BOTH:
552 IntrTypeReg |= (1 << PinNumber);
553 IntrOnAnyReg |= (1 << PinNumber);
555 case XGPIOPS_IRQ_TYPE_LEVEL_HIGH:
556 IntrTypeReg &= ~(1 << PinNumber);
557 IntrPolReg |= (1 << PinNumber);
559 case XGPIOPS_IRQ_TYPE_LEVEL_LOW:
560 IntrTypeReg &= ~(1 << PinNumber);
561 IntrPolReg &= ~(1 << PinNumber);
565 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
566 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
567 XGPIOPS_INTTYPE_OFFSET, IntrTypeReg);
569 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
570 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
571 XGPIOPS_INTPOL_OFFSET, IntrPolReg);
573 XGpioPs_WriteReg(InstancePtr->GpioConfig.BaseAddr,
574 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
575 XGPIOPS_INTANY_OFFSET, IntrOnAnyReg);
578 /****************************************************************************/
581 * This function returns the IRQ Type of a given GPIO pin.
583 * @param InstancePtr is a pointer to an XGpioPs instance.
584 * @param Pin is the pin number whose IRQ type is to be obtained.
585 * Valid values are 0 to XGPIOPS_DEVICE_MAX_PIN_NUM - 1.
589 * @note Use XGPIOPS_IRQ_TYPE_* defined in xgpiops.h for the IRQ type
590 * returned by this function.
592 *****************************************************************************/
593 u8 XGpioPs_GetIntrTypePin(XGpioPs *InstancePtr, int Pin)
602 Xil_AssertNonvoid(InstancePtr != NULL);
603 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
604 Xil_AssertNonvoid(Pin < XGPIOPS_DEVICE_MAX_PIN_NUM);
607 * Get the Bank number and Pin number within the bank.
609 XGpioPs_GetBankPin(Pin, &Bank, &PinNumber);
611 IntrType = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
612 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
613 XGPIOPS_INTTYPE_OFFSET) & PinNumber;
615 IntrPol = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
616 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
617 XGPIOPS_INTPOL_OFFSET) & PinNumber;
619 IntrOnAny = XGpioPs_ReadReg(InstancePtr->GpioConfig.BaseAddr,
620 ((Bank) * XGPIOPS_REG_MASK_OFFSET) +
621 XGPIOPS_INTANY_OFFSET) & PinNumber;
624 if (IntrOnAny == 1) {
625 IrqType = XGPIOPS_IRQ_TYPE_EDGE_BOTH;
626 } else if (IntrPol == 1) {
627 IrqType = XGPIOPS_IRQ_TYPE_EDGE_RISING;
629 IrqType = XGPIOPS_IRQ_TYPE_EDGE_FALLING;
633 IrqType = XGPIOPS_IRQ_TYPE_LEVEL_HIGH;
635 IrqType = XGPIOPS_IRQ_TYPE_LEVEL_LOW;
642 /*****************************************************************************/
645 * This function sets the status callback function. The callback function is
646 * called by the XGpioPs_IntrHandler when an interrupt occurs.
648 * @param InstancePtr is a pointer to the XGpioPs instance.
649 * @param CallBackRef is the upper layer callback reference passed back
650 * when the callback function is invoked.
651 * @param FuncPtr is the pointer to the callback function.
656 * @note The handler is called within interrupt context, so it should do
657 * its work quickly and queue potentially time-consuming work to a
660 ******************************************************************************/
661 void XGpioPs_SetCallbackHandler(XGpioPs *InstancePtr, void *CallBackRef,
662 XGpioPs_Handler FuncPtr)
664 Xil_AssertVoid(InstancePtr != NULL);
665 Xil_AssertVoid(FuncPtr != NULL);
666 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
668 InstancePtr->Handler = FuncPtr;
669 InstancePtr->CallBackRef = CallBackRef;
672 /*****************************************************************************/
675 * This function is the interrupt handler for GPIO interrupts.It checks the
676 * interrupt status registers of all the banks to determine the actual bank in
677 * which an interrupt has been triggered. It then calls the upper layer callback
678 * handler set by the function XGpioPs_SetBankHandler(). The callback is called
681 * @param InstancePtr is a pointer to the XGpioPs instance.
685 * @note This function does not save and restore the processor context
686 * such that the user must provide this processing.
688 ******************************************************************************/
689 void XGpioPs_IntrHandler(XGpioPs *InstancePtr)
695 Xil_AssertVoid(InstancePtr != NULL);
696 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
698 for (Bank = 0; Bank < XGPIOPS_MAX_BANKS; Bank++) {
699 IntrStatus = XGpioPs_IntrGetStatus(InstancePtr, Bank);
700 if (IntrStatus != 0) {
701 IntrEnabled = XGpioPs_IntrGetEnabled(InstancePtr,
703 XGpioPs_IntrClear(InstancePtr, Bank,
704 IntrStatus & IntrEnabled);
705 InstancePtr->Handler((void *)InstancePtr->
707 (IntrStatus & IntrEnabled));
712 /*****************************************************************************/
715 * This is a stub for the status callback. The stub is here in case the upper
716 * layers do not set the handler.
718 * @param CallBackRef is a pointer to the upper layer callback reference
719 * @param Bank is the GPIO Bank in which an interrupt occurred.
720 * @param Status is the Interrupt status of the GPIO bank.
726 ******************************************************************************/
727 void StubHandler(void *CallBackRef, int Bank, u32 Status)
733 Xil_AssertVoidAlways();