Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98999
  • 博文数量: 28
  • 博客积分: 1435
  • 博客等级: 上尉
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-26 11:40
文章分类

全部博文(28)

文章存档

2017年(1)

2012年(1)

2011年(6)

2010年(20)

我的朋友

分类:

2010-05-05 12:55:33

HOST端要做的事情:
硬件和软件
host端需要的硬件是:USB host controller and a root hub with one or more USB ports.
           软件是: an operating system that enables device drivers to communicate with lower-level drivers that access the USB hardware.
一个host controller总是和一个root hub结合在一起的,(但是还是不能把两者结合成一个设备,因为他们还是有具体的不同作用的)从linux的host controller driver就可以看出,struct hc_driver中即包含了对host controller的操作,也包含了对root hub的操作。上面所说的软件也就是这个host controller driver。

1. 探测设备(detect device)
On power-up, hubs make the host aware of all attached USB devices. In a process
called enumeration, the host determines what bus speed to use, assigns an
address, and requests additional information. After power-up, whenever a
device is removed or attached, a hub informs the host of the event, and the host
enumerates any newly attached device and removes any detached device from
its list of devices available to applications.
从这里可以知道,host controller和root hub的具体分工。root hub只是通知host controller有设备插入或断开,host controller接到通知后开始一个
叫做enumeration的过程(枚举),确定通信速率,分配地址等。建立真正的通信通道。

2. 控制数据流(manage data flow)
The host manages traffic on the bus. Multiple devices may want to transfer data
at the same time. The host controller divides the available time into intervals
and gives each transmission a portion of the available time.
During enumeration, a device’s driver requests bandwidth for transfers that
must have guaranteed timing. If the bandwidth isn’t available, the driver can
request a smaller portion of the bandwidth or wait until the requested band-
width is available. Transfers that have no guaranteed timing use the remaining
bandwidth and must wait if the bus is busy.
在数据传输方面,usb采用了分时的策略。传输带宽是在枚举的时候就已经确定好了的并且得以保证。

3. 错误检查(error checking)
When transferring data, the host adds error-checking bits. On receiving data,
the device performs calculations on the data and compares the result with
received error-checking bits. If the results don’t match, the device doesn’t
acknowledge receiving the data and the host knows it should retransmit.
 In a similar way, the host error-checks data received from devices.
USB also supportsa transfer type without acknowledgments for use with data such as real-time audio that tolerates errors to enable a constant transfer rate.
错误检查很容易理解,在传输数据的时候,发送方在数据中加入error-checking bits,接受方收到数据后用收到的数据计算出来的校验码和
发送方发出的校验码是否一致,不一致就不回应发送方,发送方没有接到回应就重新发送数据。usb也支持没有错误校验的传输。

4. 供电和电源管理
In addition to data wires, a USB cable has wires for a +5V supply and ground.
Some devices draw all of their power from the bus. The host provides power to
all devices on power up or attachment and works with the devices to conserve
power when possible. A high-power USB 2.0 device can draw up to 500 mA
from the bus. A high-power SuperSpeed device can draw up to 900 mA from a
USB 3.0 bus. Ports on some battery-powered hosts and hubs support only
low-power devices, which are limited to 100 mA (USB 2.0) or 150 mA (Super-
Speed). To conserve power when the bus is idle, a host can require devices to
enter a low-power state and reduce their use of bus current.

5. 交换数据
All of the above tasks support the host’s main job, which is to exchange data
with devices. In some cases, a device driver requests the host to attempt to send
or receive data at defined intervals, while in others the host communicates only
when an application or other software component requests a transfer.



DEVICE端要做的事情:
device端要做的事情分两类,一类是和HOST对应的事情,host请求,device必须给予回应。令一类就是device端自己的事情。

1.响应HOST
On power up or when a device attaches to a powered system, a device must
respond to standard requests sent by the host computer during enumeration.
The host may also send requests any time after enumeration completes.
All devices must respond to these requests, which query the capabilities and sta-
tus of the device or request the device to take other action. On receiving a
request, the device places data or status information in a buffer to send to the
host. For some requests, such as selecting a configuration, the device takes other
action in addition to responding to the host computer.
The USB specification defines requests, and a class or vendor may define addi-
tional requests. On receiving a request the device doesn’t support, the device
responds with a status code.

2. 错误检查
同HOST端类似

3. 数据传输
For most transfers where the host sends data to the
device, the device responds to each transfer attempt by sending a code that indicates whether the device accepted the data or was too busy to accept it.
For most transfers where the device sends data to the host, the device must respond
to each attempt by returning data or a code indicating the device has no data to
send.
数据传输分两种,HOST给DEVICE传输数据和HOST请求DEVICE发送数据。两者都有响应的应答机制(a code).
DEVICE不可以主动给HOST发送数据,只有当HOST请求其发送数据的时候才可以发送。(USB3.0中device可以发送code让host请求)

阅读(5661) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:时间测量

给主人留下些什么吧!~~