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.\n", 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.\n", FILE);

  1. 写函数的本质是将应用层传递过来的数据先复制到内核中,然后以正确的方式写入硬件
    应用和驱动之间的数据交换:
    copy_from_user:将数据从用户空间复制到内核空间
    copy_to_user:
    注意:复制是和mmap的映射相对应区分的
posted on 2018-07-01 15:58  Ocean&Star  阅读(122)  评论(0编辑  收藏  举报