Sudhir,
If you don't object to using a library there is libsoc[1] which is made
for this exact purpose.
https://github.com/jackmitch/libsoc
Cheers,
Jack.
On 18/10/2013 17:31, sudhir v wrote:
Hi,
I want to monitor a pin on BBB for interrupt. I chose pin 117 (pin 25 on
P9 -> GPIO3_21 = 32*3+21 = 117. I hope that's correct?)
I came across this question on stackoverflow
<http://stackoverflow.com/questions/3021146/poll2-doesnt-empty-the-event-queue>.
And This is my question on stackoverflow
<http://stackoverflow.com/questions/19434157/poll-to-monitor-a-pin-on-beaglebone-black-continuous-output-even-though-pin-n>
I am following this program from ridgerun
<https://developer.ridgerun.com/wiki/index.php/Gpio-int-test.c> and made
minor changes since I want to monitor just one pin and not any other
files. Changes are highlighted in the code below which I am trying to
run. (I have pasted just the main. Rest is the same as the code from the
site)
The problem is, when I run the program, it continuously outputs "poll()
GPIO 117 interrupt occurred" even though I haven't connected anything to
that particular pin and I have to do ctrl+C to stop the execution.
POLLPRI does not work and the program prints just ... after every
timeout and I think POLLIN is proper since it is not a priority data.
Where am I going wrong?
I read about potential problems and the program seems to take care of
the below.
1. The poll() doesn't fail.
2. read() is called after every poll() so data should be consumed. ( I
just want the program to notify whenever there is a rising edge saying
there is an event occured. I do not want to read data from pin. but
included this to avoid potential pitfalls)
3. struct pollfd is being reset inside while loop (
memset((void*)fdset,0,sizeof(fdset)); )
|
int main(int argc, char **argv)
{
*struct pollfd fdset[1];*
*int nfds= 1;*
int gpio_fd, timeout, rc;
char *buf[MAX_BUF];
unsigned int gpio;
int len;
if (argc< 2) {
printf("Usage: gpio-int <gpio-pin>\n\n");
printf("Waits for a change in the GPIO pin voltage level or input
on stdin\n");
exit(-1);
}
gpio= atoi(argv[1]);
gpio_export(gpio);
gpio_set_dir(gpio, 0);
gpio_set_edge(gpio, "rising");
gpio_fd= gpio_fd_open(gpio);
timeout= POLL_TIMEOUT;
while (1) {
memset((void*)fdset, 0, sizeof(fdset));
*fdset[0].fd= gpio_fd;
fdset[0].events= POLLIN;*
rc= poll(fdset, nfds, timeout);
if (rc< 0) {
printf("\npoll() failed!\n");
return -1;
}
if (rc== 0) {
printf(".");
}
*if (fdset[0].revents& POLLIN) {
len= read(fdset[0].fd, buf, MAX_BUF);*
printf("\npoll() GPIO %d interrupt occurred\n", gpio);
}
fflush(stdout);
}
gpio_fd_close(gpio_fd);
return 0;
}
|
Thanks,
sudhir
--
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].
For more options, visit https://groups.google.com/groups/opt_out.
--
Jack Mitchell ([email protected])
Embedded Systems Engineer
http://www.embed.me.uk
--
--
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].
For more options, visit https://groups.google.com/groups/opt_out.