【Tiny6410 And Linux】—(1.4)—device 设备模型——原理
来源:互联网 发布:mac电脑远程控制怎么弄 编辑:程序博客网 时间:2024/05/22 14:14
上一节原理中有一个特别重要的东西:
总线也是一个设备,必须按照设备注册!
1、设备描述结构
在 Linux 设备模型中,总线由 device 结构表示,定义在 <linux/device.h> 中。
其中 release 是必须要设置的!!!
struct device{ struct device *parent; /* 父设备 */ struct device_private *p; /* 设备私有数据 */ struct kobject kobj; /* 设备基类 */ const char *init_name; /* 设备初始化名称 */ struct bus_type *bus; /* 设备所在总线 */ struct device_driver *driver; /* 管理该设备的驱动 */ struct (*relaese)(struct device *dev); /* 设备释放方法 */ ...};
2、设备方法函数
设备的注册使用:
int device_register(struct device *dev);
设备的注销使用:
void device_unregister(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);};
其中 attr 成员用于描述属性的名称和对应属性文件的权限,show、store 成员方法则用于构造属性文件的读写嘻嘻,设备属性文件并不会随着设备的注册而自动创建,需要通过调用下面的函数来创建:
int device_create_file(struct device *device,struct device_attribute *entry);
设备属性文件删除使用函数:
void device_remove_file(struct device *dev,struct device_attribute *attr);
设备属性结构可以使用下面宏来完成初始化:
#define DEVICE_ATTR(_name,_mode,_show,_store) \struct device_attribute dev_attr_##_name = _ATTR(_name,_mode,_show,_store)
其中宏 __ATTR 定义在 linux/sysfs.h 下:
#define __ATTR(_name,_mode,_show,_store) { \ .attr = {.name = __stringify(_name),.mode = _mode}, \ .show = _show, \ .store = _store, \
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——原理
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——代码
- 【Tiny6410 And Linux】—(1.3)—bus 设备模型——原理
- 【Tiny6410 And Linux】—(1.5)—driver 设备模型——原理
- 【Tiny6410 And Linux】—(1.3)—bus 设备模型——代码
- 【Tiny6410 And Linux】—(1.5)—driver 设备模型——代码
- 【Tiny6410 And Linux】—(2.1)—platform 总线、设备、驱动——原理
- 【Tiny6410 And Linux】—(2.4)—实现 input 模型按键驱动——原理
- 【Tiny6410 And Linux】—(2.1)—platform 总线、设备、驱动——代码
- 【Tiny6410 And Linux】—(2.2)—Linux 中断处理——原理
- 【Tiny6410 And Linux】—(2.4)—实现 input 模型按键驱动——代码
- 【Tiny6410 And Linux】—(1.1)—kobject——原理
- 【Tiny6410 And Linux】—(1.2)—kset——原理
- 【Tiny6410 And Linux】—(2.3)—使用工作队列处理按键中断——原理
- 【Tiny6410 And Linux】—(6.1)—LCD 驱动测试程序——原理
- linux内核部件分析(六)——设备驱动模型之device
- linux内核部件分析(九)——设备驱动模型之device-driver
- linux内核部件分析(六)——设备驱动模型之device
- GDI创建旋转HFONT
- CentOS 6.2 VirtualBox虚拟机镜像
- winfrom属性formborderstyle:none以后
- IOS开发之——Core text使用
- Android权限大全代码
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——原理
- 让控件的DropdownMenu或者PopupMenu弹出来
- 可用。存储分页
- STL的默认allocator
- SAS9.1.3中文全功能版下载
- Android如何防止apk程序被反编译
- 关于求最大公约数的几种方法(第一次写博客,写的不好,大牛们请准备好板砖)
- appserv2.6 中phpmyadmin登陆问题的解决
- C语++笔试面试题收藏