4

There are several libraries like WiringPi, RPi and pigpio, claiming to implement interrupt handling for GPIO signals. But as far as I can estimate, they all do polling on the pins, therefore implement a busy wait in a parallel thread. Only the library bcm2835 warns that it's not using real interrupts.

Reviewing the available datasheets (BCM2835 and BCM2711) I was able to identify the registers on which one can enable interrupts for three pins, which then should be routed from the Video Core over the Generic Interrupt Controller (GIC-400) to the CPU cores. On ATmega32 you can write to registers like these to enable interrupts on certain pins and implement ISR(desired_vec) as interrupt handler method.

Now I'd like to know how to implement an ISR on RPi. Is that even possible in user space?

And what is the difference between interrupts and BCM's edge detection? Does this actually activate the GIC?

void
  • 43
  • 1
  • 5

3 Answers3

4

wiringPi uses interrupts, e.g. with the wiringPiISR function.

pigpio uses interrupts, e.g. with the gpioSetISRFunc function.

lgpio uses interrupts. e.g. with the gGpioSetAlertsFunc function.

None of the above use polling or busy waits. I can only assume you are confused because at a low level they use a Linux function called poll. But this function does not poll the GPIO in the sense you mean.

Linux handles interrupts. As part of its interrupt handling it will eventually schedule one of the above functions.

pigpio can additionally use GPIO polling via DMA which happens to be more accurate and reliable for short (few µs) level changes.

joan
  • 71,852
  • 5
  • 76
  • 108
3

There is no way to call userspace code from an ISR. Unlike system calls which run on the stack of the userspace program, interrupt handlers use internal kernel memory for the stack. Since that memory is not visible in userspace, the system would crash the moment your ISR userspace function finishes or tries to use the stack for local variables (if not before, due to other reasons I have overlooked).

If you need to play with interrupts, you need to write a kernel driver.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
0

wiringPi and pigpio DO NOT use interrupts! They create a new thread for each gpio and pool the exported gpio.