最方便的字符设备驱动的写法
记录一下
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <linux/poll.h>
#include <linux/device.h>static int major;
static struct class *class;
static struct class_device *ker_dev;static int ker_rw_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{switch ( cmd ) {case 0 :printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);break;case 1 :printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);break;case 2 :printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);break;case 3 :printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);break;case 4 :printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);break;default:printk("line:%d,cmd:%d,arg:%ld", __LINE__, cmd, arg);return -EINVAL;
}return 0;
}static struct file_operations ker_rw_ops = {.owner = THIS_MODULE,.ioctl = ker_rw_ioctl,
};static int ker_rw_init(void)
{major = register_chrdev(0, "ker_rw", &ker_rw_ops);class = class_create(THIS_MODULE, "ker_rw");/* 为了让mdev根据这些信息来创建设备节点 */ker_dev = class_device_create(class, NULL, MKDEV(major, 0), NULL, "ker_rw"); /* /dev/ker_rw */return 0;
}static void ker_rw_exit(void)
{class_device_unregister(ker_dev);class_destroy(class);unregister_chrdev(major, "ker_rw");
}module_init(ker_rw_init);
module_exit(ker_rw_exit);MODULE_LICENSE("GPL");
最方便的字符设备驱动的写法相关推荐
- 获取另一个驱动的设备结构体_字符设备驱动的另一种写法
字符设备驱动的另一种写法 在Linux2.6内核中,使用cdev结构体描述一个字符设备; cdev结构体(include/linux/cdev.h)定义如下: struct cdev { struct ...
- 深入浅出:Linux设备驱动之字符设备驱动
一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面向流 ...
- 蜕变成蝶~Linux设备驱动之字符设备驱动
一.linux系统将设备分为3类:字符设备.块设备.网络设备.使用驱动程序: 字符设备:是指只能一个字节一个字节读写的设备,不能随机读取设备内存中的某一数据,读取数据需要按照先后数据.字符设备是面向流 ...
- 三.字符设备驱动高级
目录 一.注册字符设备驱动新接口1 1.1.新接口与老接口 1.2.register_chrdev_region与alloc_chrdev_region函数简介 1.3.cdev介绍 1.4.设备号 ...
- 基于Cortex-A7架构的嵌入式linux ARM驱动开发<1>——字符设备驱动开发
一.什么是字符设备 字符设备是 Linux 驱动中最基本的一类设备驱动,字符设备就是一个一个字节,按照字节流进行读写操作的设备,读写数据是分先后顺序的.比如我们最常见的点灯.按键.IIC.SPI, L ...
- ()shi linux字符设备,Linux字符设备驱动基础(三)
Linux字符设备驱动基础(三) 6 创建设备节点 6.1 手动创建设备节点 查看申请的设备名及主设备号: cat /proc/devices # cat /proc/devices Characte ...
- 使用pinctrl 和 gpio 子系统的字符设备驱动
pinctrl 和 gpio 子系统的字符设备驱动 一. 修改设备树文件 二. LED 灯驱动程序编写 三.makefile 四.应用层代码 运行测试 一. 修改设备树文件 打开 imx6ull-al ...
- 设备树下字符设备驱动
设备树下字符设备驱动 一.在设备树里添加自己的节点 二.驱动代码 三.makefile 四.应用层代码 运行测试 总结 一.在设备树里添加自己的节点 alphaled { 2 #address-cel ...
- linux设备模型 字符设备,Linux 字符设备驱动模型之框架解说
一.软件操作硬件设备模型 在进行嵌入式开发的过程中,在常做的事情就是驱动配置硬件设 备,然后根据功能需求使用硬件设备,实现功能的逻辑.如下图为其 相互之间的关系. 如上图所示: 驱动程序:主要作为操作 ...
最新文章
- Linux后台开发应该具备技能
- vue-cli生成项目时你应当知道的
- 腐蚀和膨胀(erode and dilate)
- 我创业的时候从没想要去赚钱
- 【Webcam设计】USB摄像头(V4L2接口)的图片采集
- 服务器装凤凰系统,凤凰系统装在云服务器
- 完美卸载IE8/IE7安装IE6
- 组合数学1--组合数学简介
- 微软私有云服务器,微软发布私有云解决方案及数据平台
- ET框架6.0Demo运行学习笔记
- cesium绘制网格_Cesium (五) 栅格图层
- Cannot connect to the Maven process.Try again later.If the problem persists...
- 地质体剖面从构建到Web三维展示
- ListView实现item局部刷新
- 工业交换机的内部组成是什么?
- 仓库和门店移动出入库 手持移动终端 pda 扫描打印于一身 扫描打印小票和不干胶标签纸
- VMWare虚拟机下载|最新版|破解版
- velocity学习(2)--VTL 语法
- 互联网大佬们齐聚首,除了演讲还有啥?点击All in 全部热点!
- 信息安全-网络安全主动防御技术与应用(一)