字符设备驱动开发

字符设备驱动开发
步骤:
kernel阶段:
1.申请设备号
静态申请:指定主设备号和次设备号
int register_chrdev_region(dev_t from, unsigned count, const char *name)
参数:dev_t from------->设备号
unsigned count—>设备数
const char *name–>设备名
返回值:成功返回0,失败返回其他值
动态申请:自动申请未被占用的设备号
alloc_chrdev_region()
2.初始化设备cdev
cdev_init(struct cdev *cdev, const struct file_operations *fops)
参数:struct cdev *cdev------>存放设备基本信息
const struct file_operations *fops----->对设备的操作
3.添加设备
cdev_add(struct cdev *p, dev_t dev, unsigned count)
4.创建节点
1命令行输入:mknod /dev/mychr c 500 0
| | | |
名称 字符型设备 主设备号 次设备号
2自动创建:
a)class_create(owner, name)
参数:owner—>一般用THIS_MODULE
name---->逻辑类名 随便取
返回值:struct class
b)device *device_create(struct class *class, struct device *parent,
dev_t devt, void *drvdata, const char *fmt)
参数:struct class *class
device *parent—>NULL
dev_t devt-------->设备号
void *drvdata----->NULL
const char *fmt---->节点设备名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值