HCI 流控

HCI 流控

这篇主要说明HCI流控(不是串口流控). 内容主要来自core spec V4.2. Vol 2 Part E, 第四节 HCI Flow Control. P770.

名词: CT: controler

当Remote device不回应ACL数据时, HCI流控是用来避免CT端ACL数据溢出缓冲区(buffer). The Host manages the data buffers of the Controller. 对于Primary Controller, packet based flow control is the default. 对于AMP Controller,data block based data flow control is the default for ACL traffic. 对于从CT到Host的流控可能会在Primary Controller中用到, 如4.2节描述.

Command flow control is covered in Section 4.4 and Section 4.5.

4.1 HOST TO CONTROLLER DATA FLOW CONTROL

有定义了两种Data flow control: 'packet-based' flow control和'data-block-based' flow control, known as buffer management. 选择流控的操作指令: the Write Flow Control Mode command, 定义在 Section 7.3.73中.

If a BR/EDR/LE Controller implements separate buffers for ACL Data:

  1. The Host shall use the LE Read Buffer Size command to determine the buffers that are used for ACL Data on an LE-U logical link.
  2. 对于每个不同的缓冲区, Host shall use 独立的packet based flow control.
  3. 包含在ACL data packet里的Connection_Handle会被Controller用来determine which set of buffers 会被使用; 并且哪个句柄用来发送`the logical link (ACL-U or LE-U)数据.

If a BR/EDR/LE Controller does not implement separate buffers:

所有的ACL data都使用如下所示的BR/EDR buffer management. 并且, Connection_Handle只是用来决定发送the logical link (ACL-U or LE-U)数据.

4.1.1 Packet-based Data Flow Control

LE: 如果packet based flow control mechanism已被使能, Host如果支持BLE, 就会发送一个LE Read Buffer Size指令, 其中两个返回的参数determine了最大的ACL(不包含header)Data Packets, 这个参数用来决定HOST到CT的LE transport上的参数; 并且, 还有一个额外的返回参数,被用来表示the total number of HCI ACL data packets, 含义是表示CT已经在等待传输的数量(totoal number).

image-20200602181553399

一个Primary Controller可能回应the total number 为0, (for在LE transport传输ACL数据). 这种情况下,Host会发送全部BR/EDR和LE数据, which using HCI ACL data packet, 发送的大小为the Read Buffer Size command命令返回的.

BR/EDR: 在BR/EDR控制器中,when the packet based flow control mechanism is enabled, 初始化的时候, Host会发送the Read Buffer Size command. 其中两个返回的参数determine了最大HCI ACL和 synchronous Data Packets数据长度(不包含header), 这些packet是从Host到Controler; 同样, 也有两个额外的参数表示the total number of HCI ACL and synchronous data packets, 含义是表示CT已经在等待传输的数量(totoal number).

image-20200602181359390

当至少已经连接到一个其他设备时, 或者在BR/EDR Controller回环模式中, 控制器会使用the Number Of Completed Packets event事件来控制从Host发来的数据. 这个事件包含一个Connection_Handles列表, 和相应已完成的HCI Data Packets数量(transmitted, flushed, or looped back to the Host), 基准是相对与上次回给Host的相同事件, 或者是之前连接刚建立, 这个Connection_Handle对应的相同事件还没回应过.

Host chooses the Connection Handles for the following HCI Data Packets based on the information returned in this event, and/or the LE Read Buffer Size commands. Host每发一个HCI data packet, 就会假定CT的对应的空闲buffer (ACL, SCO or eSCO) 就会减少一个.

每个Number Of Completed Packets event 都会提供HCI Data packet已完成的数量(transmitted or flushed), for each Connection_Handle since the previous Number Of Completed Packets event was sent to the Host. 所以, Host可以算出目前实际的buffer usage.

image-20200602184101675

当Controller已完成一个或者更多HCI Data Packets时, 它会发送一个Number Of Completed Packets event给到Host, 直到它报告所有的pending HCI Data Packets都完成了. 这个事件的频率由manufacturer 决定.

Note: The Number Of Completed Packets events will not report on synchronous Connection_Handles if Synchronous Flow Control is disabled. (参考Read Synchronous Flow Control Enable Command, and Write Synchronous Flow Control Enable Command.)

对于每个individual Handle(句柄), 发给CT的HCI data packet的顺序和它在Host创建的顺序是一样的. 对于每个句柄, 发到空间的顺序也是一样的. 在另外一个接收端, 对应每个句柄, 从空中收到的顺序和发给host的顺序是一样的. 这意味着每一个句柄都被单独scheduling. 对于每个独立句柄, 数据的顺序跟它被创建的顺序比起来,不能有变.

HCI ACL Data Packets on an LE-U logical link shall be 27 octets or larger. A Host shall not fragment HCI ACL Data Packets on an LE-U logical link that are 27 octets or less in length.

4.1.2 Data-Block-Based Data Flow Control

这种流控类型暂略过.

4.2 CONTROLLER TO HOST DATA FLOW CONTROL

这个方向的流控略(其实和正向的流控差不多的).

4.3 DISCONNECTION BEHAVIOR

这节主要意思就是 Host 收到a Disconnection Complete, Disconnection Physical Link Complete or Disconnection Logical Link Complete 这些事件后,不要指望CT回应了Host已经发出去的指令, Primary Controller和AMP Controller都是可以不回应的.

反过来, CONTROLLER TO HOST的流控也一样.

4.4 COMMAND FLOW CONTROL

每次Power-on, 并且reset之后, Host会发送一个maximum of one outstanding HCI Command Packet until a Command Complete or Command Status event has been received.

The Command Complete and Command Status events contain a parameter called Num HCI Command Packets, which indicates the number of HCI Command Packets the Host is currently allowed to send to the Controller. The Controller may buffer one or more HCI command packets, but the Controller shall start performing the commands in the order in which they are received. The Controller can start performing a command before it completes previous commands. Therefore, the commands do not always complete in the order they are started(指令完成顺序不一定和指令开始顺序相同,因为上一条指令未完成时,控制器可以开始下一条指令.但指令开始的顺序和接收的顺序是一样的).

image-20200602182303457

To indicate to the Host that the Controller is ready to receive HCI command packets, the Controller may generate a Command Complete event with the Command Opcode 0x0000, and the Num HCI Command Packets event parameter is set to 1 or more. Command Opcode 0x0000 is a NOP (No OPeration), and can be used to change the number of outstanding HCI command packets that the Host can send. The Controller may generate a Command Complete event with the Num HCI Command Packets event parameter set to zero to inform Host it must stop sending commands(如果这个事件的Num HCI Command Packets为0, 表示Host不能再发数据下来了).

For most commands, a Command Complete event shall be sent to the Host when the Controller completes the command. Some commands are executed in the background and do not return a Command Complete event when they have been completed. Instead, the Controller shall send a Command Status event back to the Host when it has begun to execute the command(部分指令是在background执行并且不回Command Complete event,而是在开始执行这条指令时,回Command Status event). When the actions associated with the command have finished, an event that is associated with the command shall be sent by the Controller to the Host(当对应的指令执行完毕时, 一个与指令相对应的事件会发到Host).

image-20200602184812994

If the command does not begin to execute (for example, if there was a parameter error or the command is currently not allowed), the Command Status event shall be returned with the appropriate error code in the Status parameter, and the event associated with the sent command shall not be returned(假设指令不执行, the Command Status event就会回应一个错误, 并且指令对应的事件也不会回应).

4.5 COMMAND ERROR HANDLING

这节看中文注释差不多了.

If an error occurs for a command for which a Command Complete event is returned, the Return Parameters field may not contain all the return parameters specified for the command(不一定全部定义的参数都回). The Status parameter, which explains the error reason and which is the first return parameter, shall always be returned(错误原因一定要回). If there is a Handle parameter or a BD_ADDR parameter right after the Status parameter, this parameter shall also be returned so that the Host can identify to which instance of a command the Command Complete event belongs(假设有句柄参数或者地址参数,那也要回应). In this case, the Handle or BD_ADDR parameter shall have exactly the same value as that in the corresponding command parameter(这种情况, 和下来的command指令的句柄或者地址参数一样). It is implementation specific whether more parameters will be returned in case of an error.

The above also applies to commands that have associated command specific completion events with a status parameter in their completion event, with four exceptions.(上面的内容同样适用与某些指令有对应的特殊completion events并带有一个status响应参数, 但有四个例外:)

The first two exceptions are the Connection Complete and the Synchronous Connection Complete events. On failure, for these two events only, the second parameter, Connection_Handle, is not valid and the third parameter, BD_ADDR, is valid for identification purposes(失败的情况,句柄和地址参数都无效).

The third exception is the LE Connection Complete event. On failure, the Status parameter is valid, all other parameters are not valid.

The fourth exception is the Logical Link completion event. On failure, for this event, the second parameter (Logical_Link_Handle) is not valid but the third parameter (Physical_Link_Handle) is valid for identification purposes. The validity of other parameters is likewise implementation specific for failed commands in this group, but they shall be sent in any case(其他参数始终会发送).

Note: The BD_ADDR return parameter of the command Read BD_ADDR is not used to identify to which instance of the Read BD ADDR command the Command Complete event belongs. It is optional for the Controller to return this parameter in case of an error.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值