佳能70d模式转盘详解:linux字符设备驱动模版本 - hisashi的日志 - 网易博客
来源:百度文库 编辑:中财网 时间:2024/10/05 13:25:53
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12
13
14 #define MAJOR 123
15
16 static int XXXX_major=MAJOR;
17
18 struct XXXX_dev
19 {struct cdev cdev;
20 int data;
21 };
22
23 struct XXXX_dev* XXXX_devp;
24
25 int XXXX_open (struct inode *inode, struct file *filp )
26 {filp->private_data=XXXX_devp;
27 return 0;
28 }
29
30 int globalmem_release(struct inode *inode,struct file *filp)
31 {return 0;
32 }
33
34 static int XXXX_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
35 {struct XXXX*dev=filp->private_data;
36 switch(cmd)
37 {case 1: ~~~~~~~~~~~~~~~~~~~~~~~
38 break;
39 default:
40 return -EINVAL;
41 }
42 return 0;
43 }
44
45 static ssize_t XXXX_read(struct file *filp,char __user *buf,size_t size,loff_t *ppos)
46 {struct XXXX_dev *dev=filp->private_data;
47
48 ~~~~~~~~~~~~~~~~~~~~~~~~
49 ~~~~~~~~~~~~~~~~~~~~~~~~
50 }
51
52
53 static ssize_t XXXX_write(struct file *filp ,const char __user *buf,size_t size,loff_t *ppos)
54 {struct XXXX_dev *dev = filp->private_data;
55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 }
58
59
60
61 static loff_t XXXX_llseek(struct file *filp,loff_t offset,int orig)
62 {
63 }
64
65
66
67 static const struct file_operations XXXX_fops =
68 {
69 .owner=THIS_MODULE,
70 .llseek=XXXX_llseek,
71 .read=XXXX_read,
72 .write=XXXX_write,
73 .ioctl=XXXX_ioctl,
74 .open=XXXX_open,
75 .release=XXXX_release,
76 };
77
78
79 static void XXXX_setup_cdev(struct XXXX_dev *dev, int index)
80 {int err,devno=MKDEV(XXXX_major,index);
81 cdev_init(&dev->cdev,&XXXX_fops);
82 dev->cdev.owner=THIS_MODULE;
83 dev->cdev.ops=&XXXX_fops;
84 err=cdev_add(&dev->cdev,devno,1);
85 if(err) printk(KERN_NOTICE "Error %d adding led %d",err,index);
86 }
87
88 int XXXX_init(void)
89 {int result;
90 dev_t devno=MKDEV(XXXX_major,0);
91 if(XXXX_major) result=register_chrdev_region(devno,1,"globalmem");
92 else
93 {result=alloc_chrdev_region(&devno,0,1,"globalmem");
94 XXXX_major=MAJOR(devno);
95 }
96 if(result<0)
97 return result;
98 XXXX_devp=kmalloc(sizeof(struct XXXX_dev),GFP_KERNEL);
99 if(!XXXX_devp)
100 {return -ENOMEM;
101 goto fail_malloc;
102 }
103 memset(XXXX_devp,0,sizeof(struct XXXX_dev));
104 XXXX_setup_cdev(XXXX_devp,0);
105 return 0;
106 fail_malloc:unregister_chrdev_region(devno,1);
107 return result;
108 }
109
110
111 void globalmem_exit(void)
112 {cdev_del(&XXXX_devp->cdev);
113 kfree(XXXX_devp);
114 unregister_chrdev_region(MKDEV(XXXX_major,0),1);
115 }
116
117 MODULE_AUTHOR("YE Zongtai");
118 MODULE_LICENSE("Dual BSD/GPL");
119
120 module_param(XXXX_major,int,S_IRUGO);
121
122 module_init(XXXX_init);
123 module_exit(XXXX_exit);
~
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12
13
14 #define MAJOR 123
15
16 static int XXXX_major=MAJOR;
17
18 struct XXXX_dev
19 {struct cdev cdev;
20 int da
21 };
22
23 struct XXXX_dev* XXXX_devp;
24
25 int XXXX_open (struct inode *inode, struct file *filp )
26 {filp->private_da
27 return 0;
28 }
29
30 int globalmem_release(struct inode *inode,struct file *filp)
31 {return 0;
32 }
33
34 static int XXXX_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
35 {struct XXXX*dev=filp->private_da
36 switch(cmd)
37 {case 1: ~~~~~~~~~~~~~~~~~~~~~~~
38 break;
39 default:
40 return -EINVAL;
41 }
42 return 0;
43 }
44
45 static ssize_t XXXX_read(struct file *filp,char __user *buf,size_t size,loff_t *ppos)
46 {struct XXXX_dev *dev=filp->private_da
47
48 ~~~~~~~~~~~~~~~~~~~~~~~~
49 ~~~~~~~~~~~~~~~~~~~~~~~~
50 }
51
52
53 static ssize_t XXXX_write(struct file *filp ,const char __user *buf,size_t size,loff_t *ppos)
54 {struct XXXX_dev *dev = filp->private_da
55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 }
58
59
60
61 static loff_t XXXX_llseek(struct file *filp,loff_t offset,int orig)
62 {
63 }
64
65
66
67 static const struct file_operations XXXX_fops =
68 {
69 .owner=THIS_MODULE,
70 .llseek=XXXX_llseek,
71 .read=XXXX_read,
72 .write=XXXX_write,
73 .ioctl=XXXX_ioctl,
74 .open=XXXX_open,
75 .release=XXXX_release,
76 };
77
78
79 static void XXXX_setup_cdev(struct XXXX_dev *dev, int index)
80 {int err,devno=MKDEV(XXXX_major,index);
81 cdev_init(&dev->cdev,&XXXX_fops);
82 dev->cdev.owner=THIS_MODULE;
83 dev->cdev.ops=&XXXX_fops;
84 err=cdev_add(&dev->cdev,devno,1);
85 if(err) printk(KERN_NOTICE "Error %d adding led %d",err,index);
86 }
87
88 int XXXX_init(void)
89 {int result;
90 dev_t devno=MKDEV(XXXX_major,0);
91 if(XXXX_major) result=register_chrdev_region(devno,1,"globalmem");
92 else
93 {result=alloc_chrdev_region(&devno,0,1,"globalmem");
94 XXXX_major=MAJOR(devno);
95 }
96 if(result<0)
97 return result;
98 XXXX_devp=kmalloc(sizeof(struct XXXX_dev),GFP_KERNEL);
99 if(!XXXX_devp)
100 {return -ENOMEM;
101 goto fail_malloc;
102 }
103 memset(XXXX_devp,0,sizeof(struct XXXX_dev));
104 XXXX_setup_cdev(XXXX_devp,0);
105 return 0;
106 fail_malloc:unregister_chrdev_region(devno,1);
107 return result;
108 }
109
110
111 void globalmem_exit(void)
112 {cdev_del(&XXXX_devp->cdev);
113 kfree(XXXX_devp);
114 unregister_chrdev_region(MKDEV(XXXX_major,0),1);
115 }
116
117 MODULE_AUTHOR("YE Zongtai");
118 MODULE_LICENSE("Dual BSD/GPL");
119
120 module_param(XXXX_major,int,S_IRUGO);
121
122 module_init(XXXX_init);
123 module_exit(XXXX_exit);
~
设备驱动
linux字符界面下能上网么。
linux下字符界面怎么显示中文
那里有纯字符的linux 下载?
如何在Linux字符界面下回滚
如何在Linux字符界面回滚
linux下网卡驱动
linux 的网卡驱动
linux 安装显卡驱动
关于linux网卡驱动
D101GGC 装 linux驱动
本医院欲求购HIS系统软件---急
输入设备怎样驱动
关于蓝牙设备驱动
未知设备 驱动 PCI
游戏设备驱动
游戏设备驱动?/
关于声音设备驱动
Linux用装驱动吗?
linux下的硬件驱动
ati x800gto驱动 for linux
富士施乐linux驱动
驱动For linux 哪里有?
linux gcc下字符转换整型的函数?