第一个安卓驱动程序
来源:互联网 发布:备案域名交易平台top 编辑:程序博客网 时间:2024/05/21 09:52
hello~
经过了三个星期的网上资料学习,以及前人指导,终于算是完成了第一个安卓驱动.使用的是展讯的7715芯片,第一次写博客,权当记录下自己的学习经历吧.
驱动的.c文件
#include <linux/module.h>#include <linux/types.h>#include <linux/fs.h>#include <linux/errno.h>#include <linux/mm.h>#include <linux/sched.h>#include <linux/init.h>#include <linux/cdev.h>#include <asm/io.h>#include <asm/system.h>#include <asm/uaccess.h>#include <linux/kernel.h>#include <linux/delay.h>#include <asm/uaccess.h>#include <asm/irq.h>#include <linux/device.h>static struct class *firstdev_class;static struct device *firstdev_class_dev;static int first_dev_open(struct inode *inode,struct file *file){ printk("first_dev_open\n"); return nonseekable_open(inode, file);}static int first_dev_write(struct file *file, const char __user * buf, size_t count, loff_t *ppos){ printk("hello write.\n"); return 0;}static struct file_operations first_dev_fops = { .owner = THIS_MODULE, //一个宏 .open = first_dev_open, .write = first_dev_write,};int major;static struct cdev first_cdev;static struct class *cls;static int first_dev_init(void){ //major = register_chrdev(0,"first_dev",&first_dev_fops);//注册,告诉内核,主设备号.名称/* firstdev_class = class_create (THIS_MODULE, "firstdev");// if (IS_ERR(firstdev_class))// return PTR_ERR(firstdev_class); cdev_init(&first_dev, &first_cdev); cdev_add(&first_dev, MKDEV(major, 0), 1); firstdev_class_dev = device_create(firstdev_class, NULL, MKDEV(major, 0), NULL, "first_dev"); //设别节点会在dev/first_dev// if (unlikely(IS_ERR(firstdev_class_dev)))// return PTR_ERR(firstdev_class_dev);*/dev_t devid;if (major) { devid = MKDEV(major, 0); register_chrdev_region(devid, 1, "first"); /* (major,0~1) 对应 hello_fops, (major, 2~255)都不对应hello_fops */ } else { alloc_chrdev_region(&devid, 0, 1, "first"); /* (major,0~1) 对应 hello_fops, (major, 2~255)都不对应hello_fops */ major = MAJOR(devid); } cdev_init(&first_cdev, &first_dev_fops); cdev_add(&first_cdev, devid, 1); cls = class_create(THIS_MODULE, "first"); device_create(cls, NULL, MKDEV(major, 0), NULL, "first"); return 0;}static void first_dev_exit(vodi){ unregister_chrdev(major,"first_dev"); // 卸载 device_unregister(firstdev_class_dev); class_destroy(firstdev_class);}module_init(first_dev_init);module_exit(first_dev_exit);MODULE_LICENSE("GPL");
Makefile文件
obj-y += first_drv.o
Kconfig文件
config FIRST_DRV
bool “test”
default n
help
enable benchmark proc
应用程序.c文件
#include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include <stdio.h>int main(int argc , char **argv){ int fd; int val = 1; fd = open("/dev/first", O_RDWR); if(fd < 0) printf("ni haishi dabukai ya !\n"); write(fd, &val, 4); return 0;}
阅读全文
0 0
- 第一个安卓驱动程序
- 第一个驱动程序
- 第一个驱动程序
- 第一个驱动程序
- 构建第一个驱动程序
- helloworld第一个驱动程序
- 第一个android驱动程序
- 第一个中断驱动程序
- 第一个驱动程序
- 第一个Linux驱动程序
- 第一个驱动程序实验
- TQ2440 第一个驱动程序:LED驱动程序
- 第一个驱动程序---Hello world
- 编译第一个驱动程序笔记
- 我的第一个驱动程序
- 我的第一个驱动程序
- 第一个驱动程序-led驱动
- 调试第一个KMDF驱动程序
- NOI2002银河英雄传说 并查集
- Unity 游戏框架搭建 (十四) 优雅的QSignleton(零) QuickStart
- Android-NDK-之so文件签名校验
- Spring 4.2.2以上版本和swagger集成方案和踩过的坑
- 遇到版本号判断的一个原则
- 第一个安卓驱动程序
- Vue中使用vux的配置,分为两种情况:
- Windows Server2008 R2安装Mysql5.7.19时遇到问题:
- Mapreduce实现MapSideJoin
- Word Count (Map Reduce)
- Kotlin 一统天下?Kotlin/Native 开始支持 iOS 和 Web 开发
- Kaldi HMM拓扑和状态转换模型
- VueJs 监听 window.resize 方法---窗口变化
- WAP_WSP的Well-known header