AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
mig_7series_v1_9_ecc_dec_fix.v
1  //*****************************************************************************
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_dec_fix.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 `timescale 1ps/1ps
66 
68  #(
69  parameter TCQ = 100,
70  parameter PAYLOAD_WIDTH = 64,
71  parameter CODE_WIDTH = 72,
72  parameter DATA_WIDTH = 64,
73  parameter DQ_WIDTH = 72,
74  parameter ECC_WIDTH = 8,
75  parameter nCK_PER_CLK = 4
76  )
77  (
78  /*AUTOARG**/
79  // Outputs
80  rd_data, ecc_single, ecc_multiple,
81  // Inputs
82  clk, rst, h_rows, phy_rddata, correct_en, ecc_status_valid
83  );
84 
85  input clk;
86  input rst;
87 
88  // Compute syndromes.
89  input [CODE_WIDTH*ECC_WIDTH-1:0] h_rows;
90  input [2*nCK_PER_CLK*DQ_WIDTH-1:0] phy_rddata;
91  wire [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_ns;
92  genvar k;
93  genvar m;
94  generate
95  for (k=0; k<2*nCK_PER_CLK; k=k+1) begin : ecc_word
96  for (m=0; m<ECC_WIDTH; m=m+1) begin : ecc_bit
97  assign syndrome_ns[k*ECC_WIDTH+m] =
98  ^(phy_rddata[k*DQ_WIDTH+:CODE_WIDTH] & h_rows[m*CODE_WIDTH+:CODE_WIDTH]);
99  end
100  end
101  endgenerate
102  reg [2*nCK_PER_CLK*ECC_WIDTH-1:0] syndrome_r;
103  always @(posedge clk) syndrome_r <= #TCQ syndrome_ns;
104 
105  // Extract payload bits from raw DRAM bits and register.
106  wire [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_ns;
107  genvar i;
108  generate
109  for (i=0; i<2*nCK_PER_CLK; i=i+1) begin : extract_payload
110  assign ecc_rddata_ns[i*PAYLOAD_WIDTH+:PAYLOAD_WIDTH] =
111  phy_rddata[i*DQ_WIDTH+:PAYLOAD_WIDTH];
112  end
113  endgenerate
114  reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] ecc_rddata_r;
115  always @(posedge clk) ecc_rddata_r <= #TCQ ecc_rddata_ns;
116 
117  // Regenerate h_matrix from h_rows leaving out the identity part
118  // since we're not going to correct the ECC bits themselves.
119  genvar n;
120  genvar p;
121  wire [ECC_WIDTH-1:0] h_matrix [DATA_WIDTH-1:0];
122  generate
123  for (n=0; n<DATA_WIDTH; n=n+1) begin : h_col
124  for (p=0; p<ECC_WIDTH; p=p+1) begin : h_bit
125  assign h_matrix [n][p] = h_rows [p*CODE_WIDTH+n];
126  end
127  end
128  endgenerate
129 
130  // Compute flip bits.
131  wire [2*nCK_PER_CLK*DATA_WIDTH-1:0] flip_bits;
132  genvar q;
133  genvar r;
134  generate
135  for (q=0; q<2*nCK_PER_CLK; q=q+1) begin : flip_word
136  for (r=0; r<DATA_WIDTH; r=r+1) begin : flip_bit
137  assign flip_bits[q*DATA_WIDTH+r] =
138  h_matrix[r] == syndrome_r[q*ECC_WIDTH+:ECC_WIDTH];
139  end
140  end
141  endgenerate
142 
143  // Correct data.
144  output reg [2*nCK_PER_CLK*PAYLOAD_WIDTH-1:0] rd_data;
145  input correct_en;
146  integer s;
147  always @(/*AS**/correct_en or ecc_rddata_r or flip_bits)
148  for (s=0; s<2*nCK_PER_CLK; s=s+1)
149  if (correct_en)
150  rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] =
151  ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH] ^
152  flip_bits[s*DATA_WIDTH+:DATA_WIDTH];
153  else rd_data[s*PAYLOAD_WIDTH+:DATA_WIDTH] =
154  ecc_rddata_r[s*PAYLOAD_WIDTH+:DATA_WIDTH];
155 
156  // Copy raw payload bits if ECC_TEST is ON.
157  localparam RAW_BIT_WIDTH = PAYLOAD_WIDTH - DATA_WIDTH;
158  genvar t;
159  generate
160  if (RAW_BIT_WIDTH > 0)
161  for (t=0; t<2*nCK_PER_CLK; t=t+1) begin : copy_raw_bits
162  always @(/*AS**/ecc_rddata_r)
163  rd_data[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH] =
164  ecc_rddata_r[(t+1)*PAYLOAD_WIDTH-1-:RAW_BIT_WIDTH];
165  end
166  endgenerate
167 
168  // Generate status information.
169  input ecc_status_valid;
170  output wire [2*nCK_PER_CLK-1:0] ecc_single;
171  output wire [2*nCK_PER_CLK-1:0] ecc_multiple;
172  genvar v;
173  generate
174  for (v=0; v<2*nCK_PER_CLK; v=v+1) begin : compute_status
175  wire zero = ~|syndrome_r[v*ECC_WIDTH+:ECC_WIDTH];
176  wire odd = ^syndrome_r[v*ECC_WIDTH+:ECC_WIDTH];
177  assign ecc_single[v] = ecc_status_valid && ~zero && odd;
178  assign ecc_multiple[v] = ecc_status_valid && ~zero && ~odd;
179  end
180  endgenerate
181 
182 endmodule