Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => iMX233 => Topic started by: idragoev on November 27, 2012, 07:01:34 PM

Title: OlinuXino GPIO events?
Post by: 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
Title: Re: OlinuXino GPIO events?
Post by: jeroends on November 27, 2012, 07:34:49 PM
Have a look at the following site: https://www.ridgerun.com/developer/wiki/index.php/How_to_use_GPIO_signals (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).
Title: Re: OlinuXino GPIO events?
Post by: dpwhittaker on November 28, 2012, 04:26:30 PM
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.
Title: Re: OlinuXino GPIO events?
Post by: Oclistediscussion on December 05, 2012, 10:29:41 PM
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

Title: Re: OlinuXino GPIO events?
Post by: dpwhittaker on December 07, 2012, 04:07:12 PM
More information on poll()ing for gpio changes:

https://www.ridgerun.com/developer/wiki/index.php/How_to_use_GPIO_signals#Using_poll.28.29_to_monitor_for_GPIO_0_change