驅動層代碼
static int __ite_ioctl(struct file *filp,unsigned int cmd,unsigned long arg )
{
printk("__ite_ioctl \n");
switch (cmd)
{
//獲取垂直解析度
case IT6604_IO_GET_RES:
{
arg=(unsigned long)&__hdmi_info;
printk("<%4d,%4d> \n",(int)__hdmi_info.h_active, (int)__hdmi_info.v_active);
break;
}
default:
break;
}
}
用戶層代碼
int main(void)
{
int fd = 0;
__input_info hdmi_info;
fd = open("/dev/myit6604",O_RDONLY);
if(fd < 0)
{
printf("open file error \n");
return -1;
}
if(ioctl(fd, IT6604_IO_READ,&hdmi_info) < 0)
{
printf("error\n");
return -1;
}
printf("<%d,%d> \n",(int)hdmi_info.h_res,(int)hdmi_info.v_res);
close(fd);
return 0;
}
執行用戶程式的代碼后結果
此時解析度為1080P的
mnt/demo/ioctrl # ./a.out
<0,72>
/mnt/demo/ioctrl # ./a.out
<0,72>
uj5u.com熱心網友回復:
內核態和應用態互動資料是否應該用copy_from_user和copy_to_user。還有一點,為什么ioctl的命令碼不一樣,兩個命令碼名稱不一樣,定義的是否相同。uj5u.com熱心網友回復:
命令碼是對的,宏定義不一樣, 內核態和應用態互動資料如果用copy_from_user和copy_to_use會不會效率變慢呢,我看著好多的例子都是用的copy_from_user和copy_to_useuj5u.com熱心網友回復:
命令碼是對的,宏定義不一樣, 內核態和應用態互動資料如果用copy_from_user和copy_to_use會不會效率變慢呢,我看著好多的例子都是用的copy_from_user和copy_to_useuj5u.com熱心網友回復:
內核態和用戶態記憶體是不能直接相互訪問的,必須用這兩個函式訪問。轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/99074.html
標籤:內核源代碼研究區
上一篇:在shell中$@和$*的區別
下一篇:美好的一周從周一開始
