如何在 Linux 上通过 GPIO 获取边缘事件而不需要繁忙循环?
我正在使用嵌入式 Linux(内核 2.6.31)的系统。
内部是一颗AT91SAM9G20芯片,部分Pin转发到外部。
现在我想将它们用作 GPIO 输入。
我阅读了有关通过文件系统使用 GPIO 的 gpio.txt 文档,直到这里为止它都运行良好。我将一些开关连接到 gpio 引脚,我可以在 /sys/class/gpio/gpioX/value
中看到结果。但现在我想对更改做出反应,而不是在循环中忙等待。 (即回显“Switch1 被按下”)。
我想我在这里需要中断,但是如果不编写自己的内核驱动程序,我无法找到如何使用它们。我对 Linux 和 C 比较陌生(我通常用 Java 编程),所以我也想通过 sysfs 处理中断。但我的问题是,我的 GPIO 目录中没有“edge”文件(我猜是因为这只是从内核版本 2.6.33+ 开始)。是这样吗?我在那里有一个 uevent
文件,而不是“edge”,该文件在 gpio.txt
中没有描述。
在 gpio.txt 文档中提到了一个标准内核驱动程序:“gpio_keys”。可以用这个来解决我的问题吗?
我想使用这个驱动程序比允许用户空间程序操纵内核任务更好。 我找到了很多用于编写自己的驱动程序的代码片段,但我什至无法找出要包含的 600 个 gpio.h
文件中的哪些,以及如何引用该库(交叉编译器)找不到 gpio.h 文件)。
新手问题请多多指教,希望大家多多指教。
提前致谢
I'm working an a system with embedded Linux (Kernel 2.6.31).
It is a AT91SAM9G20 chip inside, and some of the Pins are forwarded to the outside.
Now I want to use them as GPIO Inputs.
I read the gpio.txt documentation about using the GPIOs via filesystem, and that works very well 'til here. I connected some switches to the gpio-pins and I can see the result in /sys/class/gpio/gpioX/value
. But now I'd like to react on a change without busy-waiting in a loop. (i.e echo "Switch1 was pressed").
I guess I need interrupts here, but I couldn't find out how to use them without writing my own kernel driver. I'm relatively new to Linux and C (I normally program in Java), so I'd like to handle the Interrupts via sysfs too. But my problem is, that there is no "edge"-file in my GPIO directory (I guess because this is only since Kernel version 2.6.33+). Is that right? Instead of "edge" I've got a uevent
file in there, which is not described in gpio.txt
.
In the gpio.txt documentation there was a Standard Kernel Driver mentioned: "gpio_keys". Is it possible to use this for my problem?
I guess it would be better to work with this driver than allowing a userspace program to manipulate kernel tasks.
I found a lot of codesnippets for writing my own driver, but I wasn't even able to find out which of the 600 gpio.h
files to include, and how to refer to the library (cross compiler couldn't find the gpio.h file).
Sorry for newbie questions, I hope you could give me some advices.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 this 有关如何执行此操作的示例。基本上,您缺少的是
select
或poll
系统调用的使用。See this for an example on how to do that. Basically, the thing you're missing is the usage of the
select
orpoll
system calls.