1 |
2 |
ZTEX |
//*****************************************************************************
|
2 |
|
|
// (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved.
|
3 |
|
|
//
|
4 |
|
|
// This file contains confidential and proprietary information
|
5 |
|
|
// of Xilinx, Inc. and is protected under U.S. and
|
6 |
|
|
// international copyright and other intellectual property
|
7 |
|
|
// laws.
|
8 |
|
|
//
|
9 |
|
|
// DISCLAIMER
|
10 |
|
|
// This disclaimer is not a license and does not grant any
|
11 |
|
|
// rights to the materials distributed herewith. Except as
|
12 |
|
|
// otherwise provided in a valid license issued to you by
|
13 |
|
|
// Xilinx, and to the maximum extent permitted by applicable
|
14 |
|
|
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
|
15 |
|
|
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
|
16 |
|
|
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
|
17 |
|
|
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
|
18 |
|
|
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
|
19 |
|
|
// (2) Xilinx shall not be liable (whether in contract or tort,
|
20 |
|
|
// including negligence, or under any other theory of
|
21 |
|
|
// liability) for any loss or damage of any kind or nature
|
22 |
|
|
// related to, arising under or in connection with these
|
23 |
|
|
// materials, including for any direct, or any indirect,
|
24 |
|
|
// special, incidental, or consequential loss or damage
|
25 |
|
|
// (including loss of data, profits, goodwill, or any type of
|
26 |
|
|
// loss or damage suffered as a result of any action brought
|
27 |
|
|
// by a third party) even if such damage or loss was
|
28 |
|
|
// reasonably foreseeable or Xilinx had been advised of the
|
29 |
|
|
// possibility of the same.
|
30 |
|
|
//
|
31 |
|
|
// CRITICAL APPLICATIONS
|
32 |
|
|
// Xilinx products are not designed or intended to be fail-
|
33 |
|
|
// safe, or for use in any application requiring fail-safe
|
34 |
|
|
// performance, such as life-support or safety devices or
|
35 |
|
|
// systems, Class III medical devices, nuclear facilities,
|
36 |
|
|
// applications related to the deployment of airbags, or any
|
37 |
|
|
// other applications that could lead to death, personal
|
38 |
|
|
// injury, or severe property or environmental damage
|
39 |
|
|
// (individually and collectively, "Critical
|
40 |
|
|
// Applications"). Customer assumes the sole risk and
|
41 |
|
|
// liability of any use of Xilinx products in Critical
|
42 |
|
|
// Applications, subject only to applicable laws and
|
43 |
|
|
// regulations governing limitations on product liability.
|
44 |
|
|
//
|
45 |
|
|
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
|
46 |
|
|
// PART OF THIS FILE AT ALL TIMES.
|
47 |
|
|
//
|
48 |
|
|
//*****************************************************************************
|
49 |
|
|
// ____ ____
|
50 |
|
|
// / /\/ /
|
51 |
|
|
// /___/ \ / Vendor : Xilinx
|
52 |
|
|
// \ \ \/ Version : %version
|
53 |
|
|
// \ \ Application : MIG
|
54 |
|
|
// / / Filename : ecc_gen.v
|
55 |
|
|
// /___/ /\ Date Last Modified : $date$
|
56 |
|
|
// \ \ / \ Date Created : Tue Jun 30 2009
|
57 |
|
|
// \___\/\___\
|
58 |
|
|
//
|
59 |
|
|
//Device : 7-Series
|
60 |
|
|
//Design Name : DDR3 SDRAM
|
61 |
|
|
//Purpose :
|
62 |
|
|
//Reference :
|
63 |
|
|
//Revision History :
|
64 |
|
|
//*****************************************************************************
|
65 |
|
|
|
66 |
|
|
`timescale 1ps/1ps
|
67 |
|
|
|
68 |
|
|
// Generate the ecc code. Note that the synthesizer should
|
69 |
|
|
// generate this as a static logic. Code in this block should
|
70 |
|
|
// never run during simulation phase, or directly impact timing.
|
71 |
|
|
//
|
72 |
|
|
// The code generated is a single correct, double detect code.
|
73 |
|
|
// It is the classic Hamming code. Instead, the code is
|
74 |
|
|
// optimized for minimal/balanced tree depth and size. See
|
75 |
|
|
// Hsiao IBM Technial Journal 1970.
|
76 |
|
|
//
|
77 |
|
|
// The code is returned as a single bit vector, h_rows. This was
|
78 |
|
|
// the only way to "subroutinize" this with the restrictions of
|
79 |
|
|
// disallowed include files and that matrices cannot be passed
|
80 |
|
|
// in ports.
|
81 |
|
|
//
|
82 |
|
|
// Factorial and the combos functions are defined. Combos
|
83 |
|
|
// simply computes the number of combinations from the set
|
84 |
|
|
// size and elements at a time.
|
85 |
|
|
//
|
86 |
|
|
// The function next_combo computes the next combination in
|
87 |
|
|
// lexicographical order given the "current" combination. Its
|
88 |
|
|
// output is undefined if given the last combination in the
|
89 |
|
|
// lexicographical order.
|
90 |
|
|
//
|
91 |
|
|
// next_combo is insensitive to the number of elements in the
|
92 |
|
|
// combinations.
|
93 |
|
|
//
|
94 |
|
|
// An H transpose matrix is generated because that's the easiest
|
95 |
|
|
// way to do it. The H transpose matrix is generated by taking
|
96 |
|
|
// the one at a time combinations, then the 3 at a time, then
|
97 |
|
|
// the 5 at a time. The number combinations used is equal to
|
98 |
|
|
// the width of the code (CODE_WIDTH). The boundaries between
|
99 |
|
|
// the 1, 3 and 5 groups are hardcoded in the for loop.
|
100 |
|
|
//
|
101 |
|
|
// At the same time the h_rows vector is generated from the
|
102 |
|
|
// H transpose matrix.
|
103 |
|
|
|
104 |
|
|
module mig_7series_v2_3_ecc_gen
|
105 |
|
|
#(
|
106 |
|
|
parameter CODE_WIDTH = 72,
|
107 |
|
|
parameter ECC_WIDTH = 8,
|
108 |
|
|
parameter DATA_WIDTH = 64
|
109 |
|
|
)
|
110 |
|
|
(
|
111 |
|
|
/*AUTOARG*/
|
112 |
|
|
// Outputs
|
113 |
|
|
h_rows
|
114 |
|
|
);
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
function integer factorial (input integer i);
|
118 |
|
|
integer index;
|
119 |
|
|
if (i == 1) factorial = 1;
|
120 |
|
|
else begin
|
121 |
|
|
factorial = 1;
|
122 |
|
|
for (index=2; index<=i; index=index+1)
|
123 |
|
|
factorial = factorial * index;
|
124 |
|
|
end
|
125 |
|
|
endfunction // factorial
|
126 |
|
|
|
127 |
|
|
function integer combos (input integer n, k);
|
128 |
|
|
combos = factorial(n)/(factorial(k)*factorial(n-k));
|
129 |
|
|
endfunction // combinations
|
130 |
|
|
|
131 |
|
|
// function next_combo
|
132 |
|
|
// Given a combination, return the next combo in lexicographical
|
133 |
|
|
// order. Scans from right to left. Assumes the first combination
|
134 |
|
|
// is k ones all of the way to the left.
|
135 |
|
|
//
|
136 |
|
|
// Upon entry, initialize seen0, trig1, and ones. "seen0" means
|
137 |
|
|
// that a zero has been observed while scanning from right to left.
|
138 |
|
|
// "trig1" means that a one have been observed _after_ seen0 is set.
|
139 |
|
|
// "ones" counts the number of ones observed while scanning the input.
|
140 |
|
|
//
|
141 |
|
|
// If trig1 is one, just copy the input bit to the output and increment
|
142 |
|
|
// to the next bit. Otherwise set the the output bit to zero, if the
|
143 |
|
|
// input is a one, increment ones. If the input bit is a one and seen0
|
144 |
|
|
// is true, dump out the accumulated ones. Set seen0 to the complement
|
145 |
|
|
// of the input bit. Note that seen0 is not used subsequent to trig1
|
146 |
|
|
// getting set.
|
147 |
|
|
function [ECC_WIDTH-1:0] next_combo (input [ECC_WIDTH-1:0] i);
|
148 |
|
|
integer index;
|
149 |
|
|
integer dump_index;
|
150 |
|
|
reg seen0;
|
151 |
|
|
reg trig1;
|
152 |
|
|
// integer ones;
|
153 |
|
|
reg [ECC_WIDTH-1:0] ones;
|
154 |
|
|
begin
|
155 |
|
|
seen0 = 1'b0;
|
156 |
|
|
trig1 = 1'b0;
|
157 |
|
|
ones = 0;
|
158 |
|
|
for (index=0; index<ECC_WIDTH; index=index+1)
|
159 |
|
|
begin
|
160 |
|
|
// The "== 1'bx" is so this will converge at time zero.
|
161 |
|
|
// XST assumes false, which should be OK.
|
162 |
|
|
if ((&i == 1'bx) || trig1) next_combo[index] = i[index];
|
163 |
|
|
else begin
|
164 |
|
|
next_combo[index] = 1'b0;
|
165 |
|
|
ones = ones + i[index];
|
166 |
|
|
if (i[index] && seen0) begin
|
167 |
|
|
trig1 = 1'b1;
|
168 |
|
|
for (dump_index=index-1; dump_index>=0;dump_index=dump_index-1)
|
169 |
|
|
if (dump_index>=index-ones) next_combo[dump_index] = 1'b1;
|
170 |
|
|
end
|
171 |
|
|
seen0 = ~i[index];
|
172 |
|
|
end // else: !if(trig1)
|
173 |
|
|
end
|
174 |
|
|
end // function
|
175 |
|
|
endfunction // next_combo
|
176 |
|
|
|
177 |
|
|
wire [ECC_WIDTH-1:0] ht_matrix [CODE_WIDTH-1:0];
|
178 |
|
|
output wire [CODE_WIDTH*ECC_WIDTH-1:0] h_rows;
|
179 |
|
|
|
180 |
|
|
localparam COMBOS_3 = combos(ECC_WIDTH, 3);
|
181 |
|
|
localparam COMBOS_5 = combos(ECC_WIDTH, 5);
|
182 |
|
|
genvar n;
|
183 |
|
|
genvar s;
|
184 |
|
|
generate
|
185 |
|
|
for (n=0; n<CODE_WIDTH; n=n+1) begin : ht
|
186 |
|
|
if (n == 0)
|
187 |
|
|
assign ht_matrix[n] = {{3{1'b1}}, {ECC_WIDTH-3{1'b0}}};
|
188 |
|
|
else if (n == COMBOS_3 && n < DATA_WIDTH)
|
189 |
|
|
assign ht_matrix[n] = {{5{1'b1}}, {ECC_WIDTH-5{1'b0}}};
|
190 |
|
|
else if ((n == COMBOS_3+COMBOS_5) && n < DATA_WIDTH)
|
191 |
|
|
assign ht_matrix[n] = {{7{1'b1}}, {ECC_WIDTH-7{1'b0}}};
|
192 |
|
|
else if (n == DATA_WIDTH)
|
193 |
|
|
assign ht_matrix[n] = {{1{1'b1}}, {ECC_WIDTH-1{1'b0}}};
|
194 |
|
|
else assign ht_matrix[n] = next_combo(ht_matrix[n-1]);
|
195 |
|
|
|
196 |
|
|
for (s=0; s<ECC_WIDTH; s=s+1) begin : h_row
|
197 |
|
|
assign h_rows[s*CODE_WIDTH+n] = ht_matrix[n][s];
|
198 |
|
|
end
|
199 |
|
|
end
|
200 |
|
|
endgenerate
|
201 |
|
|
|
202 |
|
|
endmodule // ecc_gen
|