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

Subversion Repositories bch_configurable

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Success105
///-----------------------------------------
2
///introduce:
3
///bch error position search in decoder
4
///author:jiml
5
///record:
6
///2015.1.31    initial
7
///-----------------------------------------
8
`timescale 1ns/100ps
9
module test_chian_search
10
#(
11
parameter C_PRIMPOLY_ORDER = 14,              //order of eigenpolynomial
12
parameter C_COEF_NUM = 43,                    //correct threshold
13
parameter C_TOTALBIT_NUM = 8832,              //total bit length include original and correct bits
14
parameter C_THREAD_NUM = 8,                   //parallel search thread
15
parameter C_PRIMPOLY = 15'h4443               //eigenpolynomial
16
)
17
(
18
input                                                         I_clk       ,
19
input                                                         I_rst       ,
20
input      [C_PRIMPOLY_ORDER*C_COEF_NUM-1+C_PRIMPOLY_ORDER:0] I_coef      ,  //error position polynomial
21
input                                                         I_coef_v    ,  //error position polynomial available
22
output reg [C_THREAD_NUM-1:0]                                 O_data      ,  //check data
23
output reg                                                    O_data_v    ,  //check data available
24
output reg                                                    O_data_sof  ,  //check data frame start
25
output reg                                                    O_data_eof     //check data frame end
26
);
27
 
28
//--------------------------------------------
29
//parameter and variable
30
//--------------------------------------------
31
localparam C_SEARCH_START = 2**C_PRIMPOLY_ORDER - 1 - C_TOTALBIT_NUM;
32
localparam C_CNT_LIMIT = (C_TOTALBIT_NUM-1)/C_THREAD_NUM;
33
localparam C_CNT_LIMIT_WIDTH = GETASIZE(C_CNT_LIMIT);
34
 
35
reg S_search_v = 0;
36
reg [C_PRIMPOLY_ORDER-1:0] S_const = 0;
37
reg S_search_v_d = 0;
38
reg S_search_v_2d = 0;
39
reg S_search_v_3d = 0;
40
reg [C_CNT_LIMIT_WIDTH:0] S_search_cnt = 0;
41
reg [C_PRIMPOLY_ORDER*C_COEF_NUM-1:0] S_var [C_THREAD_NUM-1:0];
42
reg [C_PRIMPOLY_ORDER*C_COEF_NUM-1+C_PRIMPOLY_ORDER:0] S_var_xor [C_THREAD_NUM-1:0];
43
reg [C_PRIMPOLY_ORDER-1:0] S_var_xor_result [C_THREAD_NUM-1:0];
44
reg [C_THREAD_NUM-1:0] S_err_id = 0;
45
wire [C_PRIMPOLY_ORDER*C_COEF_NUM-1:0] S_coef1;
46
wire integer S_coef2 [C_THREAD_NUM-1:0];
47
 
48
//--------------------------------------------
49
//function
50
//--------------------------------------------
51
//element multiplication in Galois Field
52
function [C_PRIMPOLY_ORDER-1:0] F_var_upgrade;
53
input [C_PRIMPOLY_ORDER-1:0] S_mult;
54
input integer S_times;
55
integer i;
56
reg [C_PRIMPOLY_ORDER-1:0] S_temp;
57
reg [C_PRIMPOLY_ORDER-1:0] S_temp2;
58
reg S_temp_upp;
59
begin
60
        S_temp = S_mult;
61
        for(i=0;i<S_times;i=i+1)
62
        begin
63
                S_temp_upp = S_temp[C_PRIMPOLY_ORDER-1];
64
                S_temp2 = S_temp<<1;
65
                S_temp = S_temp2 ^ (C_PRIMPOLY[C_PRIMPOLY_ORDER-1:0] & {C_PRIMPOLY_ORDER{S_temp_upp}});
66
        end
67
        F_var_upgrade = S_temp;
68
end
69
endfunction
70
 
71
//width calculation
72
function integer GETASIZE;
73
input integer a;
74
integer i;
75
begin
76
    for(i=1;(2**i)<a;i=i+1)
77
      begin
78
      end
79
    GETASIZE = i;
80
end
81
endfunction
82
 
83
///-------------------------------
84
///search
85
///-------------------------------
86
always @(posedge I_clk)
87
begin
88
    if(I_rst)
89
            S_search_v <= 'd0;
90
        else if(I_coef_v)
91
            S_search_v <= 'd1;
92
        else if(S_search_cnt == C_CNT_LIMIT)
93
            S_search_v <= 'd0;
94
end
95
 
96
always @(posedge I_clk)
97
begin
98
    if(S_search_v)
99
            S_search_cnt <= S_search_cnt + 'd1;
100
        else
101
            S_search_cnt <= 'd0;
102
end
103
 
104
always @(posedge I_clk)
105
begin
106
        S_search_v_d <= S_search_v;
107
        S_search_v_2d <= S_search_v_d;
108
        S_search_v_3d <= S_search_v_2d;
109
end
110
 
111
always @(posedge I_clk)
112
begin
113
    if(I_coef_v)
114
            S_const <= I_coef[C_PRIMPOLY_ORDER-1:0];
115
end
116
 
117
assign S_coef1 = I_coef_v ? I_coef[C_PRIMPOLY_ORDER+:C_PRIMPOLY_ORDER*C_COEF_NUM] : S_var[C_THREAD_NUM-1];
118
 
119
genvar S_k;
120
integer k,kk;
121
generate
122
for(S_k=0;S_k<C_THREAD_NUM;S_k=S_k+1)                   //parallel search
123
begin:process
124
 
125
assign S_coef2[S_k] = I_coef_v ? C_SEARCH_START : (S_k+1);
126
 
127
always @(posedge I_clk)
128
begin
129
    for(k=0;k<C_COEF_NUM;k=k+1)
130
                S_var[S_k][C_PRIMPOLY_ORDER*k+:C_PRIMPOLY_ORDER] <= F_var_upgrade(S_coef1[C_PRIMPOLY_ORDER*k+:C_PRIMPOLY_ORDER],S_coef2[S_k]*(k+1));
131
end
132
 
133
always @(*)
134
begin
135
    S_var_xor[S_k][0+:C_PRIMPOLY_ORDER] = S_const;
136
end
137
 
138
always @(*)
139
begin
140
        for(kk=0;kk<C_COEF_NUM;kk=kk+1)
141
        S_var_xor[S_k][C_PRIMPOLY_ORDER*(kk+1)+:C_PRIMPOLY_ORDER] = I_coef_v ? 'd0 : (S_var_xor[S_k][C_PRIMPOLY_ORDER*(kk)+:C_PRIMPOLY_ORDER] ^ S_var[S_k][C_PRIMPOLY_ORDER*kk+:C_PRIMPOLY_ORDER]);
142
end
143
 
144
always @(posedge I_clk)
145
begin
146
    S_var_xor_result[S_k] <= S_var_xor[S_k][C_PRIMPOLY_ORDER*C_COEF_NUM+:C_PRIMPOLY_ORDER];
147
end
148
 
149
always @(posedge I_clk)
150
begin
151
    S_err_id[S_k] <= (S_var_xor_result[S_k] == 'd0);   //zero means error position
152
end
153
 
154
end
155
endgenerate
156
 
157
//-------------------------------------------
158
//check data output
159
//-------------------------------------------
160
always @(posedge I_clk)
161
begin
162
    O_data <= S_err_id;
163
        O_data_v <= S_search_v_3d;
164
end
165
 
166
always @(posedge I_clk)
167
begin
168
    O_data_sof <= S_search_v_3d && (!O_data_v);
169
        O_data_eof <= (!S_search_v_2d) && S_search_v_3d;
170
end
171
 
172
endmodule
173
 
174
 

powered by: WebSVN 2.1.0

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