GPIO更改状态时,如何更新sysfs? [英] How is sysfs updated when a GPIO changes state?

查看:175
本文介绍了GPIO更改状态时,如何更新sysfs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假定可以在sysfs中将gpio X导出为输入引脚,然后在/sys/class/gpio/中创建一个名为gpioX的目录. gpioX/包含少量文件,例如"value",它们代表gpio X的当前状态(高或低).

Assume that the gpio X can be exported in sysfs as an input pin, after doing that a directory called gpioX will be created into /sys/class/gpio/. gpioX/ contains few file such as "value" which represents the current state of the gpio X (high or low).

当施加到引脚X的信号改变其状态(例如,从低到高)时,会发生什么(在内核空间中)?

What happens (in kernel space) when the signal applied to the pin X changes its state (for example from low to high)?

我的意思是,在转换前gpioX/value包含"low",但之后它将包含"high"值.操作系统如何更新此文件?

I mean, before the transition gpioX/value contains "low", but after that it will contain "high" value. How is this file updated by the OS?

我认为需要一个中断机制.它是否使用中断机制来更新sysfs?

I think that an interrupt mechanism is required.Does it use an interrupt mechanism to update sysfs?

推荐答案

操作系统如何更新此文件?我认为需要一种中断机制.

How is this file updated by the OS? I think that an interrupt mechanism is required.

除非支持轮询,否则不需要中断机制( man poll )或备用的异步通知.至少在大多数版本中,/sys/class/gpio/仅在有人读取文件时才读取GPIO级别.

It does not require an interrupt mechanism unless it supports polling (man poll) or alternate asynchronous notifications. At least with most version, the /sys/class/gpio/ only does a read of the GPIO level when someone reads the file.

sysfs debugfs configfs procfs 等是虚拟文件系统.当您访问文件时,Linux内核中的代码将运行以提供该值. sysfs 仅提供类似于接口的文件;这并不表示它已得到支持的实际状态.状态是可以随时读取的GPIO级别.

sysfs, debugfs, configfs, procfs, etc are virtual file systems. When you access the file, code within the Linux kernel runs to provide the value. sysfs only provides a file like interface; that doesn't mean it is backed with actual state. The state is the GPIO level which can be read at any time.

gpio .txt 获取更多信息(尤其是您的特定Linux版本).

gpio_value_show() appears to be the current implementation. What you describe with interrupts is possible. It can be done through the sysfs_set_active_low() function or the sysfs file /sys/class/gpio/gpioN/edge. Writing to the file may return an error if the GPIO doesn't support interrupts. See gpio.txt for more (especially for your particular version of Linux).

这篇关于GPIO更改状态时,如何更新sysfs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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