# Problem understending interrupt handling example in The Zynq Book

Sorry for basic question but I'm coming to embedded/fpga (as a hobby) from 'big' computers and I have trouble understanding example code from Zynq Book:

void BTN_Intr_Handler(void *InstancePtr)
{
// Disable GPIO interrupts
XGpio_InterruptDisable(&BTNInst, BTN_INT);
if ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=
BTN_INT) {
return;
}
// Increment counter based on button value

led_data = led_data + btn_value;

XGpio_DiscreteWrite(&LEDInst, 1, led_data);
(void)XGpio_InterruptClear(&BTNInst, BTN_INT);
// Enable GPIO interrupts
XGpio_InterruptEnable(&BTNInst, BTN_INT);
}

• I would expect that for such simple code it would be just top half. However top half would execute just in IRQ mode with interrupts disabled so there is no need for disabling interrupts. OTOH if we are in bottom half there is race between button interrupt and disabling interrupts - unless we use it as a mutex for led_data.
• In similar way why if GetStatus returns we don't re-enable interrupts?
• What is the book (and page), and what is the device (not only chip, but also is it PL or PS, and what is in FPGA, and what is the bus to the BTN device)? Where this code is placed, what is the OS (and kernel lib)? Some devices may have unusual Interrupt handling rules. "if GetStatus returns" - if the interrupt line is shared between 2 devices (same id: en.wikipedia.org/wiki/… and makelinux.net/ldd3/chp-10-sect-5), two handlers will be called: each checking its device and if it was not from this device, don't work with it. – osgx Jun 19 '17 at 4:37
• @osgx It's called The Zynq Book. I cannot find page ATM - possibly it is just in examples? No OS - standalone app. Bus is, well, AXI. I understand why XGpio_InterruptGetStatus might be called - I don't understand why we disable interrupts without re-enabling them on this codepath. – Maciej Piechotka Jun 19 '17 at 5:00
• "without re-enabling" - Are your sure that they are not reenabled in the xgpio library? (The example may be wrong too). Check xgpio library implementation (and xgpio device specification too), it is open: github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/… xgpio_intr.c (And posting link to online copy of full example may be useful too). No similar code in github.com/Xilinx/embeddedsw/tree/master/XilinxProcessorIPLib/… ... – osgx Jun 19 '17 at 5:16
• @osgx It's downloadable with the book. It's free but behind registration. – Maciej Piechotka Jun 19 '17 at 5:38