驱动函数的基本框架 您所在的位置:网站首页 驱动调用应用层函数 驱动函数的基本框架

驱动函数的基本框架

#驱动函数的基本框架| 来源: 网络整理| 查看: 265

1 、驱动程序和应用层的联系 1.1 从应用层看

1)首先APP斗调用Open(“dev/xxx”,O_REWR)打开设备文件后,会得到此设备文件的属性,知道属性中的“设备类型”和“主设备号”。 2)然后VFS层通过“设备类型”(如字符设备类型)去内核中的“chrdev”这个数组。在通过APP得到的“主设备号”以此为索引从内核的"chrdev"数组中知道相应的“file_operation”结构。这个结构是驱动程序“register_chrdev”注册到内核的,这样索引找到它。这个结构中有相应的一些成员函数(如read,write等),这些成员函数就对应硬件的读写操作等。 file_operation的结构体如下:

struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); int (*readdir) (struct file *, void *, filldir_t); unsigned int (*poll) (struct file *, struct poll_table_struct *); int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 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 (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, struct dentry *, int datasync); int (*aio_fsync) (struct kiocb *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有