字符设备驱动01

Code:
  1. 设备号的申请   
  2.     静态申请   
  3.     register_chrdev_region(dev_t from, unsigned count, const char *name)   
  4.     动态申请   
  5.     alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)   
  6.     <baseminor>起始的次设备号   
  7. 注销设备号   
  8.     void unregister_chrdev_region(dev_t from, unsigned count)   
  9. 手工创建设备文件   
  10.     mknod filename type major minor   
  11.     例:  mknod serial0 c 100 0   
  12. LINUX字符设备2中数据结构   
  13.     Struct File代表打开的文件   
  14.         重要成员   
  15.         loff_t f_pos/*文件读写位置*/  
  16.     Struct Inode物理上存在的文件   
  17.         重要成员   
  18.         dev_t i_rdev/*设备号*/  
  19.     struct file_operations *f_op   
  20.     例:  struct file_operations men_fpos = {   
  21.         .owner = THIS_MODULE,   
  22.         .llseek = mem_seek,   
  23.         .read = mem_read,   
  24.         .write = mem_write,   
  25.         .ioctl = mem_ioctl,   
  26.         .open = mem_open,   
  27.         .release = mem_release,   
  28.         };   
  29. 设备注册   
  30.     使用struct cdev来描述   
  31.     分配cdev   
  32.         struct cdev *cdev_alloc(void)   
  33.     初始化cdev   
  34.         void cdev_init(struct cdev *cdev, const struct file_operation *fops)       
  35.     设备的注册   
  36.         int cdev_add(struct cdev *p, dev_t dev, unsigned count)   
  37. 设备操作   
  38.     int (*open)(struct inode *, struct file *)   
  39.     void (*release)(struct inode *, struct file *)   
  40.     ssize_t (*read)(struct file *, char __user *buff, size_t, loff_t *offp)   
  41.     ssize_t (*write)(struct file*, conct char __user *buff, size_t,loff_t *offp)   
  42.     unsigned int (*poll)(struct file *, struct poll_table_struct *)   
  43.     int (*ioctl)(struct iond *, struct file *, unsigned int, unsigned long)   
  44.     int (*mmap)(struct sile *, struct vm_area_struct *)   
  45.     off_t (*llseek)(struct file *, loof_t, int)   
  46. 读和写(与用户空间的交互)   
  47.     int copy_from_user(void *to, const void __user *form, int n)   
  48.     int copy_to_user(void __user *to, const void *from, int n)   
  49. 设备注销   
  50.     int cdev_del(struct cdev *p)  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值