The HiPi Perl distribution provides a set of modules that wrap GPIO interrupt handling.
The module HiPi::Interrupt loads background threads that monitor or poll for interrupts and notify your main thread
The module HiPi::Interrupt::Handler can be used directly or you can derive your own class from it to handle interrupt notifications in your main thread.
Basic usage is covered in three examples:
Only pins accessed through the though the kernel device driver sysfs filespace using HiPi::Device::GPIO provide true system interrupt handling. For pins accessed directly on the hardware using HiPi::BCM2835 or HiPi::Wiring, pseudo interrupt handling is provided by polling the pin values for changes. This is necessary because recent Raspbian releases include code in the statically compiled gpio kernel driver that prevents use of the BCM2835 hardware interrupt registers.
You are unlikely to be able to drive any form of protocol that is timing critical or consistently handle state changes of very short duration using these interrupt modules. It is a limitation of user space code on the Linux Operating system and Perl without considering any flaws that may be introduced by this particular implementation.
However, you should be able to build working applications where timing is not critical and communication is driven using waits of indeterminate length.
The use of separate threads to handle interrupts and value polling means that issues with catching all events should be minimal. However, your main thread code may fall behind as multiple interrupts are received depending on the efficiency of your main thread code so this should be a consideration in designing your model and application. The only guarantee is that those interrupts or state changes that are caught will be delivered to the main thread code in order for each particular pin.