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 11

Go to most recent revision | 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
    output reg              locked,
86
    input wire [DWIDTH-1:0] data_in,
87
    output reg [DWIDTH-1:0] data_out
88
 
89
);
90
 
91
reg  [14:0]       lfsr;                    // LINEAR FEEDBACK SHIFT REGISTER
92
wire [14:0]       lfsr_slipped;            // Temporary lfsr for bitslip
93
wire [14:0]       lfsr_steps [DWIDTH-1:0]; // LFSR values for serial time steps
94
wire [14:0]       calculated_seed;
95
wire [DWIDTH-1:0] data_out_tmp;
96
 
97
generate
98
    if(BITSLIP_SHIFT_RIGHT==1) begin
99
        assign lfsr_slipped = { (lfsr_steps[DWIDTH-1][1] ^ lfsr_steps[DWIDTH-1][0]) , lfsr_steps[DWIDTH-1][14:1] };
100
    end else begin
101
        assign lfsr_slipped = { lfsr_steps[DWIDTH-1][13:0], (lfsr_steps[DWIDTH-1][14] ^ lfsr_steps[DWIDTH-1][0])};
102
    end
103
endgenerate
104
 
105
// SEQUENTIAL PROCESS
106
`ifdef ASYNC_RES
107
always @(posedge clk or negedge res_n)  begin `else
108
always @(posedge clk)  begin `endif
109
    if (!res_n) begin
110
        locked   <= 1'b0;
111
        lfsr     <= 15'h0;
112
        data_out <= {DWIDTH {1'b0}};
113
    end else begin
114
 
115
        data_out <= data_out_tmp;
116
 
117
        if (!locked && |data_in) begin
118
            lfsr <= calculated_seed;
119
            // Locked when the calculated seeds match
120
            if (calculated_seed == lfsr_steps[DWIDTH-1]) begin
121
                locked <= 1'b1;
122
            end
123
        end else begin
124
            if (bit_slip) begin
125
                lfsr <= lfsr_slipped;
126
            end else begin
127
                lfsr <= lfsr_steps[DWIDTH-1];
128
            end
129
        end
130
    end
131
end                 // serial shift right with left input
132
 
133
// SCRAMBLE
134
 
135
genvar j;
136
generate
137
    localparam OFFSET = DWIDTH-15; // It breaks here if DWIDTH < 15
138
    assign calculated_seed[14] = 1'b1; // Guess the top bit is 1
139
 
140
    // data_in is the past state of the LFSR, so we can figure out
141
    // the current value using a loop.
142
 
143
    for(j = 0; j < 14; j = j + 1) begin : seed_calc
144
        assign calculated_seed[j] = data_in[j+OFFSET] ^ data_in[j+OFFSET+1];
145
    end
146
 
147
    assign data_out_tmp [0] = data_in[0] ^ lfsr[0]; // single bit scrambled
148
    assign lfsr_steps[0]    = { (lfsr[1] ^ lfsr[0]) , lfsr[14:1] }; // lfsr at next bit clock
149
    for(j = 1; j < DWIDTH; j = j + 1) begin : scrambler_gen
150
        assign data_out_tmp[j] = data_in[j] ^ lfsr_steps[j-1][0];
151
        assign lfsr_steps[j]   = { (lfsr_steps[j-1][1] ^ lfsr_steps[j-1][0]) , lfsr_steps[j-1][14:1] };
152
    end
153
endgenerate
154
 
155
endmodule
156
 
157
`default_nettype wire
158
 

powered by: WebSVN 2.1.0

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