摘要: 打开int open(struct inode *inode,struct file *filp);模块使用计数加1识别次设备号硬件操作检查设备相关错误(诸如设备未就绪或类似的硬件问题)如果设备是首次打开,则对其初始化如果有中断操作,申请中断处理程序关闭int release(struct inode *inode,struct file *filp);模块使用计数减1释放由open分配的,保存在filp>private_data里的所有内容。硬件操作:如果申请了中断,则释放中断中中断处理程序。在最后一次关闭操作时关闭设备。read/writessize_t read(struct fi 阅读全文
posted @ 2012-12-02 21:18 黑-色-柳—丁 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 一:字符设备开发的基本步骤 1.确定主设备号和次设备号主设备和号是内核识别一类设备的标识。整数(占12位)一般1-255次设备号由内核使用,用于正确确定设备文件所指的设备。整数(20位)一般0-255设备编号的内部表示dev_t类型(32位)用来保存设备编号(包括主设备号(12位)和次设备号(20位))从dev_t获得主设备号和次设备号:MAJOR(dev_t);MINOR(dev_t);将主设备号和次设备号转换成dev_t类型:MKDEV(int major,int minor); 分配主设备号手工分配主设备号:找一个内核没有使用的主设备号来使用#include<linux/fs.h& 阅读全文
posted @ 2012-12-02 16:59 黑-色-柳—丁 阅读(207) 评论(0) 推荐(0) 编辑
摘要: helloworl.c#include<linux/init.h>#include<linux/module.h>MODULE_LICENSE("Dual BSD/GPL");static int hello_init(void){ printk("hello world"); return 0;}static void hello_exit(void){ printk("exit the hello world!\n");}module_init(hello_init);module_exit(hello_e 阅读全文
posted @ 2012-12-02 16:09 黑-色-柳—丁 阅读(356) 评论(0) 推荐(0) 编辑