USB3.2超高速协议规范
+ -

USB3.2超高速数据扰频

2021-06-06 1118 0

在数据时行发送前,一般先扰频,然后再序序列化数据,最后通过差分发送器将数据从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;
}
HID人机交互QQ群:564808376    UAC音频QQ群:218581009    UVC相机QQ群:331552032    BOT&UASP大容量存储QQ群:258159197    STC-USB单片机QQ群:315457461    USB技术交流QQ群2:580684376    USB技术交流QQ群:952873936   

0 篇笔记 写笔记

USB3.2超高速GEN2数据扰频
USB3.2GEN2的扰频规则和USB3.2GEN1的扰频算法是不一样的。USB3.2GEN2的扰频算法图:USB3.2GEN2的扰频有以下几种模式:扰码器前进并与数据异或。扰码器前进并被绕过(不与数据异或)。扰码器不前进且被绕过(不与数据异或)USB3.2GEN2的扰频规则:块头(Block he......
USB3.2超高速数据扰频
在数据时行发送前,一般先扰频,然后再序序列化数据,最后通过差分发送器将数据从LSB-MSB发送出去。在接收端,同理也需要进行解扰频。在实际的USB物理IP核开发调试中,可以通过禁用扰频来进行调试开发以降低调试的难度。以下子程序用LFSR对“inbyte”中包含的8位值进行编码和解码。这个例子演示了如......
USB3.2超高速GEN1数据扰频
扰码功能是使用一个自由运行的线性反馈移位寄存器(LFSR)实现的。来实现的。LFSR:Linear Feedback Shift Register在发送端,对8b/10b之前的字符进行加扰编码。在接收端,对8b/10b解码后的字符进行解扰。每当发送或接收到COM符号(COM symbol)时,LFS......
关注公众号
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!