Linux设备驱动学习

一、设备驱动概念

    设备驱动完成以下功能:

    1.对设备的初始化和释放

    2.把数据从内核传送到硬件和从硬件读取数据

    3.读取应用程序传送给设备文件和回送应用程序请求的数据

    4.检测和处理设备出现的错误


    可分为字符设备和块设备。

    区别:字符设备发出请求后,实际的I/O要紧接着发生;块设备利用一块系统缓冲区,缓冲区的内容可以满足用户请求,直接返回,不能的话,调用实际I/O。


    主设备号:驱动程序

    次设备号:同一驱动下不同设备


    应用程序通过系统调用来使用驱动程序,系统调用如下:

struct file_operations {

int (*seek) (struct inode * ,struct file *, off_t ,int);

int (*read) (struct inode * ,struct file *, char ,int);

int (*write) (struct inode * ,struct file *, off_t ,int);

int (*readdir) (struct inode * ,struct file *, struct dirent * ,int);

int (*select) (struct inode * ,struct file *, int ,select_table *);

int (*ioctl) (struct inode * ,struct file *, unsined int ,unsigned long

int (*mmap) (struct inode * ,struct file *, struct vm_area_struct *);

int (*open) (struct inode * ,struct file *);

int (*release) (struct inode * ,struct file *);

int (*fsync) (struct inode * ,struct file *);

int (*fasync) (struct inode * ,struct file *,int);

int (*check_media_change) (struct inode * ,struct file *);

int (*revalidate) (dev_t dev);

}

    驱动程序主要是实现这些系统调用。


    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值