蓝牙 BCSP 剖析(一)

一.Introduction 

BCSP( BlueCore Serial Protoco)是CSR的一个协议,不是标准的蓝牙协议,在HCI层之下,通俗点讲:就是HCI又包了一层BCSP协议发给uart,以便做到可靠性传输
如图:
蓝牙 BCSP 剖析(一)_第1张图片

Host是软件协议栈,Host Controller是芯片端

二.Context

蓝牙 BCSP 剖析(一)_第2张图片
An instance of the BCSP stack runs on the Host and the Host Controller

The top of the BCSP stack presents: 
!  One bidirectional reliable datagram service 
!  One bidirectional unreliable datagram service

BCSP运行于三线uart(TX,RX,GND),也可以运行在5线uart(TX,RX,GND,CTS,RTS)

三.Overview

蓝牙 BCSP 剖析(一)_第3张图片
Considering the diagram from the bottom: 
!  The UART Driver Layer initialises and controls the local UART, translating the flows of bytes on the 
physical UART connection to the peer computer into flows of bytes at the base of the SLIP Layer. 
!  The SLIP Layer uses the Serial Link Internet Protocol (SLIP) to transform the flow of bytes into a flow of 
packets. 
!  The Packet Integrity Layer ensures that packets received from the SLIP layer are intact. 
!  The MUX Layer routes received packets either tothe Sequencing Layer or to the Datagram Queue 
Layer. The MUX Layer also keeps a note of the time at which the last packet was last successfully 
received. 
!  The Sequencing Layer uses a windowing mechanism to provide a single reliable flow of packets to and 
from the peer. Code above the Layer can route packets using a Protocol Identifier value, which is carried 
with each packet. 
!  The Datagram Queue Layer provides a single unreliable flow of packets to and from the peer. As with 
the Sequencing Layer, code above this Layer can route packets using a Protocol Identifier value, which 
is carried with each packet. 

每层后续再介绍

四.Packet Structure

1): 

蓝牙 BCSP 剖析(一)_第4张图片

2):Flags field format:


seq:0-2bit,范围是0-7,只对Sequencing Laye层有效,Unreliable Datagram Stream层这个field都设置为0
Ack:3-5bit,范围是0-7,只对Sequencing Laye层有效,Unreliable Datagram Stream层这个field都设置为0
CRC:是否包含CRC校验,0表示不包含,1表示包含,如果包含的话会在payload后面增加两个bytes
Protocol Type:只在MUX曾用到,根据这个上传到上面那一层

3):The Protocol Identifier Field:

BCSP Packets struct 的第2个byte的 0-3bit,用来标示是哪一种上层协议的数据,这个字段通常被称为BCSP channel,
对于可靠和不可靠的两种BCSP封包每个channel具有不同含义,如图:

4):Payload Length Field

BCSP Packets struct 第3个byte + 第2个byte的4-7bit,代表payload的长度,不包含CRC两个byte

5):Checksum Field

BCSP header的校验位,通常为前三个byte的和值取反

6):Payload

需要BCSP运送的数据

7):CRC Field

就是一个校验算法,来保证传输接近于可靠性,只能校验,不能纠错,所以一般出错的处理是:丢弃或者重传,
在BCSP Packets Struct中占2个byte

五.Detail Layer

1):UART Driver Layer

The UART Driver Layer of the stack initialises and controls the local UART. The Layer transfers bytes between 
the local UART and the bottom of the SLIP Layer. 
The local UART connects to the peer computer via a physical link with the following default characteristics: 
!  A three-wire link: data in both directions plus a common ground 
!  No hardware flow control signals 
!  8 data bits, transmitted least significant bit first 
!  Even parity 
!  One stop bit 
!  38.4kbaud 
If a received byte fails its parity test then the byte is silently discarded. 
The baud rate, number of stop bits, parity on/off, parity even/odd and use of hardware flow control may be 
changed by local configuration. 
If the Layer is reset, then it restores the configuration listed above

2):SLIP Layer 

SLIP层主要是把串口驱动层传来的字节流数据轮换成SLIP包的形式传给“包完整层”,SLIP packet是以字节0xc0开始和结束的
所以当上层(包完整层)传送下来的时候,会对每个packet里的每一个字节监测,如果这个字节是0xc0,就把它装换成两个字节
(0xdb,0xdc),如果这个字节是0xdb,则转化成(0xdb,0xdd),然后再把这个包送到uart driver layer,同样对于uart Driver传来
的数据进行相反的转换再传到上层

3):Packet Integrity Layer

针对包进行完整性检测,去掉不完整的或者有错误的包

4):MUX Layer 

BCSP的路由层,负责把包完整性层传过来的包送到更上层的可靠性或者不可靠性层

你可能感兴趣的:(蓝牙,UART,bcsp)