第一个Linux字符设备驱动程序和应用测试
2017-03-19 22:19
232 查看
1 首先写一个字符设备源文件 xxx.c 字符设备驱动程序的框架结构/*文件打开函数*/
int scull_open(struct inode *inode,struct file *filp);
/*文件释放函数*/
int scull_release(struct inode *inode, struct file *filp);
/*读函数*/static ssize_t scull_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos);
/*写函数*/static ssize_t scull_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos);
/* seek文件定位函数 */static loff_t scull_llseek(struct file *filp, loff_t offset, int whence);
/*文件操作结构体*/static const struct file_operations scull_fops ={};
/*设备驱动模块加载函数*/static int sculldev_init(void);
/*模块卸载函数*/static void sculldev_exit(void);2 编写头文件xxx.h3 编写Makefile完成以上3个步骤后编译make生成xxx.ko安装到系统内sudo insmod xxx.ko 查看驱动设备cat /proc/devices前面的数字为主设备号,如果与已有设备号冲突,则需要修改主设备号创建设备节点sudo mknod xxxx c AA BB上边xxxx 代表设备驱动的名称 c 代表字符设备 AA 主设备号 BB次设备号可以用 ls -al xxxx 查看驱动设备的相关信息4 编写应用程序main.c 测试驱动程序编译并执行执行时需要加sudo
相关文章推荐
- Linux字符设备驱动程序的设计
- Linux字符设备驱动程序的编写框架
- Linux字符设备驱动程序的编写框架
- Linux字符设备驱动程序开发
- 深入浅出 Linux字符设备驱动程序解析
- Linux 2.6字符设备驱动程序样例
- linux字符设备驱动程序相关的数据结构及操作
- Linux 2.6 字符设备驱动程序
- 深入浅出Linux字符设备驱动程序解析(转自http___linux_chinaitlab_com_driver_720255_html)
- Linux字符设备驱动程序编写基本流程
- linux字符设备驱动程序学习实验记录
- 一个简单的演示用的Linux字符设备驱动程序
- Linux设备驱动程序学习(1)-字符设备驱动程序
- 【转】+【改】Linux 2.6字符设备驱动程序样例
- Linux字符设备驱动程序开发之笔记及摘要
- LINUX2.6.26.6内核下的第一个LED驱动程序测试成功!
- linux字符设备驱动程序设计概述
- Linux设备驱动程序学习(1)-字符设备驱动程序
- Linux字符设备驱动程序开发
- Linux 2.6 字符设备驱动程序