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

Subversion Repositories bch_configurable

[/] [bch_configurable/] [trunk/] [src/] [test_correct.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Success105
///-----------------------------------------
2
///introduce:
3
///bch correct in decoder
4
///author:jiml
5
///record:
6
///2015.3.15    initial
7
///-----------------------------------------
8
`timescale 1ns/100ps
9
module test_correct
10
#(
11
parameter C_INPUT_NUM = 128,          //length of input bit 
12
parameter C_DWIDTH = 16,              //input data width
13
parameter C_ECCWIDTH = 16             //check data width
14
)
15
(
16
input                     I_clk        ,
17
input                     I_rst        ,
18
input [C_DWIDTH-1:0]      I_data       ,  //input data
19
input                     I_data_sof   ,  //input data frame start
20
input                     I_data_eof   ,  //input data frame end
21
input                     I_data_v     ,  //input data available
22
input [C_ECCWIDTH-1:0]    I_ecc        ,  //check data
23
input                     I_ecc_v      ,  //check data available
24
input                     I_ecc_sof    ,  //check data frame start
25
input                     I_ecc_eof    ,  //check data frame end
26
output reg [C_DWIDTH-1:0] O_data       ,  //corrected data
27
output reg                O_data_v     ,  //corrected data available
28
output reg                O_data_sof   ,  //corrected data frame start
29
output reg                O_data_eof      //corrected data frame end
30
);
31
 
32
//----------------------------------------
33
//parameter and variable
34
//----------------------------------------
35
localparam C_OVERFLOW_THRESHOLD = C_DWIDTH-C_ECCWIDTH+1;
36
localparam C_DIF = C_DWIDTH - C_ECCWIDTH;
37
localparam C_SLR_CNT_WIDTH = GETASIZE(C_DWIDTH)+1;
38
localparam C_CHIP_NUM = C_INPUT_NUM/C_DWIDTH;
39
localparam C_CHIP_NUM_WIDTH = GETASIZE(C_CHIP_NUM);
40
 
41
reg [2*C_DWIDTH-1:0] S_data_slr = 0;
42
reg [C_SLR_CNT_WIDTH-1:0] S_slr_cnt = 0;
43
reg S_ov_id = 0;
44
reg [C_DWIDTH-1:0] S_data_tran = 0;
45
reg S_ecc_eof = 0;
46
reg S_ecc_eof_d = 0;
47
reg S_ecc_v = 0;
48
reg [C_ECCWIDTH-1:0] S_ecc = 0;
49
reg S_data_tran_v = 0;
50
reg [C_DWIDTH-1:0] S_ecc_ram [2**C_CHIP_NUM_WIDTH-1:0];
51
reg [C_DWIDTH-1:0] S_data_ram [2**C_CHIP_NUM_WIDTH-1:0];
52
reg [C_CHIP_NUM_WIDTH-1:0] S_ecc_waddr = 0;
53
reg [C_CHIP_NUM_WIDTH:0] S_data_waddr = 0;
54
reg [C_CHIP_NUM_WIDTH-1:0] S_ecc_raddr = 0;
55
reg S_ecc_r = 0;
56
reg [C_DWIDTH-1:0] S_ecc_dout;
57
reg [C_DWIDTH-1:0] S_dataout;
58
reg S_ecc_r_d = 0;
59
reg S_data_eof = 0;
60
//-------------------------------------------
61
//function
62
//-------------------------------------------
63
//width calculation
64
function integer GETASIZE;
65
input integer a;
66
integer i;
67
begin
68
    for(i=1;(2**i)<=a;i=i+1)
69
      begin
70
      end
71
    GETASIZE = i;
72
end
73
endfunction
74
 
75
//big endian change to little endian
76
function [C_DWIDTH-1:0] F_data_inv;
77
input [C_DWIDTH-1:0] S_datain;
78
integer i;
79
begin
80
    for(i=0;i<C_DWIDTH;i=i+1)
81
                F_data_inv[i] = S_datain[C_DWIDTH-1-i];
82
end
83
endfunction
84
 
85
//-----------------------------------------
86
//check data alignment
87
//-----------------------------------------
88
always @(posedge I_clk)
89
begin
90
    S_ecc_eof <= I_ecc_eof;
91
        S_ecc_eof_d <= S_ecc_eof;
92
        S_ecc_v <= I_ecc_v;
93
        S_ecc <= I_ecc;
94
end
95
 
96
always @(posedge I_clk)
97
begin
98
    if(S_ecc_eof)
99
        begin
100
                S_slr_cnt <= 'd0;
101
                S_ov_id <= 1'b0;
102
        end
103
        else if(I_ecc_v)
104
        begin
105
                if(S_slr_cnt <= C_OVERFLOW_THRESHOLD)
106
                begin
107
                S_slr_cnt <= S_slr_cnt + C_ECCWIDTH;
108
                        S_ov_id <= 1'b0;
109
                end
110
                else
111
                begin
112
                    S_slr_cnt <= S_slr_cnt - C_DIF;
113
                        S_ov_id <= 1'b1;
114
                end
115
        end
116
end
117
 
118
always @(posedge I_clk)
119
begin
120
    if(S_ecc_eof_d)
121
            S_data_slr <= 'd0;
122
        else if(I_ecc_v || S_ecc_v)
123
        begin
124
            if(!S_ov_id)
125
                        S_data_slr <= (I_ecc<<S_slr_cnt) | S_data_slr;
126
                else
127
                    S_data_slr <= (S_data_slr>>C_DWIDTH) | (I_ecc<<S_slr_cnt);
128
        end
129
end
130
 
131
always @(posedge I_clk)
132
begin
133
    if(S_ecc_v && S_ov_id)
134
            S_data_tran <= F_data_inv(S_data_slr[0+:C_DWIDTH]);
135
        else if(S_ecc_eof_d)
136
            S_data_tran <= F_data_inv(S_data_slr[0+:C_DWIDTH]);
137
end
138
 
139
always @(posedge I_clk)
140
begin
141
    S_data_tran_v <= (S_ecc_v && S_ov_id) || S_ecc_eof_d;
142
end
143
 
144
//--------------------------------------------------
145
//original data save
146
//--------------------------------------------------
147
always @(posedge I_clk)
148
begin
149
    if(I_data_v)
150
            S_data_ram[S_data_waddr[C_CHIP_NUM_WIDTH-1:0]] <= I_data;
151
        S_dataout <= S_data_ram[S_ecc_raddr];
152
        if(I_data_eof)
153
            S_data_waddr <= 'd0;
154
        else if(I_data_v && (S_data_waddr<C_CHIP_NUM))
155
            S_data_waddr <= S_data_waddr + 'd1;
156
end
157
 
158
always @(posedge I_clk)
159
begin
160
    if(S_data_tran_v)
161
            S_ecc_ram[S_ecc_waddr] <= S_data_tran;
162
        S_ecc_dout <= S_ecc_ram[S_ecc_raddr];
163
        if(I_ecc_sof)
164
            S_ecc_waddr <= 'd0;
165
        else if(S_data_tran_v)
166
            S_ecc_waddr <= S_ecc_waddr + 'd1;
167
end
168
 
169
always @(posedge I_clk)
170
begin
171
    if(S_ecc_waddr == C_CHIP_NUM-1 && S_data_tran_v)
172
            S_ecc_r <= 1'b1;
173
        else if(S_ecc_raddr == C_CHIP_NUM-1)
174
            S_ecc_r <= 1'b0;
175
        S_ecc_r_d <= S_ecc_r;
176
end
177
 
178
always @(posedge I_clk)
179
begin
180
    if(I_ecc_sof)
181
            S_ecc_raddr <= 'd0;
182
        else if(S_ecc_r)
183
            S_ecc_raddr <= S_ecc_raddr + 'd1;
184
end
185
 
186
//---------------------------------------
187
//correct
188
//---------------------------------------
189
always @(posedge I_clk)
190
begin
191
    O_data_sof <= S_ecc_raddr == 'd1;
192
        S_data_eof <= S_ecc_raddr == C_CHIP_NUM-1;
193
        O_data_eof <= S_data_eof;
194
end
195
 
196
always @(posedge I_clk)
197
begin
198
    O_data <= S_dataout ^ S_ecc_dout;
199
        O_data_v <= S_ecc_r_d;
200
end
201
 
202
endmodule

powered by: WebSVN 2.1.0

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