GPIO Interrupts

HI,
I’m trying to use interrupts on some gpio’s of my beaglebone black.
I’ve found some webside which explain the usage from userspace:

https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals#GPIO_interrupts_from_user_space

It says i have to write some kind of trigger mode into /sys/class/gpio/gpio<<>>/edge. Then the value file will be blocked until the state of the spesific gpio has changed.
Yet, my programm has to check all the time if reading on value is possible. That sounds like polling… My programm is waiting for the GPIO to change level.
Is there a way to interrupt the main loop immediately if a gpio change without doing polling? Like:

`

`

Bonescript offers a function calls “attachInterrupt = function(pin, handler, mode, callback)”
source: https://github.com/jadonk/bonescript/blob/master/node_modules/bonescript/index.js

But I don’t understand how it works…
Would be great if some one explains the steps “attachInterrupt()” is doing to setup and get the interrupt.

Thanks

HI,
I'm trying to use interrupts on some gpio's of my beaglebone black.
I've found some webside which explain the usage from userspace:

https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals#GPIO_interrupts_from_user_space

It says i have to write some kind of trigger mode into
/sys/class/gpio/gpio<<<number>>>/edge. Then the value file will be blocked
until the state of the spesific gpio has changed.
Yet, my programm has to check all the time if reading on value is possible.
That sounds like polling... My programm is waiting for the GPIO to change
level.

What you're looking for is the select(2) or poll(2) functions that let
you wait on a set of file handles until one or more of them are ready.
If you open up the "value" file and pass its file handle to select(),
select() will block until the gpio changes state. More documentation
can be found in the Linux kernel. Check out the end of this file where
it talks about the sysfs interface:

http://lxr.linux.no/linux+v3.10.1/Documentation/gpio.txt

Is there a way to interrupt the main loop immediately if a gpio change
without doing polling? Like:

gpiosetInterrupt("P9_12", blinkLED);

while()
{
//do some thing
// no polling
}

blinkLED()
{
//Blink Led
}

The gpio sysfs api is expecting an event driven programming structure
that looks like this:

open a bunch of file handles
while()
{
    select(file handles)
    process handles that are marked as ready
}

Bonescript (or more specifically node.js) does this for you behind the
scenes. Specifically, it will open the /sys/class/gpio/gpioxxx/value
file and include its file handle in the set of handles that are passed
to select(). When select returns and that handle is marked as ready,
it reads the value file and calls your Javascript handler function
back.

Frank

Hi Frank,

I’m using Java to control the GPIO’s, ADC’s and PWM Outputs.
I access the files in userspace via normal IO-Methods.

Yesterday i attempted to use a lib calls Jnotify which is able to monitor a filesystem.
It generates software interrupts if something changes.
But unfortunately it dosen’t recognize if the value file changes by pressing a button… It only works if I’m writing another value into the file by myself…
(How does the system change gpio files ?)

Are there some simple examples for “linux/gpio.h” and where i can find this libs?
I may be able to integrate this as native code in Java…

Does anybody ever build a kind of java lib for the beaglebone ? Like “Pi4J” http://pi4j.com/

Thanks

Hi Frank,

I'm using Java to control the GPIO's, ADC's and PWM Outputs.
I access the files in userspace via normal IO-Methods.
Yesterday i attempted to use a lib calls Jnotify which is able to monitor a
filesystem.
It generates software interrupts if something changes.
But unfortunately it dosen't recognize if the value file changes by pressing
a button... It only works if I'm writing another value into the file by
myself...
(How does the system change gpio files ?)

Are there some simple examples for "linux/gpio.h" and where i can find this
libs?
I may be able to integrate this as native code in Java...

Does anybody ever build a kind of java lib for the beaglebone ? Like "Pi4J"
http://pi4j.com/

I don't know if this helps, but Pi4J uses the sysfs interface too, so
maybe something could be extracted from it. Here's the key file:

https://github.com/Pi4J/pi4j/blob/master/pi4j-native/src/main//com_pi4j_wiringpi_GpioInterrupt.c