Interrupt service


Is it possible to handle hardware interrupts from Elixir?

I ask because I need to respond to a button press. If I was coding to bare metal I would write an ISR, but of course there is BEAM sitting on Debian. If I can’t do an ISR can I have a process block until the hardware changes?



Short: No you can’t.

Longer: you might be able to achieve your goal using ports and cports. External programs that can be written in any language and communicate with the BEAM. You can read these messages as if they were from another process using a receive block.

I do not think that you can use NIFs properly here.

Also, since I’m on a mobile I can’t search appropriate links right now.


Thanks for the reply and info @NobbZ. What is an NIF?


Natively implemented function.


When sitting in user-space on a Linux system, I think GPIO sysfs is the way to go about it.

elixir_ale provides a nice Elixir abstraction on top of GPIO sysfs. I haven’t had time to play around with it yet, but from its documentation and the example it looks fairly straight forward.


The elixir_ale solution seems to be exactly what I need. It’s a soft real time system so I don’t need to process the interrupt the microsecond it is triggered. As long as I get it within say 100 or 200 ms that will do very well.