OpenCores
URL https://opencores.org/ocsvn/openhmc/openhmc/trunk

Subversion Repositories openhmc

[/] [openhmc/] [trunk/] [openHMC/] [rtl/] [hmc_controller/] [rx/] [rx_descrambler.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 juko
/*
2
 *                              .--------------. .----------------. .------------.
3
 *                             | .------------. | .--------------. | .----------. |
4
 *                             | | ____  ____ | | | ____    ____ | | |   ______ | |
5
 *                             | ||_   ||   _|| | ||_   \  /   _|| | | .' ___  || |
6
 *       ___  _ __   ___ _ __  | |  | |__| |  | | |  |   \/   |  | | |/ .'   \_|| |
7
 *      / _ \| '_ \ / _ \ '_ \ | |  |  __  |  | | |  | |\  /| |  | | || |       | |
8
 *       (_) | |_) |  __/ | | || | _| |  | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
9
 *      \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
10
 *           | |               | |            | | |              | | |          | |
11
 *           |_|               | '------------' | '--------------' | '----------' |
12
 *                              '--------------' '----------------' '------------'
13
 *
14
 *  openHMC - An Open Source Hybrid Memory Cube Controller
15
 *  (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
16
 *  www.ziti.uni-heidelberg.de
17
 *  B6, 26
18
 *  68159 Mannheim
19
 *  Germany
20
 *
21
 *  Contact: openhmc@ziti.uni-heidelberg.de
22
 *  http://ra.ziti.uni-heidelberg.de/openhmc
23
 *
24
 *   This source file is free software: you can redistribute it and/or modify
25
 *   it under the terms of the GNU Lesser General Public License as published by
26
 *   the Free Software Foundation, either version 3 of the License, or
27
 *   (at your option) any later version.
28
 *
29
 *   This source file is distributed in the hope that it will be useful,
30
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 *   GNU Lesser General Public License for more details.
33
 *
34
 *   You should have received a copy of the GNU Lesser General Public License
35
 *   along with this source file.  If not, see <http://www.gnu.org/licenses/>.
36
 *
37
 *
38
 *  Module name: rx_descrambler
39
 *
40
 * Scrambler Logic (HMC Spec version 1.0)
41
 * This module implements a parallel scrambler based on the
42
 * polynomial 1+ x^(-14) + x^(-15).
43
 *
44
 * Such Scrambler is typically shown as a 15 bit Linear Feedback Shift Register
45
 * (LFSR) with bits shifting from register 1 on the left to register 15 on the
46
 * right, with register 14 and 15 combining to shift into register 1.
47
 * The HMC Serializer outputs data[0] first from parallel tx data[n:0],
48
 * so if data[n:0] is to be bitwise scrambled with LFSR[n:0], we need the LFSR
49
 * to shift from n -> 0, the opposite direction from the typical illustration.
50
 * This implementation shifts data from LFSR[14] on the left to LFSR[0] on the
51
 * right, with LFSR[1] and [0] combining to shift into LFSR[14]. This way
52
 * LFSR[14:0] can bitwise scramble data[14:0] and be compatible with serializ-
53
 * ation that shifts out on the data[0] side.
54
 * Put otherwise: Polynomial 1+ x^(-14) + x^(-15) is equiv to
55
 * x^15 + x^1 + x^0
56
 *
57
 * This parallelized version calculates the next DWIDTH steps of values for
58
 * the LFSR.  These bits are used to scramble the parallel input, and to
59
 * choose the next value of lfsr (lfsr_steps[DWIDTH-1]).
60
 *
61
 * This is the descrambler.  It is self-seeding.  When lock is asserted it has
62
 * successfully found the correct value for the LFSR.  It is only implemented
63
 * for DWIDTH > 14.
64
 *
65
 * Since we know that scrambled zeros are being translated, we can calculate
66
 * what the seed will be in the next timestep.  In order to simplify the
67
 * calculation, we assume that the top bit is a one.  That has the happy side-
68
 * effect of letting us know that the seed didn't get stuck at all zeros.
69
 *
70
 * After the scrambler is locked, the input word may need to be aligned.  The
71
 * bit_slip input allows the scrambler to shift one bit with the serializer
72
 * to keep the scrambler in sync.
73
 */
74
 
75
`default_nettype none
76
 
77
module rx_descrambler #(
78
    parameter DWIDTH=16,
79
    parameter BITSLIP_SHIFT_RIGHT=1
80
)
81
(
82
    input wire              clk,
83
    input wire              res_n,
84
    input wire              bit_slip,
85 15 juko
    input wire              can_lock,
86 11 juko
    output reg              locked,
87
    input wire [DWIDTH-1:0] data_in,
88
    output reg [DWIDTH-1:0] data_out
89
 
90
);
91
 
92
reg  [14:0]       lfsr;                    // LINEAR FEEDBACK SHIFT REGISTER
93
wire [14:0]       lfsr_slipped;            // Temporary lfsr for bitslip
94
wire [14:0]       lfsr_steps [DWIDTH-1:0]; // LFSR values for serial time steps
95
wire [14:0]       calculated_seed;
96
wire [DWIDTH-1:0] data_out_tmp;
97
 
98
generate
99
    if(BITSLIP_SHIFT_RIGHT==1) begin
100
        assign lfsr_slipped = { (lfsr_steps[DWIDTH-1][1] ^ lfsr_steps[DWIDTH-1][0]) , lfsr_steps[DWIDTH-1][14:1] };
101
    end else begin
102
        assign lfsr_slipped = { lfsr_steps[DWIDTH-1][13:0], (lfsr_steps[DWIDTH-1][14] ^ lfsr_steps[DWIDTH-1][0])};
103
    end
104
endgenerate
105
 
106 15 juko
`ifdef SIMULATION
107
    initial begin
108
       lfsr     <= 15'h0;
109
    end
110
`endif
111
 
112 11 juko
// SEQUENTIAL PROCESS
113
`ifdef ASYNC_RES
114
always @(posedge clk or negedge res_n)  begin `else
115
always @(posedge clk)  begin `endif
116 15 juko
    `ifdef RESET_ALL
117
        if(!res_n) begin
118
            data_out <= {DWIDTH {1'b0}};
119
            lfsr     <= 15'h0;
120
        end else
121
    `endif
122
    begin
123 11 juko
        data_out <= data_out_tmp;
124 15 juko
        if (!locked) begin
125 11 juko
            lfsr <= calculated_seed;
126
        end else begin
127
            if (bit_slip) begin
128
                lfsr <= lfsr_slipped;
129
            end else begin
130
                lfsr <= lfsr_steps[DWIDTH-1];
131
            end
132 15 juko
        end
133
    end
134
 
135
    if(!res_n) begin
136
        locked   <= 1'b0;
137
    end else begin
138
        if (!locked) begin
139
            if (calculated_seed == lfsr_steps[DWIDTH-1]) begin
140
                locked <= 1'b1;
141
            end
142 11 juko
        end
143 15 juko
        if(!can_lock) begin
144
            locked <= 1'b0;
145
        end
146 11 juko
    end
147
end                 // serial shift right with left input
148
 
149
// SCRAMBLE
150
 
151
genvar j;
152
generate
153
    localparam OFFSET = DWIDTH-15; // It breaks here if DWIDTH < 15
154
    assign calculated_seed[14] = 1'b1; // Guess the top bit is 1
155
 
156
    // data_in is the past state of the LFSR, so we can figure out
157
    // the current value using a loop.
158
 
159
    for(j = 0; j < 14; j = j + 1) begin : seed_calc
160
        assign calculated_seed[j] = data_in[j+OFFSET] ^ data_in[j+OFFSET+1];
161
    end
162
 
163
    assign data_out_tmp [0] = data_in[0] ^ lfsr[0]; // single bit scrambled
164
    assign lfsr_steps[0]    = { (lfsr[1] ^ lfsr[0]) , lfsr[14:1] }; // lfsr at next bit clock
165
    for(j = 1; j < DWIDTH; j = j + 1) begin : scrambler_gen
166
        assign data_out_tmp[j] = data_in[j] ^ lfsr_steps[j-1][0];
167
        assign lfsr_steps[j]   = { (lfsr_steps[j-1][1] ^ lfsr_steps[j-1][0]) , lfsr_steps[j-1][14:1] };
168
    end
169
endgenerate
170
 
171
endmodule
172
 
173
`default_nettype wire
174
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.