【发布时间】:2014-12-30 03:32:39
【问题描述】:
在我的内核模块中,我有以下读取功能:
static ssize_t sample_read(struct file *filp, char *buffer, size_t length, loff_t * offset) //read function here means to manage the communication with the button
{
int ret = 1;
int c;
c = gpio_get_value( BTN );
copy_to_user( buffer, &c, 1 ); //Buffer is the stack where to place the data read by function. copy_to_user copies the buffer on the user space. Here the reading is very simple. But if I would like to transfer more data?
printk( KERN_INFO "%s: %s read %d from BTN\n", module_name, __func__, c );
return( ret );
}
这里我通过缓冲区将c的值(也就是gpio的值)复制到用户空间。
如果我需要使用 copy_to_user 函数将更多数据复制到用户空间?
例如,如果我还想将值复制到用户空间 int x = gpio_get_value( BTN_2 )?
【问题讨论】:
-
copy to user space more data和copy to user space also a value int x = gpio_get_value( BTN_2 )?是什么意思? -
您可以从 sysfs 导出设备信息/值,而不是使用结构。
-
嗨 askb... 我不知道如何使用 sysfs。你能举个例子或小解释一下吗?
标签: c linux-kernel kernel kernel-module