Re: [beagleboard] declare create interrupts gpio tren beaglebone black

2016-05-21 Thread John Syne
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 
#include 
#include 
#include 
#include 
#include 

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, caonguyen1...@gmail.com 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 
> 
> --- 
> 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 beagleboard+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/beagleboard/de95e703-789b-4709-b059-2f2c570e3edd%40googlegroups.com
>  
> .
> For more options, visit 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 beagleboard+unsubscr...@googlegroups.com.
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.


Re: [beagleboard] declare create interrupts gpio tren beaglebone black

2016-05-17 Thread John Syne
BlackLib is for user space programming. To process interrupts, you have to be 
in kernel space so you have to use a Kernel Module or Device Driver to process 
interrupts. To pass the event onto user space, there are several options, such 
as blocking on a read,  or sigaction, etc. Best to read Linux Device Driver 3rd 
edition on how to do this. Search Google as this book is online.

Regards,
John




> On May 16, 2016, at 9:13 PM, caonguyen1...@gmail.com 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 
> 
> --- 
> 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 beagleboard+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/beagleboard/de95e703-789b-4709-b059-2f2c570e3edd%40googlegroups.com
>  
> .
> For more options, visit 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 beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/6F50BA43-137D-456C-85CF-DFF6B725551B%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[beagleboard] declare create interrupts

2016-05-17 Thread caonguyen1907
I'm trying to declare interrupt generated on board beaglebone black, but I 
do not know how to report, please help me
I using library Blacklib c++
Thanks.

-- 
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 beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/3082a368-2c0c-4884-bf25-a5ea7915bc5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[beagleboard] declare create interrupts gpio tren beaglebone black

2016-05-17 Thread caonguyen1907
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
--- 
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 beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/de95e703-789b-4709-b059-2f2c570e3edd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.