b0b0b
Posts: 7
Joined: Wed Oct 23, 2013 4:17 pm

GPIO to SYSFS

Sat Nov 02, 2013 5:39 pm

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

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: GPIO to SYSFS

Sat Nov 02, 2013 6:34 pm

The file is not updated, as it is no file in that sense.

Only if read, the value that seems to come from the file ist generated by the kernel.

b0b0b
Posts: 7
Joined: Wed Oct 23, 2013 4:17 pm

Re: GPIO to SYSFS

Sun Nov 03, 2013 12:52 pm

So... how is it generated?

User avatar
rpdom
Posts: 15199
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO to SYSFS

Sun Nov 03, 2013 1:35 pm

When you read or write to "files" in /sys, the values are passed to the relevant drivers (in this case the gpio driver). That then reads or writes the appropriate locations in memory where the values are stored as if they were an actual file.

For example, if you do "echo '1' >/sys/class/gpio/gpio27/value", then the driver will write the value 0x08000000 to memory location 0x7e20001c, meaning "Set gpio 27 high".

If you do "cat /sys/class/gpio/gpio27/value", then the driver will return "0" or "1" depending on the value of bit 27 of location 0x7e200034.

Return to “Raspbian”