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?
Sysfs is a pseudo filesystem provided by the Linux kernel that makes information about various kernel subsystems, hardware devices, and device drivers available in user space through virtual files. GPIO devices appear as part of sysfs.
sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files.
One of the foundational kinds of interfaces between the CPU and other hardware is the GPIO pin. A GPIO, or “General Purpose Input/Output” is a programmable digital pin that allows you to implement either input or output. They have no default behavior but can be configured in a number of useful ways.
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures. ( More precisely, the files and directories in sysfs provide a view of the kobject structures defined internally within the kernel.)
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With