Chinaunix首页 | 论坛 | 博客
  • 博客访问: 929873
  • 博文数量: 376
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1558
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-13 08:42
文章分类

全部博文(376)

文章存档

2014年(11)

2013年(88)

2012年(260)

2011年(17)

分类:

2012-03-31 18:37:54

序:近来一直在打酱油,闲暇之余分析了下usb gadget驱动。每天的工作就是扯,工作吧,你不扯还不行,哎,所以近来工作很郁闷,不过也该走啦。离开这个让我几乎窒息的华为,一直不明白为什么还有那么多的人挤着要进华为,哎,好啦,不扯啦,开始言归正转,分析下代码,不过我也是现学现卖,欢迎高手拍砖。
现总体看下gadget子系统。
                                   |  gadaet驱动  |(adb,大容量存储设备)
                                   |  gadget API  |(对UDC控制器驱动操作函数的封装)
                                   | UDC控制器驱动|(设备的控制器驱动)
不过这个架构在android系统中又复杂了很多。最新的android4.0和android2.3.7的代码结构已经不一样啦,这也是昨天才发现的,所以今天看了一天android4.0的kernel,不过没有完全搞懂,学了一点就先记下来,当做笔记吧,也好供以后查看。
先贴几个重要的结构体再说:
  1. struct android_dev {
  2.     struct android_usb_function **functions;//该android_dev支持的功能如adb,大容量存储
  3.     struct list_head enabled_functions;// 开启的功能链表
  4.     struct usb_composite_dev *cdev;//符合设备的dev
  5.     struct device *dev;//支持设备驱动模型的dev

  6.     bool enabled;
  7.     struct mutex mutex;//操作该结构体是用到的互斥锁
  8.     bool connected;//记录当前的连接状态
  9.     bool sw_connected;//记录切换后的连接状态
  10.     struct work_struct work;//支持的工作队列
  11. };

  1. struct android_usb_function {
  2.     char *name;//该功能的名字
  3.     void *config;//该功能所依赖的配置

  4.     struct device *dev;//为设备驱动模型准备的device
  5.     char *dev_name;
  6.     struct device_attribute **attributes;

  7.     /* 挂入android_dev中的enabled_functions的链表节点*/
  8.     struct list_head enabled_list;

  9.     /* 在绑定的时候,执行的初始化函数*/
  10.     int (*init)(struct android_usb_function *, struct usb_composite_dev *);

  11.     /* 在解除绑定时,执行清除的函数*/
  12.     void (*cleanup)(struct android_usb_function *);
  13.     /* 把该function绑定到特定的配置上,此时function相当一个接口*/
  14.     int (*bind_config)(struct android_usb_function *, struct usb_configuration *);

  15.     /* Optional: called when the configuration is removed */
  16.     void (*unbind_config)(struct android_usb_function *, struct usb_configuration *);
  17.     /* Optional: handle ctrl requests before the device is configured */
  18.     int (*ctrlrequest)(struct android_usb_function *,
  19.                     struct usb_composite_dev *,
  20.                     const struct usb_ctrlrequest *);
  21. };
顺便补充下什么是符合设备?
Example:  a device with a single configuration supporting both network
 link and mass storage functions is a composite device.  Those functions
 might alternatively be packaged in individual configurations, but in
 the composite model the host can use both functions at the same time.
这点英语看懂了吧,这就是符合设备。
现贴这么多吧,等完全分析明白了再写个专题。

阅读(602) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~