• 5.2.11.添加读写接口


    1. ./app

    如果app只使用了write(fd, "hellowrite", 10);没有read的话,./app没有反应

    error:如果该写了驱动,则应该重新安装驱动

    #lsmod
    Module                  Size  Used by    Not tainted
    module_test             1087  0
    
    # cat /proc/devices
    
    # lsmod
    
    # insmod module_test.ko
    
    #mknod /dev/test c 250 0
    #ls /dev/test -l
    
    #./app
    

    [ 143.016905] test_chrdev_open
    open /dev/test su[ 143.175274] test_chrdev_write
    [ 143.179043] test_chrdev_release
    ccess.
    j--->
    [ 143.016905] test_chrdev_open ----------------->test_chrdev_open --------->test_chrdev_open 1. fd = open(FILE, O_RDWR);
    open /dev/test success. -------------------->main 2.printf("open %s success. ", FILE);
    [ 143.175274] test_chrdev_write ----------------->test_chrdev_write --------->test_chrdev_write 3.write(fd, "hellowrite", 10);
    [ 143.179043] test_chrdev_release ----------------->test_chrdev_release --------->test_chrdev_release 4.close(fd);

     #./app
    

    [ 566.922098] test_chrdev_open ----------------->test_chrdev_open --------->test_chrdev_open 1. fd = open(FILE, O_RDWR);
    [ 566.923665] test_chrdev_write ----------------->test_chrdev_write --------->test_chrdev_write 3.write(fd, "hellowrite", 10);
    [ 566.926485] test_chrdev_read ----------------->test_chrdev_read --------->test_chrdev_read 4.read(fd, buffer, 10);
    [ 566.929342] test_chrdev_release ----------------->test_chrdev_release --------->test_chrdev_release 5.close(fd);
    open /dev/test success. -------------------->main 2.printf("open %s success. ", FILE);

    1. 写函数的本质是将应用层传递过来的数据先复制到内核中,然后以正确的方式写入硬件
      应用和驱动之间的数据交换:
      copy_from_user:将数据从用户空间复制到内核空间
      copy_to_user:
      注意:复制是和mmap的映射相对应区分的
  • 相关阅读:
    磁盘冗余 ---RAID磁盘管理
    linux磁盘管理
    linux基础命令
    Apache配置rewrite
    memcache运维整理
    mysql主从配置
    rsync相关整理
    Lua 学习笔记(六)
    Lua 学习笔记(五)
    Lua 学习笔记(四)
  • 原文地址:https://www.cnblogs.com/Ocean-Star/p/9250363.html
Copyright © 2020-2023  润新知