
-
编译kernel命令
1
./device/amlogic/common/quick_build_kernel.sh bootimage -j2
-
ioctl驱动init
1
2
3
4
5
6
7
8
9
10
11static int __init (void)
{
int status;
printk("%s %dn",__func__,__LINE__);
status = misc_register(&pi_device);
if(status){
printk("%s:misc_register failedn",__func__);
return -1;
}
return 0;
} -
上下层接口,底层通过ioctl进行参数传递
通过pi_ioctl函数来进行switch选择1
2
3
4
5
6
7
8
9
10
11static const struct file_operations pi_fops = {
.owner = THIS_MODULE,
.open = pi_open,
.read = pi_read,
.write = pi_write,
.release = pi_release,
.unlocked_ioctl = pi_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = pi_compat_ioctl,
#endif
}; -
下面是pi_ioctl里面的switch控制逻辑,当switch传入的宏定义是CLOSE_DLP_LDE,将会关闭DLP灯管
1
2
3
4
5
6
7
8
9
10
11
12
13
14static long pi_ioctl(struct file *file,unsigned int cmd,unsigned long arg)
{
switch(cmd){
case CLOSE_DLP_LED:
printk("close dlp ledn");
break;
default:
printk("default moden");
break;
}
printk("%s---->n",__func__);
return 0;
} -
目前就是kernel里面基本就写完了ioctl的驱动,目前就是需要上层进行配对
在Codes_pwd/external/目录里面新建一个目录。如下1
2
3
4mkdir Codes_pwd/external/testioctl
cd Codes_pwd/external/testioctl/
touch ioctl.c
touch Android.mk -
开始编辑ioctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main(int argc,char const *argv[]){
int iomask = 2;
if((fd = open("/dev/pi",O_RDWR)) <0){
printf("Open error on /dev/pin");
exit(0);
}
ioctl(fd,CLOSE_DLP_LED,iomask);
return 0;
} -
Android.mk
1
2
3
4
5
6
7
8
9
10LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_SRC_FILES := ioctl.c
LOCAL_MODULE := testioctl
LOCAL_CPPFLAGS += -DANDROID
LOCAL_SHARED_LIBRARIES := libc
inclde $(BUILD_EXECUTABLE)




近期评论