USB相关内容总结

工作中涉及了一些USB相关的内容,整理总结一下。

概念

Universal Serial Bus (USB)通用串行总线,使主机可以与外设进行数据交换,外设共享USB带宽,可以并发访问。详细请访问USB官网进行了解。
协议文档下载路径:
USB Specification: http://www.usb.org/developers/docs/documents_archive/
USB Device Class: http://www.usb.org/developers/docs/devclass_docs/

USB系统

USB系统由USB host、USB devices、USB interconnect组成,即USB主机、USB设备以及两者之间的连接。
USB总线的拓扑结构如下图,由于hub和线缆的限制,最多7层,其中第一层是主机上的RootHub,最后一层只能是设备。(因为连了hub也没法再连设备了)
USB总线拓扑

USB Host

USB系统中只能有一个host,host上的USB接口也被称作USB Host Controller,集成了Root Hub,为USB devices提供连接点。一个Host Controller最多连接可127个设备,一般情况下,由主机向设备供电。

USB Devices

USB devices分为两种:Hub、Functions。
Hub可以提供更多的USB连接点。
A function is a USB device that is able to transmit or receive data or control information over the bus. A function is typically implemented as a separate peripheral device with a cable that plugs into a port on a hub.
Each function contains configuration information that describes its capabilities and resource requirements. Before a function can be used, it must be configured by the host. This configuration includes allocating USB bandwidth and selecting function-specific configuration options.
Functions可以为Host提供某种功能,例如:网卡、移动硬盘、蓝牙等。

这里要提到几个概念:configuration、interface、endpoint。

  • configuration,一个USB设备可以有多个configuration(一般只有一个);至少包含一个interface;设备枚举过程中,host通过USB request选择configuration;设备通过提供多个不同的配置,利用有限的资源提供更多的功能,例如:iPhone连接到电脑时,可以浏览手机上的照片视频;当连接到汽车导航时,可以做为iPod,播放手机上的音乐。当选择configuration 0(假设是0)的时候,iPhone作为一个相机设备,选择1的时候,iPhone作为一个音频设备。
  • interface,引用USB Specification中的一段话:An interface is a related set of endpoints that present a single feature or function of the device to the host.
    每个interface都可以有可选设定(Alternate setting),通过Alternate setting可以重新配置endpoint的数量。比较常用的情景是:Alternate setting 0没有endpoint,表示reset状态;Alternate setting 1有至少1个endpoint,代表工作状态。主机通过SetInterface()选择interface的Alternate setting。例如:CDC NCM(USB网卡)设备的Data interface,主机可以通过设置Alternate setting 0,即关闭数据传输通道来禁用网卡。
    有时由多个interface一起实现一个完整的功能,例如:USB Audio,包含一个Control interface(负责控制)和一个Audio stream interface。(负责传输Audio data)
  • endpoint,通俗的讲,端点就是一个管子的接头,主机将管子连接到这个端点之后,就可以根据端点的传输方向接收/发送数据。
    属性包括:Address、direction、transfer type、Max Packet Size等。
    Address是一个8bit的整数,0~3bit表示endpoint number,bit7表示direction。
    transfer type:Control、Isochronous、Bulk、Interrupt。

连接过程

从USB Devices连接到USB Host,到USB Devices可用,经历了哪些连接过程?以USB Device的状态进行说明:
这里写图片描述
主要说一下Address和Configured,由于Host Controller可以连接很多个设备(最多127个),所以每个设备连接到Host之后,都会被分配一个唯一的Address,在此之前使用默认地址进行通信。地址分配之后,就可以对设备进行Configure了。
Configure阶段,host对设备进行枚举,获取设备的描述信息,选择合适的驱动接管设备,设备驱动获取interface相关信息,进行interface相关设定,然后打开endpoints,与设备进行数据通信。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值