To use sysfs, enable kernel config : CONFIG_GPIO_SYSFS
Core files related with this : gpiolib.c at Kernel
sysfs nodes can be found at /sys/class/gpio
[ Prerequisite ]
writing value to '/sys/class/gpio/export' uses 'gpio_request()' function at gpiolib in kernel.
So, if given gpio is already requested by other owner, exporting is failed.
Therefore, gpio should not be owned by others in kernel to control gpio at user space.
[ How to use at user space ]
Assumption : current working directory is '/sys/class/gpio'
#> echo [gpio num] > export
=> export give gpio to sysfs. gpioN link is newly created if gpio number is valid one.
#> cd gpioN
=> Then, several nodes (active_low, direction, value etc) can be found.
Writing or reading following nodes, is one of useful way to debug/control gpio at user space.
(attribute functions for each node are defined at gpiolib.c)
[ Detail Example ]
* at /sys/class/gpio
export, unexport : gpio number
#> echo 86 > export
#> echo 86 > unexport
* at /sys/class/gpio/gpioN
direction : in, out, low, high
value : 0, 1
edge : none, rising, falling, both
active_low : 0, 1
#> echo in > direction
#> echo 1 > value
#> echo both > edge
< See gpio.txt of Kernel document for details about each sysfs node. >
'Domain > Kernel' 카테고리의 다른 글
[Kernel] SMP and IRQ - case (2011-Sep) (0) | 2011.09.23 |
---|---|
[Kernel] Potential bug for using jiffies - ex. schedule_timeout() - at Linux kernel. (0) | 2011.08.18 |
[Kernel] module & parameter initialization. (0) | 2011.06.08 |
[Kernel] kobject uevent in kernel (0) | 2011.04.19 |
[Kernel] Creating user-space process in Kernel (0) | 2011.04.19 |