民意调查()都返回,POLLPRI&安培; POLLERR [英] poll() returns both, POLLPRI & POLLERR

查看:271
本文介绍了民意调查()都返回,POLLPRI&安培; POLLERR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在C编程与Linux和嵌入式系统(路由器硬件与OpenWrt的)来获得。我有个GPIO上启用interupts使用调查工作......近。

I started to get in C programming with Linux and embedded systems (router hardware and openwrt). I have got interupts on GPIOs enabled, using poll works ... nearly.

我可以使用轮询(),如果我preSS按钮来触发中断,轮询()具有值> 0返回到目前为止好。现在,我尝试simultaniosly若干个GPIO使用轮询()并为此要分析每一个潜在的中断源的revents中。 Allthough中断似乎工作,我得到POLLPRI&安培; POLLERR回来,我不明白为什么。降低pollfd结构为1项不改变任何东西。

I can use poll() and if i press the button to trigger the interrupt, poll() returns with a value > 0. So far so good. Now i try to use poll() on several GPIOs simultaniosly and therefor want to analyze the revents of every potential interrupt source. Allthough the interrupt seems to work, i get POLLPRI & POLLERR back and i do not understand why. Reducing the pollfd structure to 1 entry does not change anything.

char value;

int fd_btn1 = open("/sys/class/gpio/gpio14/value", O_RDONLY);
int fd_left = open("/sys/class/gpio/gpio12/value", O_RDONLY);
int fd_right = open("/sys/class/gpio/gpio13/value", O_RDONLY);

struct pollfd fds[3];
fds[0].fd = fd_btn1;
fds[1].fd = fd_left;
fds[2].fd = fd_right;
fds[0].events = POLLPRI;
fds[1].events = POLLPRI;
fds[2].events = POLLPRI;

read(fd_btn1, &value, 1);
read(fd_left, &value, 1);
read(fd_right, &value, 1);

ret = poll(fds, 1, 10000);
//debugging purpose
printf("ret: %i - revents[0]: %i", ret, fds[0].revents);

在情况下按钮是pressed(中断触发):
RET = 1D,revents中= 10D

In case button was pressed (interrupt triggered): ret=1d, revents=10d

在什么情况下是pressed,无论是0D

In case nothing was pressed, both is 0d

推荐答案

我已经找到了一些答案在暗示你的问题:的 http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/t/182883

I've found some answer alluding to your question at: http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/716/t/182883

我刚跑进你看到太POLLERR的事情。原来,这是
  所有的sysfs文件如何工作的,你通过sysfs的使用GPIO
  接口。

I just ran into the POLLERR thing you're seeing too. Turns out this is how all sysfs files work, and you're using gpio through the sysfs interface.

从sysfs的GPIO内核文件:如果引脚可配置为
  中断产生的中断,如果它已被配置为
  产生中断(见边缘的说明),您可以轮询(2)
  在该文件上和poll(2)将返回时中断了
  触发。如果你使用的poll(2),设置事件POLLPRI和POLLERR。
  另外,如果你看看参加FS / sysfs中/ file.c中看看内核code,
  你会看到sysfs_poll回报DEFAULT_POLLMASK | POLLERR |
  POLLPRI。

From the sysfs GPIO kernel document: 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. Also, if you look take a look at the kernel code in fs/sysfs/file.c, you'll see that sysfs_poll returns DEFAULT_POLLMASK | POLLERR | POLLPRI.

所有这一切说,它似乎奇怪的sysfs文件返回
  POLLERR,我不知道他们为什么选择这样做。

All that said, it does seem strange that sysfs files return POLLERR, I'm not sure why they chose to do that.

这篇关于民意调查()都返回,POLLPRI&安培; POLLERR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆