【Tiny6410 And Linux】—(1.1)—kobject——代码
来源:互联网 发布:最锋利的美工刀片 编辑:程序博客网 时间:2024/05/10 11:56
总该有个先后,原理在上一篇文章也有介绍,所以这篇文章就是代码喽~~
还是先是程序,然后是图!
1、驱动程序
①、kobject.c
#include <linux/device.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/string.h>#include <linux/sysfs.h>#include <linux/stat.h>MODULE_AUTHOR("_Justin");MODULE_LICENSE("GPL");/* 函数声明 */void obj_test_release(struct kobject *);ssize_t kobj_test_show(struct kobject *,struct attribute *,char *);ssize_t kobj_test_store(struct kobject *,struct attribute *,const char *,size_t);static struct kobject kobj;static struct attribute test_attr = {.name = "Kobj_config",.mode = S_IRWXUGO,};static struct attribute *def_attrs[] = {&test_attr,NULL,};static struct sysfs_ops obj_test_sysops ={.show = kobj_test_show,.store = kobj_test_store,};static struct kobj_type ktype ={.release = obj_test_release,.sysfs_ops = &obj_test_sysops,.default_attrs = def_attrs,};void obj_test_release(struct kobject *kobject){printk("eric_test: release!\n");}ssize_t kobj_test_show(struct kobject *kobject,struct attribute *attr,char *buf){printk("Have show -->\n");printk("attrname: %s.\n",attr->name);sprintf("buf,%s\n",attr->name);return strlen(attr->name) + 2;}ssize_t kobj_test_store(struct kobject *kobject,struct attribute *attr,const char *buf,size_t size){printk("Have store -->\n");printk("write: %s.\n",buf);return size;}static int __init kobj_test_init(){printk("Kobject test init.\n");kobject_init_and_add(&kobj,&ktype,NULL,"kobject_test");return 0;}static void __exit kobj_test_exit(){printk("Kobject test exit.\n");kobject_del(&kobj);}module_init(kobj_test_init);module_exit(kobj_test_exit);
②、Makefile
ifneq ($(KERNELRELEASE),)obj-m := kobject.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.1)—kobject——代码
- 【Tiny6410 And Linux】—(1.1)—kobject——原理
- 【Tiny6410 And Linux】—(1.2)—kset——代码
- 【Tiny6410 And Linux】—(1.3)—bus 设备模型——代码
- 【Tiny6410 And Linux】—(1.4)—device 设备模型——代码
- 【Tiny6410 And Linux】—(1.5)—driver 设备模型——代码
- 【Tiny6410 And Linux】—(2.1)—platform 总线、设备、驱动——代码
- 【Tiny6410 And Linux】—(2.3)—使用工作队列处理按键中断——代码
- 【Tiny6410 And Linux】—(2.4)—实现 input 模型按键驱动——代码
- 【Tiny6410 And Linux】—(6.1)—LCD 驱动测试程序——代码
- 初学kobject--kobject的作用(—)
- 【Tiny6410 And Linux】——LED 驱动程序设计——代码
- 【Tiny6410 And Linux】——基于 platform 总线的按键驱动——代码
- 【Tiny6410 And Linux】—(5.1)—RamDisk 驱动实现(内核缺省的处理函数 __make_request())——代码
- 【Tiny6410 And Linux】—(5.2)—RamDisk 驱动实现(自己绑定 make_request_fn() )——代码
- 【Tiny6410 And Linux】—(6.2)—LCD 驱动测试程序(BMP 显示位图)——代码
- 【Tiny6410 And Linux】—(2.2)—Linux 中断处理——原理
- Tiny6410学习—Linux命令
- Firefox火狐浏览器 链接点击之后不能变色的一种解决方法
- 位运算
- NSDate 农历
- Linux下读写速度测试
- NSDate 农历节日
- 【Tiny6410 And Linux】—(1.1)—kobject——代码
- linux下epoll如何实现高效处理百万句柄的
- [亲情]风雨过后尽开颜
- 闹钟源码解析
- Eclipse快捷键大全
- C#代码鉴赏1
- 查看Apache并发请求数及其TCP连接状态
- 第十章1
- 实现tomcat启动时自动运行代码