GPIO interrupts


I need to know when the value of one input pin changes.
For example, the pin X is connected to other chip that sends a binary 0. In some condition the chip sends a binary 1 to the pin and I want to be noticed (in beaglebone) of this as son as posible.
I only have found solutions using polling (or busy-waiting) but I think that a real interrupt system should be better.

Thank you!

I do this with poll() and edge triggered interrupts, it seems to work very well. What do you suggest instead of polling as in user space you can't have an ISR - I believe you would have to write a kernel module.


If you use Pool() did the work, please show me some code. i’m interesting at this.
If you want a real-time interrupt, I can inform you how to write the module, it is not hard.


It usually involves writing (or adapting) a kernel module. In C.
There may be usermode ways, but the kernel is where the action is at
the low level.

LLD3 [1] can be helpful if you're really interested in interrupts in
Linux. It's not horribly difficult to write a decent kernel module.



Could you show how this module should be? The best for me is a real-time interrupt.

Thank you

2012/7/17 xiooozzz <>

you can write a module only have init method and exit method, no ioctrl, no read and etc.
in your init method, you request gpio, set irq type, enable irq, request irq.
when you are requesting irq, you register the irq handler function.
you can do the things you like in irq handler function.

but remenber you are in the kernel space, if you want to inform a user space process, use signal.

when you want to compile your module, you can use the linux code provided by TI for am335x_evm board as your KERNEL location.


Do you have some documentation about this interrupts?

Thank you

2012/7/18 xiooozzz <>

In the file

	"value" ... reads as either 0 (low) or 1 (high).  If the GPIO
		is configured as an output, this value may be written;
		any nonzero value is treated as high.

		If the pin can be configured as interrupt-generating interrupt
		and if it has been configured to generate interrupts (see the
		description of "edge"), you can poll(2) on that file and
		poll(2) will return whenever the interrupt was triggered. If
		you use poll(2), set the events POLLPRI and POLLERR. If you
		use select(2), set the file descriptor in exceptfds. After
		poll(2) returns, either lseek(2) to the beginning of the sysfs
		file and read the new value or close the file and re-open it
		to read the value.

	"edge" ... reads as either "none", "rising", "falling", or
		"both". Write these strings to select the signal edge(s)
		that will make poll(2) on the "value" file return.

		This file exists only if the pin can be configured as an
		interrupt generating input pin.

Information about poll function:

Page which shows this code:

#include <stropts.h>
#include <[poll.h](>
struct pollfd fds[2];
int timeout_msecs = 500;
int ret;
    int i;

/* Open STREAMS device. */
fds[0].fd = open("/dev/dev0", ...);
fds[1].fd = open("/dev/dev1", ...);
    fds[0].events = POLLOUT | POLLWRBAND;
    fds[1].events = POLLOUT | POLLWRBAND;

ret = poll(fds, 2, timeout_msecs);

if (ret > 0) {
    /* An event on one of the fds has occurred. */
    for (i=0; i<2; i++) {
        if (fds[i].revents & POLLWRBAND) {
        /* Priority data may be written on device number i. */
        if (fds[i].revents & POLLOUT) {
        /* Data may be written on device number i. */
        if (fds[i].revents & POLLHUP) {
        /* A hangup has occurred on device number i. */

At the moment I cant check it (I’m not at home) but what I understand is the
function “poll” block the process until something happends.

2012/7/18 Alvaro Garcia <>

The fastest way to write the module is to copy some code from other modules.
Search kernel with “request_irq”, then you will get a lot models showing the whole interrupt process.

By the way, do you know any ways to debug a user space application, my gdb doesn’t work.