USB device和USB host

2023-11-19

USB,英文全称:Universal Serial Bus,即通用串行总线。

常常各种USB芯片同时具有host和device两种接口。host就是主的,可以起控制作用;device(slave)就是从,是被控制的。比如PC机的USB口,可以识别U盘或者其他USB设备,起到控制的作用,就是host;而U盘是被控制的,是device(slave)。

只有一个host和一个device(slave)才能起到数据传输或者控制的作用。

而还有一种称为OTG,例如芯片ISP1761就有OTG的口,它是指它既可以做host口也可以做device(slave)口。




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请求)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

USB device和USB host 的相关文章

  • QT信号和槽机制实现及源码阅读

    说明 QT的信号和槽采用观察者模式 Q OBJECT是提供信号和槽的基础 使用过connect第五个参数的可知 槽可以在信号发出的线程处理 也可以加入任务队列进行处理 但是在此只写了在触发线程处理的代码 如下是实现的类QT信号和槽 gt F
  • 终于有人把软件测试用例讲清楚了(一定要收藏)

    目录 1 公司流程 1 1 测试用例的4个特性 1 1 测试用例通常包括以下几个组成元素 1 编写测试用例的基本方法 1 1 1 概念 1 1 1 示例 1 1练习案例 1 1 边界值法 1 1 1 确定边界值的方法 1 1 因果图法 1
  • ubuntu 20.04装nvidia显卡驱动

    装这个显卡驱动遇到了很多问题 第一次装了两三天没有成功 休息了一个星期 又来试 终于成功了 显卡驱动安装 1 检查自己的显卡型号 lspci grep i vga 会出现一个16进制的数字 选有nvidia的那个就是独显 我的是TU104M
  • visual studio:解决方案资源管理器中限定为此范围的显示与取消

    参考 VS 解决方案资源管理器中限定为此范围的显示与取消
  • 利用python做一个超简单的抽签器

    抽签器 用python写一个超基础的简单版抽签器 我利用了list函数来存储待抽签的选项 先将候选人输入到列表中 再进行随机抽签 以下是代码 一个抽签器 能够从多人中随机抽取一人 import random def random draw
  • Seekbar细节

    Seekbar可以自定义thumb图标 但是有时候发现thumb没有展示完全 或者图标周围显示的是背景色 此时就需要设置一些属性 android background null android thumbOffset 0dp android
  • QT入门之QToolBar

    目录 一 QToolBar界面相关 1 布局介绍 2 界面基本属性 3 添加动作测试 4 代码添加动作 5 创建按钮 此文为作者原创 转载请标明出处 一 QToolBar界面相关 1 布局介绍 先看下界面中创建个toolBar 右键Main
  • 真题详解(传引用)-软件设计(七十五)

    真题详解 补码转换 软件设计 七十四 https blog csdn net ke1ying article details 130674214 分治算法技术设计 答案 1 问题划分 2 递归求解 3 合并解 虚拟存储体系 两级构成 解析
  • 3、RH850端口说明及及复用功能配置

    RH850端口有3种工作模式 通用IO口 普通数字口 PMC控制寄存器对应bit为0 软件配置复用模式 PMC控制寄存器对应bit为1 PIPC寄存器对应bit为0 硬件直接连接模式 PMC控制寄存器对应bit为1 PIPC寄存器对应bit
  • 冒号 定义成员函数_C++ 类成员 类成员的构造 冒号语法

    设有类CTime和CDate分别用于描述时间和日期 另外有CDateTime类描日期和时间 请为三个类给出具体的实现代码 并在main函数中测试 include includeusingnamespace 设有类CTime 和CDate分别
  • XMind 2020 for mac (XMind思维导图)

    xmind 2020中文版是一款十分实用的思维导图软件 相信很多用户都还不了解XMind XMind官方版优化了许多功能 性能上大大提高 使用XMind思维导图可以帮助用户完成逻辑图 树形图 组织结构图等 还可以导出ppt word 图片
  • 【java基础】 方法,实参和形参,方法的重载,签名,递归

    目录 方法概念及使用 实参和形参的关系 重要 方法的重载 方法签名 简单了解 递归 简单介绍 方法概念及使用 方法就是一个代码片段 类似于 C 语言中的 函数 作用 是能够模块化的组织代码 当代码规模比较复杂的时候 做到代码被重复使用 一份
  • element ui表单中嵌套时间和日期下拉选择并且提交给后端

    使用element ui 的
  • vue 中 ‘\“ 替换成 “/“

    var filePath trim filePath val 正则表达式替换字符 对于String对象的replace方法 表达式不加入g 则只替换第一个匹配 如果加入g 则替换所有匹配 var newFilPath filePath re
  • Scope, Duration, and Linkage___CH_6

    Each project corresponds to one program 6 1 Compound statements blocks A compound statement also called a block or block
  • 强化学习代码 (肖志清)部分

    目录部分 1 初识RL 2 Markov 决策过程 3 有模型数值迭代 4 回合更新价值迭代 5 时序差分价值迭代 6 函数近似方法 点击跳转原书代码链接 1 初识RL 解决我电脑中pip install不了的问题 pip install
  • KiCad使用笔记(01)-介绍及设置

    文章目录 为什么使用KiCad 使用前工作 简单认识 主界面 使用流程 已知存在问题 总结 为什么使用KiCad KiCad A Cross Platform and Open Source Electronics Design Autom

随机推荐