linux驱动学习1---led驱动

来源:互联网 发布:桥梁工程施工测量软件 编辑:程序博客网 时间:2024/05/15 05:19


1. uboot启动内核,
   内核启动应用程序。

  
2. 应用程序找到相应的驱动程序流程

  -------------------------------------------------
   应用层: open   read   write  poll
         c库                                                    软件
  ---------------------------------------------------------------
   system call interface
   system_open system_read  system_write    --- >> VFS
  
  驱动: led_open led_read led_write  
  -------------------------------------------------
  具体的硬件                                              硬件
  ----------------------------------------------------------------
  
 
3. 驱动程序编写

(1)编写led_open, led_read, led_write
(2)定义一个file_operations,加入定义的函数
(3)入口函数,将驱动注册进内核
       register_chrdev(major, name, &file_operations);
(4)出口函数,卸载驱动函数
       unregister_chrdev(major, name, &file_operations);
   
      
4. 建立主设备号,应用程序和驱动建立连接

(1)驱动程序里可以自动分配主设备号
           手工指定主设备号

(2)应用程序 open("dev/xxx",...)

 手工建立:a. mknod /dev/xxx c, majro, minor
 自动建立:b. udev mdev 根据信息建立设备节点
      -> class
            -> class_device.
 

 

 

 


   

原创粉丝点击