Question

How does select work with gpio under Linux?

Is it possible to use select to create a kind of interrupt driven program, maybe with the help of some threads?

And what shall I think about when I use the select call?

Thanks


Note: I have read the man page on select, but I think I need some more help on this topic.

  • man 3posix select
  • man 2 select
  • man 2 select_tut

Update: The gpio is exposed in the sysfs gpio block. But I don't know if I can use that with select.

Was it helpful?

Solution

Apparently you can use select() on a GPIO exposed through sysfs, but only if it can be configured to generate an interrupt. Your platform may have this or not.

What you want to read though is Documentation/gpio.txt in your kernel source, which mentions how to enable an interrupt for a pin if the kernel driver allows it.

OTHER TIPS

It should be possible to write multi-threaded program that looks for interrupts and does something when they occur. This blog highlights what can be done when you are hitting the limitations of select. I have not worked with GPIOs but from what I read up, GPIO should not be very different from the telephony/network card discussed in the blog mentioned above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top