问题描述
我对Linux内核和GPIO有一些疑问.我知道在Linux中所有内容都是文件,因此当我执行
I have some question about Linux kernel and GPIOs. I know that in Linux everything is file so when I do something like
echo 30 > /sys/class/gpio/export
和
echo 1 > /sys/class/gpio/gpio30/value
真正发生了什么?我的意思是sysfs如何处理呢?它会调用在gpiolib中实现的系统调用吗?
what really happens? I mean how does sysfs handle that? Does it call system calls implemented in gpiolib?
推荐答案
gpiolib 以这种方式注册value属性:
The gpiolib registers the value attribute in this way:
static const DEVICE_ATTR(value, 0644, gpio_value_show, gpio_value_store);
它创建一个名为value
的设备属性,权限为644
;在读取时调用gpio_value_show
,在写入时调用gpio_value_store
It creates a device attribute named value
, with permission 644
; on read it calls gpio_value_show
, on write it calls gpio_value_store
sysfs的作用是将read
和write
重定向到sysfs属性的相应功能.
What sysfs does, is to redirect read
and write
to the correspondent function of a sysfs attribute.
这篇关于Linux GPIO处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!