欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

字符设备驱动开发 Linux 设备号 字符设备驱动开发步骤 open 函数调用流程  设备号的组成 设备号的分配 Linux 应用程序对驱动程序的调用 字符设备注册与注销 实现设备的具体操作函数

程序员文章站 2022-07-14 15:18:47
...

字符设备驱动简介

         字符设备是 Linux 最基本的设备驱动

         字符设备就是一个一个字节,按字节流进行读写操作,读写数据分 先后顺序

         字符设备驱动包括 点灯、按键、 IIC、 SPI,LCD 等

    Linux 应用程序对驱动程序的调用

字符设备驱动开发 Linux 设备号 字符设备驱动开发步骤 open 函数调用流程  设备号的组成 设备号的分配 Linux 应用程序对驱动程序的调用 字符设备注册与注销 实现设备的具体操作函数

   

 

      应用程序 运行在 用户空间

      驱动 运行在 内核空间

    open 函数调用流程

字符设备驱动开发 Linux 设备号 字符设备驱动开发步骤 open 函数调用流程  设备号的组成 设备号的分配 Linux 应用程序对驱动程序的调用 字符设备注册与注销 实现设备的具体操作函数

 

 

// file_operations 结构体

struct file_operations
{ 
    struct module *owner;                                                     // 该结构体的模块的指针
    loff_t (* llseek) (struct file *, loft_t, int);                           // 修改文件当前的读写位置
    ssize_t (* read) (struct file *, char __user *, size_t, loff_t *);        // 读取设备文件
    ssize_t (* weite) (struct file *, const char __user *, size_t, loff_t *); // 向设备文件写入数据
    ssize_t (* read_iter) (struct kiocb *, struct iov_iter *);                   
    ssize_t (* write_iter) (struct kiocb *, stuct iov_iter *);
    int (* iterate) (struct file *, struct dir_context *);
    unsigned int (* poll) (struct file *, struct poll_table_struct *);        // 
    long (* unlocked_ioctl) (struct file *, unsigned int, unsigned long);     // 
    long (* compat_ioctl) (struct file *, unsigned int, unsigned long);       // 
    int (* mmap) (struct file *, struct vm_area_struct *);
    int (* mremap) (struct file *, struct vm_area_struct *);
    int (* open) (struct inode *, struct file *);
    int (* flush) (struct file *, fl_owner_t id);
    ssize_t ()
};

 

 

 

字符设备驱动开发步骤

 

 

Linux 设备号

       

 

     

 

 

相关标签: Linux驱动开发