您现在的位置是:主页 > USB3.2超高速协议规范 >
USB3.2超高速数据扰频
发布时间:2022-12-27 08:14:11所属栏目:USB3.2超高速协议规范 已帮助人编辑作者:【USB接口百科】
在数据时行发送前,一般先扰频,然后再序序列化数据,最后通过差分发送器将数据从LSB-MSB发送出去。在接收端,同理也需要进行解扰频。
在实际的USB物理IP核开发调试中,可以通过禁用扰频来进行调试开发以降低调试的难度。
以下子程序用LFSR对“inbyte”中包含的8位值进行编码和解码。
这个例子演示了如何在一个操作中将LFSR进行八次,以及如何在一个操作中将数据异或。当然也可以用其它方法实现,但它们都必须产生与这里所示相同的输出。
/*
this routine implements the serial descrambling algorithm in parallel
form
for the LSFR polynomial: x^16+x^5+x^4+x^3+1
this advances the LSFR 8 bits every time it is called
this requires fewer than 25 xor gates to implement (with a static
register)
The XOR required to advance 8 bits/clock is:
bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7
8 9 10 11 12 13 14 15
8 9 10 11 12 13 14 15
8 9 10 11 12 13 14 15
The serial data is just the reverse of the upper byte:
bit 0 1 2 3 4 5 6 7
15 14 13 12 11 10 9 8
*/
int scramble_byte(int inbyte)
{
static int scrambit[16];
static int bit[16];
static int bit_out[16];
static unsigned short lfsr = 0xffff; // 16 bit short for polynomial
int i, outbyte;
if (inbyte == COMMA) // if this is a comma
{
lfsr = 0xffff; // reset the LFSR
return (COMMA); // and return the same data
}
if (inbyte == SKIP) // don't advance or encode on skip
return (SKIP);
for (i = 0; i<16; i++) // convert LFSR to bit array for legibility
bit[i] = (lfsr >> i) & 1;
for (i = 0; i<8; i++) // convert byte to be scrambled for legibility
scrambit[i] = (inbyte >> i) & 1;
// apply the xor to the data
if (!(inbyte & 0x100) && // if not a KCODE, scramble the data
!(TrainingSequence == TRUE)) // and if not in the middle of
{ // a training sequence
scrambit[0] ^= bit[15];
scrambit[1] ^= bit[14];
scrambit[2] ^= bit[13];
scrambit[3] ^= bit[12];
scrambit[4] ^= bit[11];
scrambit[5] ^= bit[10];
scrambit[6] ^= bit[9];
scrambit[7] ^= bit[8];
}
// Now advance the LFSR 8 serial clocks
bit_out[0] = bit[8];
bit_out[1] = bit[9];
bit_out[2] = bit[10];
bit_out[3] = bit[11] ^ bit[8];
bit_out[4] = bit[12] ^ bit[9] ^ bit[8];
bit_out[5] = bit[13] ^ bit[10] ^ bit[9] ^ bit[8];
bit_out[6] = bit[14] ^ bit[11] ^ bit[10] ^ bit[9];
bit_out[7] = bit[15] ^ bit[12] ^ bit[11] ^ bit[10];
bit_out[8] = bit[0] ^ bit[13] ^ bit[12] ^ bit[11];
bit_out[9] = bit[1] ^ bit[14] ^ bit[13] ^ bit[12];
bit_out[10] = bit[2] ^ bit[15] ^ bit[14] ^ bit[13];
bit_out[11] = bit[3] ^ bit[15] ^ bit[14];
bit_out[12] = bit[4] ^ bit[15];
bit_out[13] = bit[5];
bit_out[14] = bit[6];
bit_out[15] = bit[7];
lfsr = 0;
for (i = 0; i <16; i++) // convert the LFSR back to an integer
lfsr += (bit_out[i] << i);
outbyte = 0;
for (i = 0; i<8; i++) // convert data back to an integer
outbyte += (scrambit[i] << i);
return outbyte;
}
解扰频/* NOTE THAT THE DESCRAMBLE ROUTINE IS IDENTICAL TO THE SCRAMBLE ROUTINE
this routine implements the serial descrambling algorithm in parallel
form
this advances the lfsr 8 bits every time it is called
this uses fewer than 25 xor gates to implement (with a static
register)
The XOR tree is the same as the scrambling routine
*/
int unscramble_byte(int inbyte)
{
static int descrambit[8];
static int bit[16];
static int bit_out[16];
static unsigned short lfsr = 0xffff; // 16 bit short for polynomial
int outbyte, i;
if (inbyte == COMMA) // if this is a comma
{
lfsr = 0xffff; // reset the LFSR
return (COMMA); // and return the same data
}
if (inbyte == SKIP) // don't advance or encode on skip
return (SKIP);
for (i = 0; i<16; i++) // convert the LFSR to bit array for legibility
bit[i] = (lfsr >> i) & 1;
for (i = 0; i<8; i++) // convert byte to be de-scrambled for
legibility
descrambit[i] = (inbyte >> i) & 1;
// apply the xor to the data
if (!(inbyte & 0x100) && // if not a KCODE, scramble the data
!(TrainingSequence == TRUE)) // and if not in the middle of
{ // a training sequence
descrambit[0] ^= bit[15];
descrambit[1] ^= bit[14];
descrambit[2] ^= bit[13];
descrambit[3] ^= bit[12];
descrambit[4] ^= bit[11];
descrambit[5] ^= bit[10];
descrambit[6] ^= bit[9];
descrambit[7] ^= bit[8];
}
// Now advance the LFSR 8 serial clocks
bit_out[0] = bit[8];
bit_out[1] = bit[9];
bit_out[2] = bit[10];
bit_out[3] = bit[11] ^ bit[8];
bit_out[4] = bit[12] ^ bit[9] ^ bit[8];
bit_out[5] = bit[13] ^ bit[10] ^ bit[9] ^ bit[8];
bit_out[6] = bit[14] ^ bit[11] ^ bit[10] ^ bit[9];
bit_out[7] = bit[15] ^ bit[12] ^ bit[11] ^ bit[10];
bit_out[8] = bit[0] ^ bit[13] ^ bit[12] ^ bit[11];
bit_out[9] = bit[1] ^ bit[14] ^ bit[13] ^ bit[12];
bit_out[10] = bit[2] ^ bit[15] ^ bit[14] ^ bit[13];
bit_out[11] = bit[3] ^ bit[15] ^ bit[14];
bit_out[12] = bit[4] ^ bit[15];
bit_out[13] = bit[5];
bit_out[14] = bit[6];
bit_out[15] = bit[7];
lfsr = 0;
for (i = 0; i <16; i++) // convert the LFSR back to an integer
lfsr += (bit_out[i] << i);
outbyte = 0;
for (i = 0; i<8; i++) // convert data back to an integer
outbyte += (descrambit[i] << i);
return outbyte;
}
以上就是USB接口百科为您提供USB3.2超高速数据扰频的解读,本文章链接: http://www.usb-hub.cn/usb32gf/42235.html 欢迎分享转载,更多婚礼相关资讯请前往USB3.2超高速协议规范
相关文章
猜你喜欢
USB超高速3.0/3.2在电磁、引脚定义及物理接口TYPE-C上的变化
USB 3.0,其USB速率模式称为“Super Speed”,是通用序列总线(Universal Serial Bus,...
USB超高速3.0协议与USB2.0协议的差异
超高速在框架层级是向后兼容 USB 2.0 的。然而, USB 2.0 和超高速协议还是有一...
USB超高速(SuperSpeed)体系结构
USB超高速(SuperSpeed)体系结构在协议层分为物理层,数据链路层,协议层。...
USB3.2超高速兼容USB2.0数据收发的双总线架构
超高速USB体系和以前的USB版本的功能一致,都是通过USB线缆将USB主机USB外设相...
USB接口百科推荐
USB3.2超高速的设备总线枚举
USB超高速规范物理层概述
USB3.2超高速 BOS描述符
USB3.2超高速链路通道极性反转
USB超高速 GEN1设备状态
USB3.2超高速兼容USB2.0数据收发的双总线架构
USB超高速设备描述符的bMaxPacketSize0为0x09
USB超高速 增强型超高速USB设备特性描述符
USB3.2时钟补偿-弹性缓冲器和SKP有序集
USB3.2超高速描述符分类
USB3.2中数据通路lan的概念
USB超高速 配置概要描述符
USB超高速(SuperSpeed)体系结构
USB3.2超高速GEN2数据扰频
USB3.2超高速 USB2.0扩展特性描述符
