#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.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/cdev.h>
#include <linux/types.h> #define xxx_DEVICE_COUNT 1 /*自己主动创建设备节点类*/
static struct class *xxx_dev_class;
static struct class_device *xxx_dev_class_dev; /*
xxx设备相关的相关操作函数:open、read、write、close、ioctl等
*/
static int xxx_dev_open(struct inode *inode, struct file *filp)
{
printk("Open xxx device OK.\n");
return 0;
} static int xxx_dev_close(struct inode *inode, struct file *filp)
{
printk("Close xxx device OK.\n");
return 0;
} static int xxx_dev_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
printk("Write xxx device OK.\n");
return 0;
} static int xxx_dev_read(struct file *file, const char __user *buf, size_t count, loff_t ppos)
{
printk("Read xxx device OK.\n");
return 0;
} static int xxx_dev_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
printk("DRIVER : Get cmd %d.\n", cmd);
return 0;
} /*
xxx设备操作函数结构体
*/
struct file_operations xxx_fops = {
.owner = THIS_MODULE,
.open = xxx_dev_open,
.release = xxx_dev_close,
.read = xxx_dev_read,
.write = xxx_dev_write,
.ioctl = xxx_dev_ioctl,
}; /*
xxx设备驱动模块的注冊和卸载
*/
int xxx_major = 0;
static int __init initialization_xxx_dev(void)
{
/* 注冊设备号 */
printk("Before register xxx Major = %d\n", xxx_major);
if (xxx_major) {
register_chrdev(xxx_major, "xxx", &xxx_fops);
} else {
xxx_major = register_chrdev(0, "xxx", &xxx_fops);
}
printk("After register xxx Major = %d\n", xxx_major); /* 自己主动生成设备节点 */
xxx_dev_class = class_create(THIS_MODULE, "xxx_dev");
xxx_dev_class_dev = class_device_create(xxx_dev_class, NULL, MKDEV(xxx_major, 0), NULL, "xxx");
/* 模块初始化成功必须返回0 */
printk("Module register OK.\n");
return 0;
} static void __exit cleanup_xxx_dev(void)
{
/* 删除设备文件 */
unregister_chrdev(xxx_major, "xxx");
class_device_unregister(xxx_dev_class_dev);
class_destroy(xxx_dev_class); printk("Module unregister OK.\n");
} /*
模块注冊与卸载
*/
module_init(initialization_xxx_dev);
module_exit(cleanup_xxx_dev); /*
模块传參:insmod char_driver_frame_old.ko xxx_major=xxx
*/
module_param(xxx_major, int, S_IRUGO); /*
模块的相关声明
*/
MODULE_AUTHOR("lhbo");
MODULE_DESCRIPTION("GPIO Driver for xxx");
MODULE_LICENSE("GPL");

linux字符设备驱动程序框架(老方法)的更多相关文章

  1. 浅析Linux字符设备驱动程序内核机制

    前段时间在学习linux设备驱动的时候,看了陈学松著的<深入Linux设备驱动程序内核机制>一书. 说实话.这是一本非常好的书,作者不但给出了在设备驱动程序开发过程中的所须要的知识点(如对 ...

  2. ARM Linux字符设备驱动程序

    1.主设备号和次设备号(二者一起为设备号): 一个字符设备或块设备都有一个主设备号和一个次设备号.主设备号用来标识与设备文件相连的驱动程序,用来反  映设备类型.次设备号被驱动程序用来辨别操作的是哪个 ...

  3. 一步步理解linux字符设备驱动框架(转)

    /* *本文版权归于凌阳教育.如转载请注明 *原作者和原文链接 http://blog.csdn.net/edudriver/article/details/18354313* *特此说明并保留对其追 ...

  4. 简单linux字符设备驱动程序

    本文代码参考<LINUX设备驱动程序>第三章 字符设备驱动程序 本文中的“字符设备”是一段大小为PAGE_SIZE的内存空间 功能:向字符设备写入字符串:从字符设备读出字符串 代码: 1. ...

  5. 一个简单的演示用的Linux字符设备驱动程序

    实现如下的功能:--字符设备驱动程序的结构及驱动程序需要实现的系统调用--可以使用cat命令或者自编的readtest命令读出"设备"里的内容--以8139网卡为例,演示了I/O端 ...

  6. Linux字符设备驱动框架

    字符设备是Linux三大设备之一(另外两种是块设备,网络设备),字符设备就是字节流形式通讯的I/O设备,绝大部分设备都是字符设备,常见的字符设备包括鼠标.键盘.显示器.串口等等,当我们执行ls -l ...

  7. Linux驱动实践:你知道【字符设备驱动程序】的两种写法吗?

    作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...

  8. Linux字符设备简单示例

    1. Linux字符设备是一种按字节来访问的设备,字符驱动则负责驱动字符设备,这样的驱动通常实现open.close.read和write系统调用.例如:串口.Led.按键等. 2. 通过字符设备文件 ...

  9. 嵌入式Linux驱动学习之路(二十一)字符设备驱动程序总结和块设备驱动程序的引入

    字符设备驱动程序 应用程序是调用C库中的open read write等函数.而为了操作硬件,所以引入了驱动模块. 构建一个简单的驱动,有一下步骤. 1. 创建file_operations 2. 申 ...

随机推荐

  1. LeetCode 653. Two Sum IV – Input is a BST

    Given a Binary Search Tree and a target number, return true if there exist two elements in the BST s ...

  2. PAT Basic 1028

    1028 人口普查 某城镇进行人口普查,得到了全体居民的生日.现请你写个程序,找出镇上最年长和最年轻的人. 这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过200岁的老人,而 ...

  3. 【转】Sqlserver通过链接服务器访问Oracle的解决办法

    一.创建sqlserver链接服务(sqlserver链接oracle)  首先sqlserver 链接oracle可以通过两个访问接口: “MSDAORA” 和“OraOLEDB.Oracle” 1 ...

  4. http过程

    当在浏览器里输入URL地址时,http的通讯过程: 1) 连接 DNS解析:URL——>DNS服务器(找到返回其ip,否则继续将DNS解析请求传给上级DNS服务器) Socket连接:通过IP和 ...

  5. angular 创建项目

    介绍有很多可用的工具可以帮助你开发AngularJS 应用,那些非常复杂的框架不在我的讨论范围之中,这也是我开始这系列教程的原因.在第一部分,我们掌握了angularjs框架的基本结构,开发了第一应用 ...

  6. Neural Networks and Deep Learning

    Neural Networks and Deep Learning This is the first course of the deep learning specialization at Co ...

  7. ps 批量杀死进程

    ps aux | grep xxx |awk '{print $2}'|xargs kill -9

  8. BZOJ 3240 [Noi2013]矩阵游戏 ——费马小定理 快速幂

    发现是一个快速幂,然而过不去. 怎么办呢? 1.十进制快速幂,可以用来练习卡时. 2.费马小定理,如果需要乘方的地方,可以先%(p-1)再计算,其他地方需要%p,所以需要保存两个数. 然后就是分类讨论 ...

  9. BZOJ 3926 [Zjoi2015]诸神眷顾的幻想乡 ——广义后缀自动机

    神奇的性质,叶子节点不超过20个. 然后把这些节点提出来构成一颗新树,那么这些树恰好包含了所有的情况. 所以直接广义后缀自动机. 然后统计本质不同的字符串就很简单显然了. #include <c ...

  10. Redis的数据类型及相关操作命令

    redis 基础内容 —— redis的数据类型及相关操作的Linux命令.所谓大厦千层基础承载,希望大家认真学习这一讲: 一.redis 的五大数据类型: 1.String(字符串): 2.List ...