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

Subversion Repositories reed_solomon_decoder

[/] [reed_solomon_decoder/] [trunk/] [rtl/] [BM_lamda.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 aelmahmoud
/* This program is free software: you can redistribute it and/or modify
2
   it under the terms of the GNU General Public License as published by
3
   the Free Software Foundation, either version 3 of the License, or
4
   (at your option) any later version.
5
 
6
   This program is distributed in the hope that it will be useful,
7
   but WITHOUT ANY WARRANTY; without even the implied warranty of
8
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
   GNU General Public License for more details.
10
 
11
   You should have received a copy of the GNU General Public License
12
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
13
 
14
   Email : semiconductors@varkongroup.com
15
   Tel   : 1-732-447-8611
16
 
17
*/
18
 
19
 
20
module BM_lamda
21
//// use Berlekamp Massey’s Algorithm to calculate lamda polynomial
22
(
23
input clk, // input clock planned to be 56 Mhz
24
input reset, // active high asynchronous reset
25
 
26
// input modified syndromes in decimal format 
27
input [7:0] Sm1,Sm2,Sm3,Sm4,Sm5,Sm6,Sm7,Sm8,
28
input [7:0] Sm9,Sm10,Sm11,Sm12,Sm13,Sm14,Sm15,Sm16,
29
 
30
//active high flag for one clock to indicate that input Sm is ready
31
input Sm_ready,
32
 
33
// active high flag for one clock to indicate that erasures values are ready
34
input erasure_ready,
35
input [3:0] erasure_cnt,  /// number of erasures per block 0:8 
36
 
37
input [7:0] pow1,pow2,    /// output of power memories
38
input [7:0] dec1,        /// output of decimal memories
39
 
40
output reg [7:0] add_pow1,add_pow2,     /// address to power memories
41
output  [7:0] add_dec1,                              /// address to decimal memories
42
 
43
// active high flag for one clock to indicate that lamda polynomial is ready
44
output reg L_ready,
45
output [7:0] L1,L2,L3,L4,L5,L6,L7,L8   ///  lamda coeff values in decimal format 
46
);
47
 
48
reg [7:0] L [1:9];   /// Lamda polynomial coeff
49
reg [7:0] Lt [1:9]; /// temp register for next Lamda polynomial coeff values
50
reg [7:0] T [1:10];  /// T polynomial
51
reg [7:0] D; /// delta
52
 
53
reg [4:0]  K;  //  max 16   // operation counter
54
reg [3:0]  N;  //  max 8    // operation counter
55
 
56
 
57
reg [3:0]  e_cnt;
58
reg [7:0] S [1:16];
59
 
60
 
61
reg [8:0] add_1;   /// address to decimal memory
62
reg IS_255_1;
63
reg div1;  ///  1  division ,  0 multiplication
64
 
65
reg [3:0] cnt ;  // max 12
66
 
67
parameter Step1  = 8'b00000001;
68
parameter Step2  = 8'b00000010;
69
parameter Step3  = 8'b00000100;
70
parameter Step4  = 8'b00001000;
71
parameter Step5  = 8'b00010000;
72
parameter Step6  = 8'b00100000;
73
parameter Step7  = 8'b01000000;
74
parameter Step8  = 8'b10000000;
75
 
76
reg [8:0] const_timing;
77
reg [7:0] Step = Step1;
78
 
79
assign L1=L[2];
80
assign L2=L[3];
81
assign L3=L[4];
82
assign L4=L[5];
83
assign L5=L[6];
84
assign L6=L[7];
85
assign L7=L[8];
86
assign L8=L[9];
87
 
88
//// to handle mutipilcation / division output (address to decimal memory)
89
assign add_dec1  =(IS_255_1)?  8'h00 :
90
                                 (&add_1[7:0] && !add_1[8])?     8'h01 :
91
                                 (div1)? add_1[7:0] - (add_1[8]) +1 :
92
                                 add_1[7:0] +add_1[8] +1 ;
93
 
94
always@(posedge reset or posedge clk)
95
begin
96
        if (reset)
97
                begin
98
                        add_1<=0;
99
                        IS_255_1<=0;
100
                        div1<=0;
101
                        add_pow1<=0;add_pow2<=0;
102
 
103
                        e_cnt<=0;
104
 
105
                        S[1]<=0;S[2]<=0;S[3]<=0;S[4]<=0;S[5]<=0;
106
                        S[6]<=0;S[7]<=0;S[8]<=0;
107
                        S[9]<=0;S[10]<=0;S[11]<=0;S[12]<=0;S[13]<=0;
108
                        S[14]<=0;S[15]<=0;S[16]<=0;
109
 
110
                        L[1]<=0; L[2]<=0; L[3]<=0;L[4]<=0;L[5]<=0;
111
                        L[6]<=0;L[7]<=0;L[8]<=0;L[9]<=0;
112
                        Lt[1]<=0; Lt[2]<=0; Lt[3]<=0;Lt[4]<=0;Lt[5]<=0;
113
                        Lt[6]<=0;Lt[7]<=0;Lt[8]<=0;Lt[9]<=0;
114
                        T[1]<=0; T[2]<=0; T[3]<=0;T[4]<=0;T[5]<=0;
115
                        T[6]<=0;T[7]<=0;T[8]<=0;T[9]<=0;T[10]<=0;
116
                        D<=0;
117
                        K<=0;
118
                        N<=0;
119
 
120
                        cnt<=0;
121
                        Step<=Step1;
122
 
123
                        L_ready<=0;
124
                        const_timing<=0;
125
                end
126
        else
127
                begin
128
                        case (Step)
129
                        /////////////////////////////////////////////////////////////////
130
                        default:begin  /// idle Step    ----- > Step1
131
                                L[1]<=1; L[2]<=0; L[3]<=0;L[4]<=0;L[5]<=0;
132
                                L[6]<=0;L[7]<=0;L[8]<=0;L[9]<=0;
133
                                Lt[1]<=1; Lt[2]<=0; Lt[3]<=0;Lt[4]<=0;Lt[5]<=0;
134
                                Lt[6]<=0;Lt[7]<=0;Lt[8]<=0;Lt[9]<=0;
135
                                T[1]<=0; T[2]<=1; T[3]<=0;T[4]<=0;T[5]<=0;
136
                                T[6]<=0;T[7]<=0;T[8]<=0;T[9]<=0;T[10]<=0;
137
                                D<=0;
138
                                K<=0;
139
                                N<=0;
140
                                cnt<=0;
141
                                L_ready<=0;
142
                                //////// register erasure count///////////////////////////////
143
                                if(erasure_ready)
144
                                        begin
145
                                                e_cnt<=erasure_cnt;
146
                                        end
147
                                //// when input modified syndromes are ready//////////
148
                                if(Sm_ready)
149
                                        begin
150
                                                Step<=Step2;
151
                                                S[1]<=Sm1;S[2]<=Sm2;S[3]<=Sm3;S[4]<=Sm4;S[5]<=Sm5;
152
                                                S[6]<=Sm6;S[7]<=Sm7;S[8]<=Sm8;
153
                                                S[9]<=Sm9;S[10]<=Sm10;S[11]<=Sm11;S[12]<=Sm12;
154
                                                S[13]<=Sm13;S[14]<=Sm14;S[15]<=Sm15;S[16]<=Sm16;
155
                                        end
156
                        end
157
                        //////////////////////////////////////////////////////////
158
                        Step2:begin
159
                                K<= K+1;
160
                                Step<=Step3;
161
                        end
162
                        /////////////////////////////////////////////////////////
163
                        Step3:begin
164
                                if (N==0)
165
                                        begin
166
                                                D<= S[K+e_cnt];
167
                                                if(S[K+e_cnt]==0)
168
                                                        Step<= Step6;
169
                                                else
170
                                                        Step <= Step4;
171
                                        end
172
                                else
173
                                        begin
174
 
175
                                                if(cnt == N+4)
176
                                                        begin
177
                                                                cnt<=0;
178
                                                                if ( (D^dec1)  == 0)
179
                                                                        Step <= Step6;
180
                                                                else
181
                                                                        Step <= Step4;
182
                                                        end
183
                                                else
184
                                                        cnt<=cnt+1;
185
                                                ///////////////////////////////////////////     
186
                                                if (cnt == 0)
187
                                                        begin
188
                                                                D<= S[K+e_cnt];
189
                                                        end
190
                                                else if (cnt < 5)
191
                                                        begin
192
                                                                add_pow1<= L[cnt+1];
193
                                                                add_pow2<= S[K+e_cnt-cnt];
194
 
195
                                                                div1<=0;
196
                                                                add_1<= pow1 + pow2;
197
                                                                IS_255_1<=(&pow1 || &pow2)? 1:0;
198
                                                        end
199
                                                else  /// from 5 to  N+4
200
                                                        begin
201
                                                                add_pow1<= L[cnt+1];
202
                                                                add_pow2<= S[K+e_cnt-cnt];
203
 
204
                                                                div1<=0;
205
                                                                add_1<= pow1 + pow2;
206
                                                                IS_255_1<=(&pow1 || &pow2)? 1:0;
207
 
208
                                                                D <= D ^ dec1;
209
                                                        end
210
                                        end
211
                        end
212
                        /////////////////////////////////////////////////////////
213
                        Step4:begin
214
                                ////////////////////////////////////////
215
                                if(cnt == (11 - e_cnt[3:1]) )
216
                                        begin
217
                                                cnt<=0;
218
                                                Step <= Step5;
219
                                        end
220
                                else
221
                                        cnt<=cnt+1;
222
                                ///////////////////////////////////////////     
223
                                add_pow1<= T[cnt+2];
224
                                add_pow2 <= D;
225
 
226
                                div1<=0;
227
                                add_1<= pow1 + pow2;
228
                                IS_255_1<=(&pow1 || &pow2)? 1:0;
229
 
230
                                if (cnt>3)
231
                                        begin
232
                                                Lt[cnt-2] <= L[cnt-2] ^ dec1;
233
                                        end
234
                        end
235
                        /////////////////////////////////////////////////////////////
236
                        Step5:begin
237
                                if ({N,1'b0} >= K )     /// 2N >= K
238
                                        begin
239
                                                Step<=Step6;
240
                                                L[1]<=Lt[1]; L[2]<=Lt[2]; L[3]<=Lt[3];
241
                                                L[4]<=Lt[4]; L[5]<=Lt[5];
242
                                                L[6]<=Lt[6]; L[7]<=Lt[7];
243
                                                L[8]<=Lt[8]; L[9]<=Lt[9];
244
                                        end
245
                                else
246
                                        begin
247
                                                ////////////////////////////////////////
248
                                                if(cnt == (12-e_cnt[3:1]) )
249
                                                        begin
250
                                                                cnt<=0;
251
                                                                Step <= Step6;
252
 
253
                                                                N <= K - N;
254
 
255
                                                                L[1]<=Lt[1]; L[2]<=Lt[2]; L[3]<=Lt[3];
256
                                                                L[4]<=Lt[4]; L[5]<=Lt[5];
257
                                                                L[6]<=Lt[6]; L[7]<=Lt[7];
258
                                                                L[8]<=Lt[8]; L[9]<=Lt[9];
259
                                                        end
260
                                                else
261
                                                        cnt<=cnt+1;
262
                                                ///////////////////////////////////////////     
263
                                                add_pow1<= L[cnt+1];
264
                                                add_pow2 <= D;
265
 
266
                                                div1<=1;
267
                                                add_1<= pow1 - pow2;
268
                                                IS_255_1<=(&pow1 || &pow2)? 1:0;
269
 
270
                                                if (cnt>3)
271
                                                        begin
272
                                                                T[cnt-3] <= dec1;
273
                                                        end
274
                                                //////////////////////////////////////////////
275
                                        end
276
                        end
277
                        ////////////////////////////////////////////////////////////
278
                        Step6:begin
279
                                Step<=Step7;
280
                                T[1]<=0;
281
                                T[2]<=T[1];
282
                                T[3]<=T[2];
283
                                T[4]<=T[3];
284
                                T[5]<=T[4];
285
                                T[6]<=T[5];
286
                                T[7]<=T[6];
287
                                T[8]<=T[7];
288
                                T[9]<=T[8];
289
                                T[10]<=T[9];
290
                        end
291
                        ////////////////////////////////////////////////////////////
292
                        Step7:begin
293
                                if(K< 16 - e_cnt)
294
                                        Step<=Step2;
295
                                else
296
                                        begin
297
                                                Step<=Step8;
298
                                        end
299
                        end
300
                        ////////////////////////////////////////////////////////////
301
                        Step8: begin
302
                                if(const_timing == 0)
303
                                        begin
304
                                                L_ready<=1;
305
                                                Step<=Step1;
306
                                        end
307
                        end
308
                        ////////////////////////////////////////////////////////////
309
                        endcase
310
 
311
                        ////////////////  const timing Step machine //////////
312
                        if(Step == Step1)
313
                                begin
314
                                        //// max possible is estimated to 500 clks
315
                                        const_timing<=500;
316
                                end
317
                        else
318
                                begin
319
                                        const_timing <=const_timing -1;
320
                                end
321
                        //////////////////////////////////////////
322
 
323
                end
324
end
325
 
326
 
327
endmodule

powered by: WebSVN 2.1.0

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