I found this info in the book "Mastering Embedded Linux Programming” by Chris
Simmonds
HANDLING INTERRUPTS FROM GPIO
In many cases, a GPIO input can be configured to generate an interrupt when it
changes state, which allows you to wait for the interrupt rather than polling
in an inefficient software loop. If the GPIO bit can generate interrupts, the
file edge exists. Initially, it has the value none, meaning that it does not
generate interrupts. To enable interrupts, you can set it to one of these
values:
• rising: Interrupt on rising edge
• falling: Interrupt on falling edge
• both: Interrupt on both rising and falling edges
• none: No interrupts (default)
You can wait for an interrupt using the poll() function with POLLPRI as the
event. If you want to wait for a rising edge on GPIO 48, you first enable
interrupts:
# echo 48 > /sys/class/gpio/export
# echo rising > /sys/class/gpio/gpio48/edge
Then, you use poll() to wait for the change, as shown in this code example:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <poll.h>
int main (int argc, char *argv[])
{
int f;
struct pollfd poll_fds [1];
int ret;
char value[4];
int n;
f = open("/sys/class/gpio/gpio48", O_RDONLY);
if (f == -1) {
perror("Can't open gpio48");
return 1;
}
poll_fds[0].fd = f;
poll_fds[0].events = POLLPRI | POLLERR;
while (1) {
printf("Waiting\n");
ret = poll(poll_fds, 1, -1);
if (ret > 0) {
n = read(f, &value, sizeof(value));
printf("Button pressed: read %d bytes, value=%c\n",
n, value[0]);
}
}
return 0;
}
Regards,
John
> On May 16, 2016, at 9:13 PM, [email protected] wrote:
>
> Hello all,
> I am trying to generate interrupts on the board Beaglebone black, but not yet
> know how to declare
> I using library BlackLib c++.
> Please give me answers
> Thanks
>
> --
> For more options, visit http://beagleboard.org/discuss
> <http://beagleboard.org/discuss>
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beagleboard/de95e703-789b-4709-b059-2f2c570e3edd%40googlegroups.com
>
> <https://groups.google.com/d/msgid/beagleboard/de95e703-789b-4709-b059-2f2c570e3edd%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/22B4E3BE-2F8F-4C5A-BA18-F8E9C3977627%40gmail.com.
For more options, visit https://groups.google.com/d/optout.