以我內核模塊我有以下讀取功能:copy_to_user:處理多個數據
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)?
你說的'複製到用戶空間更data'和'複製到用戶空間也值爲INT X = gpio_get_value(BTN_2)?'是什麼意思? –
您可以從sysfs中導出設備信息/值,而不是使用結構。 – askb
嗨askb ...我不知道如何使用sysfs。你可以做一個例子或一個小的解釋? – Anth