OlinuXino GPIO events?

Started by idragoev, November 27, 2012, 07:01:34 PM

Previous topic - Next topic

idragoev

Hi,
we have a program that needs to work with GPIOs. We have to track when a GPIO configured as input has a new value. We have 2 options: to use /sys/class/gpio or using gpio-mmap.h. I have the following questions regarding GPIOs:
1. If we use /sys/class/gpio, how can we achieve this without using pooling to check for new value? I will appreciate some examples
2. If we use gpio-mmap.h, how can we extend it to have a function that accepts a callback as parameter so when a new values is set to the GPIO the callback is called?
3. are there other ways of handling value change on GPIO inputs?

thanks in advance,
Ivan

jeroends

Have a look at the following site: https://www.ridgerun.com/developer/wiki/index.php/How_to_use_GPIO_signals.
They explain how to use the /sys/class/gpio interface in "C" and "shell" using interrupts. It's a good base to start. It's explained for another board but it works for the Olinuxino as well (U don't have to reconfigure the kernel).

dpwhittaker

Gpio-mmap won't trigger an interrupt (well, you could make it trigger one, but you can't catch it in user space).  You'd have to poll for the value (manually, like in a loop).  Using poll (the syscall) on a sys/class/gpio is the most efficient way to watch for gpio changes currently.

Somewhere down my list is a kernel driver that watches a set of gpios, blocks reads on a char device until a change occurs, and gives you the timestamp at the moment of the interrupt when you do get around to reading it, but that is probably a month or two off.

Oclistediscussion

Quote from: idragoev on November 27, 2012, 07:01:34 PM
Hi,
we have a program that needs to work with GPIOs. We have to track when a GPIO configured as input has a new value. We have 2 options: to use /sys/class/gpio or using gpio-mmap.h. I have the following questions regarding GPIOs:
1. If we use /sys/class/gpio, how can we achieve this without using pooling to check for new value? I will appreciate some examples
2. If we use gpio-mmap.h, how can we extend it to have a function that accepts a callback as parameter so when a new values is set to the GPIO the callback is called?
3. are there other ways of handling value change on GPIO inputs?

thanks in advance,
Ivan

In debian i use inotify/incron (Sorry for french) :
http://www.sysadmin-fr.org/fr/linux/incron