How is sysfs updated when a GPIO changes state?

匆匆过客 提交于 2019-12-12 13:19:38

问题


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

What happens (in kernel space) when the signal applied to the pin X changes its state (for example from low to 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?

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


回答1:


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

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, 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_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).



来源:https://stackoverflow.com/questions/19744811/how-is-sysfs-updated-when-a-gpio-changes-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!