Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does C/C++ select work with gpio under Linux?

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.

like image 365
Johan Avatar asked Jul 28 '26 10:07

Johan


1 Answers

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.

like image 145
Torp Avatar answered Jul 30 '26 23:07

Torp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!