gpt4 book ai didi

c - 选择(),轮询()或 epoll()?对于 sysfs 属性

转载 作者:IT王子 更新时间:2023-10-29 00:21:53 27 4
gpt4 key购买 nike

我正在处理 gpio 中断。我在“/sys/class/gpio/gpio38/value”中有一个文件。每当属性 value 发生变化时,我都希望收到通知。那么我怎样才能在用户空间中实现这一点。由于我已经收集了信息,所以我可以使用 select()、poll() 或 epoll()。那么对于这个应用程序哪个是正确的?或者请建议我是否可以使用/proc/irq 或其他东西。谢谢:)

最佳答案

我找到了一些东西 here这可能有帮助:

GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42) and have the following read/write attributes:

"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.

虽然它说它适用于“gpio42”,但我猜这可能适用于您的情况。如果没有,请在我的回答中发表评论。

关于c - 选择(),轮询()或 epoll()?对于 sysfs 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12541922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com