Linux驱动开发 (总线式设备驱动)_ssize_t ( store)(struct device dev, struct device

bus_type结构体:

-> 关键是match函数uevent函数 。

struct bus_type {
 
const char		*name;  //总线类型名
struct bus_attribute	*bus_attrs;  //总线属性和导出到sysfs中的方法
struct device_attribute	*dev_attrs;  //设备属性和导出到sysfs中的方法
struct driver_attribute	*drv_attrs;  //驱动程序属性和导出到sysfs中的方法
 
//匹配函数,检验参数2中的驱动是否支持参数1中的设备
int (*match)(struct device *dev, struct device_driver *drv);
int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
int (*probe)(struct device *dev);  //探测设备
int (*remove)(struct device *dev); //移除设备
void (*shutdown)(struct device *dev); //关闭函数
 
int (*suspend)(struct device *dev, pm_message_t state);//改变设备供电状态,使其节能
int (*resume)(struct device *dev);  //恢复供电状态,使其正常工作
 
const struct dev_pm_ops *pm;  //关于电源管理的操作符
 
struct bus_type_private *p;  //总线的私有数据
};

内核中 usb总线的定义:

在这里插入图片描述

内核中ac97总线的定义

在这里插入图片描述

总线私有数据:

struct bus type private {
 
struct kset subsys;/*代表该bus子系统,里面的kobj是该bus的主kobj,也就是最顶层*/ 
 
struct kset *drivers kset;/*挂接到该总线上的所有驱动集合*/ 
struct kset *devices kset;/*挂接到该总线上的所有设备集合*/ 
struct klist klist devices;/*所有设备的列表,与devices kset中的1ist相同*/
struct klist klist drivers;/*所有驱动程序的列表,与drivers_kset中的1ist相同*/ 
struct blocking notifier head bus notifier;/**/ 
unsigned int drivers autoprobe:1;/*设置是否在驱动注册时, 自动探测(probe)设备*/ 
struct bus type *bus;/*回指包含自己的总线*/
}

总线属性:

struct bus_attribute {
	struct attribute	attr;//总线属性
	ssize_t (*show)(struct bus_type *bus, char *buf);  //属性读函数
	ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);//属性写函数
};

2.设备

在Linux设备驱动模型中,每一个设备都由一个device结构体来描述。

device结构体包含了设备所具有的一些通用信息。

对于驱动开发人员来说,当遇到新设备时,需要定义一个新的设备结构体,将device作为新结构体的成员。这样就可以在新结构体中定义新设备的一些信息,而设备通用的信息就使用device结构体来表示。

使用device结构体的另一个好处是,可以通过device轻松地将新设备加入设备驱动模型的管理中。

device中的大多数函数被内核使用,驱动开发人员不用关注。

struct device是硬件设备在内核驱动框架中的抽象。

struct device {
 
struct klist_klist children;        连接子设备的链表
struct device *parent;              指向父设备的指针
struct kobject kobj;				内嵌的kobject结构体
char bus_id[BUS ID SIZE];			连接到总线上的位置
unsigned uevent suppress:1;			是否支持热插拔事件
const char init_name;				设备的初始化名字
struct device_type *type;			设备相关的特殊处理函数
struct bus_type *bus;				指向连接的总线指针
struct device_driver *driver;		指向该设备的驱动程序
void *driver data;					指向驱动程序私有数据的指针
struct dev_pm info power;			电源管理信息
dev t deyt;							设备号
struct class *class;				指向设备所属类
struct attribute_group **groups;	设备的组属性
void (*release) (struct device *dev);释放设备描述符的回调函数
 
}

设备属性:

struct device_attribute {
	struct attribute	attr;
	ssize_t (*show)(struct device *dev, struct device_attribute *attr,
			char *buf);
	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
			 const char *buf, size_t count);
};

用来在devic目录下创建一个属性文件:

int device_create_file(struct device *dev,  //创建
		       const struct device_attribute *attr)
void device_remove_file(struct device *dev,  //删除
			const struct device_attribute *attr)

3.驱动

-> struct device_driver是驱动程序在内核驱动框架中的抽象。

-> name,驱动程序的名字,很重要,经常被用来作为驱动和设备的匹配依据。

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新!!

%以上嵌入式&物联网开发知识点,真正体系化!**

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新!!

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值