【Tiny6410 And Linux】—(1.4)—device 设备模型——代码
来源:互联网 发布:小米mix2全球网络制式 编辑:程序博客网 时间:2024/05/22 15:29
这三个程序本是一体的!
但是一开始写的时候有这个顺序,所以也就来这个顺序吧!!
1、内核代码
①、bus.c
这个代码跟上一篇文章的代码一样,我也就是拷贝的!
②、device.c
#include <linux/device.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/string.h>MODULE_AUTHOR("_Justin");MODULE_LICENSE("GPL");extern struct device my_bus_dev;extern struct bus_type my_bus_type;static void my_dev_release(struct device *dev){printk("[Call my_dev_release!]\n");}struct device my_dev = {.init_name = "my_dev",.bus = &my_bus_type,.parent = &my_bus_dev,.release = my_dev_release,/* 这个函数必须有,可以为空 */};/* 属性文件的读操作 */static ssize_t mydev_show(struct device *dev,struct device_attribute *attr,char *buf){return sprintf(buf,"%s\n","This is my device!");}/* 创建结构描述的属性文件 */static DEVICE_ATTR(dev,S_IRUGO,mydev_show,NULL);static int __init my_device_init(void){int ret = 0;printk("[Call my_device_init!]\n");/* 注册设备 */ret = device_register(&my_dev);if(ret)return ret;/* 创建属性文件 */ret = device_create_file(&my_dev,&dev_attr_dev);return ret;}static void __exit my_device_exit(void){printk("[Call my_device_exit!]\n");device_unregister(&my_dev);}module_init(my_device_init);module_exit(my_device_exit);
③、Makefile
ifneq ($(KERNELRELEASE),)obj-m := device.oelseKDIR := /home/_Jana/linux-2.6.38all:make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-clean:rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.orderendif
2、测试结果
- 【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.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
- linux内核部件分析(九)——设备驱动模型之device-driver
- 1000~2000内能被17与37同时整除的数
- redhat 6.2(x64) 配置tomcat+nginx
- 分苹果问题
- SAP ALV 详细说明 .
- 视频采集的基本流程
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——代码
- 三个数大小的比较
- C#多线程之 任务工厂
- javascript 编程风格
- Spring MVC 文件上传下载
- Morphia 学习四 数据类型与容器
- Android logcat在dos窗口下输出的中文乱码问题
- 十个数大小的比较
- web.xml中对spring的监听