FGX的个人空间 https://blog.eetop.cn/1641659 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

scramble for PCIe(Gen1/Gen2)

已有 9 次阅读| 2023-7-12 16:53 |个人分类:数据处理|系统分类:芯片设计| scramble, PCIe, simple

/*
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
*/

`timescale 1ns/1ps
module scramble(
                      clk,
                      rst_b,
                      datain,
                      COMMA,
                      SKIP,
                      K,        //K symbol
                      scramble_enable,
                      valid_en,
                      dataout
               );
input    clk;
input    rst_b;
input    COMMA;
input    SKIP;
input    K;
input    scramble_enable;
input[7:0]  datain;
output[7:0]  dataout;
output      valid_en;
reg [7:0]    dataout;
reg          valid_en;
wire[7:0]    scramble_bit;//scramble data
reg [15:0]   LFSR;
wire[15:0]   LFSR_N;
parameter    DLY = 1;

always @(posedge clk or negedge rst_b)
  begin
    if(!rst_b)
     valid_en <= #1 1'b0;
    else if(scramble_enable)
     valid_en <= #1 1'b1;
    else
     valid_en <= #1 1'b0;
  end
always @(posedge clk or negedge rst_b)
  begin
    if(!rst_b)
      dataout <= #1 8'h0;
    else if ( COMMA | SKIP | K)
     dataout <= #1 datain;//COMMA SKIP and K are not scramble
    else if(scramble_enable)
     dataout <= #1 scramble_bit ;
    else 
     dataout <= #1 datain;//disable scramble
  end

//parallel data  
assign   scramble_bit[0]  = datain[0] ^ LFSR[15] ;
assign   scramble_bit[1]  = datain[1] ^ LFSR[14] ;
assign   scramble_bit[2]  = datain[2] ^ LFSR[13] ;
assign   scramble_bit[3]  = datain[3] ^ LFSR[12] ;
assign   scramble_bit[4]  = datain[4] ^ LFSR[11] ;
assign  scramble_bit[5]  = datain[5] ^ LFSR[10];
assign  scramble_bit[6]  = datain[6] ^ LFSR[9];
assign  scramble_bit[7]  = datain[7] ^ LFSR[8];

always @(posedge clk or negedge rst_b)
  begin
   if(!rst_b)
     LFSR <= #1 16'hffff;
   else if(COMMA)
     LFSR <= #1 16'hffff;
   else if( K | SKIP)
     LFSR <= #1 LFSR;
   else if(scramble_enable)
     LFSR <= #1 LFSR_N;
  end
  
assign LFSR_N[0]  = LFSR[8];
assign LFSR_N[1]  = LFSR[9];
assign LFSR_N[2]  = LFSR[10];
assign LFSR_N[3]  = LFSR[11] ^ LFSR[8];
assign LFSR_N[4]  = LFSR[12] ^ LFSR[9]  ^  LFSR[8];
assign LFSR_N[5]  = LFSR[13] ^ LFSR[10] ^ LFSR[9]  ^ LFSR[8];
assign LFSR_N[6]  = LFSR[14] ^ LFSR[11] ^ LFSR[10] ^ LFSR[9];
assign LFSR_N[7]  = LFSR[15] ^ LFSR[12] ^ LFSR[11] ^ LFSR[10];
assign LFSR_N[8]  = LFSR[0]  ^ LFSR[13] ^ LFSR[12] ^ LFSR[11];
assign LFSR_N[9]  = LFSR[1]  ^ LFSR[14] ^ LFSR[13] ^ LFSR[12];
assign LFSR_N[10]  = LFSR[2]  ^ LFSR[15] ^ LFSR[14] ^ LFSR[13];
assign LFSR_N[11]  = LFSR[3]         ^ LFSR[15] ^ LFSR[14];
assign LFSR_N[12]  = LFSR[4]               ^ LFSR[15];
assign LFSR_N[13]  = LFSR[5];
assign LFSR_N[14]  = LFSR[6];
assign LFSR_N[15]  = LFSR[7];


//serial data
wire [15:0] LFSR_T_tmp_0 ;
wire [15:0] LFSR_T_tmp_1 ;
wire [15:0] LFSR_T_tmp_2 ;
wire [15:0] LFSR_T_tmp_3 ;
wire [15:0] LFSR_T_tmp_4 ;
wire [15:0] LFSR_T_tmp_5 ;
wire [15:0] LFSR_T_tmp_6 ;
wire [15:0] LFSR_T_tmp_7 ;
wire [15:0] LFSR_T_tmp_8 ;
wire [15:0] LFSR_T_tmp_9 ;
wire [15:0] LFSR_T_tmp_10 ;
wire [15:0] LFSR_T_tmp_11 ;
wire [15:0] LFSR_T_tmp_12 ;
wire [15:0] LFSR_T_tmp_13 ;
wire [15:0] LFSR_T_tmp_14 ;
wire [15:0] LFSR_T_tmp_15 ;
reg [7:0]  dat_out;
wire [7:0]  dat_out_t;

LFSR_SHIFT I_LFSR_SHIFT_0 (.LFSR_cur(LFSR_T),    .ser_dat(datain[0]), .LFSR_next(LFSR_T_tmp_0), .scr_dat(dat_out_t[0]) );
LFSR_SHIFT I_LFSR_SHIFT_1 (.LFSR_cur(LFSR_T_tmp_0), .ser_dat(datain[1]), .LFSR_next(LFSR_T_tmp_1), .scr_dat(dat_out_t[1]) );
LFSR_SHIFT I_LFSR_SHIFT_2 (.LFSR_cur(LFSR_T_tmp_1), .ser_dat(datain[2]), .LFSR_next(LFSR_T_tmp_2), .scr_dat(dat_out_t[2]) );
LFSR_SHIFT I_LFSR_SHIFT_3 (.LFSR_cur(LFSR_T_tmp_2), .ser_dat(datain[3]), .LFSR_next(LFSR_T_tmp_3), .scr_dat(dat_out_t[3]) );
LFSR_SHIFT I_LFSR_SHIFT_4 (.LFSR_cur(LFSR_T_tmp_3), .ser_dat(datain[4]), .LFSR_next(LFSR_T_tmp_4), .scr_dat(dat_out_t[4]) );
LFSR_SHIFT I_LFSR_SHIFT_5 (.LFSR_cur(LFSR_T_tmp_4), .ser_dat(datain[5]), .LFSR_next(LFSR_T_tmp_5), .scr_dat(dat_out_t[5]) );
LFSR_SHIFT I_LFSR_SHIFT_6 (.LFSR_cur(LFSR_T_tmp_5), .ser_dat(datain[6]), .LFSR_next(LFSR_T_tmp_6), .scr_dat(dat_out_t[6]) );
LFSR_SHIFT I_LFSR_SHIFT_7 (.LFSR_cur(LFSR_T_tmp_6), .ser_dat(datain[7]), .LFSR_next(LFSR_T_tmp_7), .scr_dat(dat_out_t[7]) );

always @(posedge clk or negedge rst_b)
  begin
    if(!rst_b)
      LFSR_T <= #1 16'hffff;
    else if(scramble_enable)
      LFSR_T <= #1 LFSR_T_tmp_7;
   end
always @(posedge clk or negedge rst_b)
  begin
    if(!rst_b)
     dat_out <= #1 8'h0;
    else if(scramble_enable)
     dat_out <= #1 dat_out_t;
  end
endmodule


module LFSR_SHIFT(
                 //input
                 LFSR_cur,
                 ser_dat,
                 //output
                 LFSR_next,
                 scr_dat
                 );
input [15:0]     LFSR_cur ;
input        ser_dat;
output[15:0]     LFSR_next;
output        scr_dat;

wire[15:0]     LFSR_next;

assign  LFSR_next[0] = LFSR_cur[15];
assign  LFSR_next[1] = LFSR_cur[0];
assign  LFSR_next[2] = LFSR_cur[1];
assign  LFSR_next[3] = LFSR_cur[2] ^ LFSR_cur[15];
assign  LFSR_next[4] = LFSR_cur[3] ^ LFSR_cur[15];
assign  LFSR_next[5] = LFSR_cur[4] ^ LFSR_cur[15];
assign  LFSR_next[6] = LFSR_cur[5] ;
assign  LFSR_next[7] = LFSR_cur[6] ;
assign  LFSR_next[8] = LFSR_cur[7] ;
assign  LFSR_next[9] = LFSR_cur[8] ;
assign  LFSR_next[10] = LFSR_cur[9] ;
assign  LFSR_next[11] = LFSR_cur[10] ;
assign  LFSR_next[12] = LFSR_cur[11] ;
assign  LFSR_next[13] = LFSR_cur[12] ;
assign  LFSR_next[14] = LFSR_cur[13] ;
assign  LFSR_next[15] = LFSR_cur[14] ;

assign  scr_dat = LFSR_cur[15] ^ ser_dat;

endmodule




点赞

全部作者的其他最新日志

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

FGX

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 3

    粉丝
  • 0

    好友
  • 0

    获赞
  • 1

    评论
  • 116

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-28 03:27 , Processed in 0.014776 second(s), 9 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部