USB - 如何保持主机和设备间的连接

USB 总线上的 USB 通信是通过若干机制维持的,这些机制旨在确保 USB 主机和连接设备之间进行连续可靠的数据交换。以下是保持 USB 通信活跃和顺畅运行的关键方面:

1. 轮询和调度:

    * USB 主机定期轮询所连接的设备,检查是否有数据需要发送或接收。轮询定期进行,确保设备有机会与主机通信。

2. 帧开始(SOF)数据包:

    * USB 主机在每个帧开始时发送帧开始(SOF)数据包(USB 1.1 和 USB 2.0 每 1 毫秒发送一次,USB 2.0 微帧每 125 微秒发送一次)。这些数据包有助于同步通信并保持总线定时的准确性。

3. 数据传输类型:

    * 控制传输: 用于设备配置和命令/响应通信。

    * 批量传输: 用于无特定时间要求的大数据传输,如向 USB 驱动器传输文件。

    * 中断传输: 用于需要保证延迟的小型快速数据传输,如鼠标和键盘输入。

    * 等时传输: 用于对时间敏感的数据传输,如音频或视频流,在这种情况下,数据的定时传输至关重要。

4. 端点管理:

    * 每个 USB 设备都有作为数据传输通道的端点。主机对这些端点进行寻址,以发送和接收数据。

5. 错误检测和恢复:

    * USB 通信包括错误检测机制,如循环冗余校验(CRC),以确保数据完整性。如果检测到错误,主机和设备可以重试数据传输。

6. 流控:

    * 主机和设备使用流控机制来管理数据传输速率,确保任何一方都不会被过多的数据淹没。

7. 挂起和恢复:

    * USB 主机可将设备置于低功耗挂起状态,以节省能源,同时在需要时可快速恢复通信。设备可以向主机发出请求唤醒该设备和恢复通信的信号。

8. 描述符和枚举

    * 设备连接后,主机会执行枚举以识别设备及其功能。主机从设备读取描述符,以了解如何与其正确通信。

9. 电源管理:

    * USB 规范包括电源管理功能,可确保设备获得所需的电源,同时有效管理电流消耗。

10. 集线器通信:

    * USB 集线器可将多个设备连接到一个主机端口。主机通过与集线器通信来管理下游设备,确保正确的数据流和功率分配。

通过采用这些机制,USB 通信保持活跃和可靠,使多个设备能够通过 USB 总线与主机进行有效通信。

USB communication is maintained on the USB bus through several mechanisms designed to ensure continuous and reliable data exchange between the USB host and connected devices. Here are the key aspects that keep USB communication active and functioning smoothly:

1. Polling and Scheduling:

    * The USB host regularly polls connected devices to check for data that needs to be sent or received. This is done at regular intervals, ensuring that devices have the opportunity to communicate with the host.

2. Start-of-Frame (SOF) Packets:

    * The USB host sends Start-of-Frame (SOF) packets at the beginning of each frame (every 1 millisecond for USB 1.1 and USB 2.0, and every 125 microseconds for USB 2.0 microframes). These packets help synchronize communication and keep the bus timing accurate.

3. Data Transfer Types:

    * Control Transfers: Used for device configuration and command/response communication.

    * Bulk Transfers: Used for large data transfers with no specific timing requirements, like file transfers to a USB drive.

    * Interrupt Transfers: Used for small, quick data transfers that need guaranteed latency, like mouse and keyboard inputs.

    * Isochronous Transfers: Used for time-sensitive data transfers, such as audio or video streaming, where data delivery at regular intervals is crucial.

4. Endpoint Management:

    * Each USB device has endpoints that act as channels for data transfer. The host addresses these endpoints to send and receive data.

5. Error Detection and Recovery:

    * USB communication includes error detection mechanisms, such as Cyclic Redundancy Check (CRC) to ensure data integrity. If errors are detected, the host and device can retry the data transfer.

6. Flow Control:

    * The host and devices use flow control mechanisms to manage data transfer rates and ensure that neither side becomes overwhelmed with too much data at once.

7. Suspend and Resume:

    * While the USB host can put devices into a low-power suspend state to save energy, communication can be quickly resumed when needed. Devices can signal the host to wake up and resume communication.

8. Descriptors and Enumeration:

    * When a device is connected, the host performs enumeration to identify the device and its capabilities. The host reads descriptors from the device to understand how to communicate with it properly.

9. Power Management:

    * The USB specification includes power management features to ensure that devices receive the power they need while managing energy consumption efficiently.

10. Hub Communication:

    * USB hubs allow multiple devices to be connected to a single host port. The host communicates with hubs to manage downstream devices, ensuring proper data flow and power distribution.

By employing these mechanisms, USB communication is kept active and reliable, allowing multiple devices to communicate effectively with the host over the USB bus.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值