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

Subversion Repositories reed_solomon_codec_generator

[/] [reed_solomon_codec_generator/] [trunk/] [source/] [RsDecodeChien.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeChien
3
// File Name   : RsDecodeChien.cpp
4
// Function    : RTL Decoder Chien Module generation
5
// 
6
// Revision History:
7
// Date          By           Version    Change Description
8
//===================================================================
9
// 2009/02/03  Gael Sapience     1.0       Original
10
//
11
//===================================================================
12
// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.
13
//
14
#include <stdio.h>
15
#include <stdlib.h>
16
#include <iostream>
17
#include<windows.h>
18
#include<fstream>
19
#include <string.h>
20
using namespace std;
21
 
22
FILE  *OutFileDecodeChien;
23
void RsGfMultiplier( int*, int*,int*, int, int);
24
 
25
void RsDecodeChien(int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int ErasureOption, int *MrefTab, int *PrefTab, int errorStats, int passFailFlag, int pathFlag, int lengthPath, char *rootFolderPath) {
26
 
27
 
28
   //---------------------------------------------------------------
29
   // C++ variables
30
   //---------------------------------------------------------------
31
   int syndromeLength;
32
   syndromeLength = TotalSize - DataSize;
33
 
34
   int ii,jj,zz,kk;
35
   int MaxValue;
36
   int param1;
37
   int tempix;
38
   int tempo2;
39
   int index;
40
   int initValue;
41
   int Pidx;
42
   int init;
43
   int idx1;
44
   int idx2;
45
   int tempNum;
46
   int mmTabSize = (bitSymbol*2) -1;
47
   int indexSyndrome;
48
   int countSize;
49
   int lambdaPointer;
50
   int omegaPointer;
51
   int *coeffTab;
52
   int *initTab;
53
   int *x1Tab;
54
   int *x2Tab;
55
   int *ppTab;
56
   int *powerTab;
57
   int *bbTab;
58
   int *ttTab;
59
   int *bidon;
60
   char *strRsDecodeChien;
61
 
62
   MaxValue = 2;
63
   for(ii=0; ii<(bitSymbol-1); ii++){
64
      MaxValue = MaxValue*2;
65
   }
66
 
67
   coeffTab = new int[MaxValue];
68
   initTab  = new int[MaxValue];
69
   x1Tab    = new int[bitSymbol];
70
   x2Tab    = new int[bitSymbol];
71
   ppTab    = new int[bitSymbol];
72
   powerTab = new int[bitSymbol];
73
   bbTab    = new int[bitSymbol];
74
   ttTab    = new int[bitSymbol];
75
   bidon    = new int[bitSymbol];
76
 
77
 
78
   if (ErasureOption == 0){
79
      lambdaPointer = (syndromeLength/2)+1;
80
      omegaPointer  = (syndromeLength/2);
81
   }else{
82
      lambdaPointer = syndromeLength;
83
      omegaPointer  = syndromeLength;
84
   }
85
 
86
 
87
 
88
   //---------------------------------------------------------------
89
   //---------------------------------------------------------------
90
   countSize = 0;
91
 
92
   if (TotalSize > 2047) {
93
      countSize = 12;
94
   } else{
95
      if (TotalSize > 1023) {
96
         countSize = 11;
97
      } else{
98
         if (TotalSize > 511) {
99
            countSize = 10;
100
         }else{
101
            if (TotalSize > 255) {
102
               countSize = 9;
103
            }else{
104
               if (TotalSize > 127) {
105
                  countSize = 8;
106
               }else{
107
                  if (TotalSize > 63) {
108
                     countSize = 7;
109
                  }else{
110
                     if (TotalSize > 31) {
111
                        countSize = 6;
112
                     }else{
113
                        if (TotalSize > 15) {
114
                           countSize = 5;
115
                        }else{
116
                           if (TotalSize > 7) {
117
                              countSize = 4;
118
                           }else{
119
                              if (TotalSize > 3) {
120
                                 countSize = 3;
121
                              }else{
122
                                 countSize = 2;
123
                              }
124
                           }
125
                        }
126
                     }
127
                  }
128
               }
129
            }
130
         }
131
      }
132
   }
133
 
134
 
135
   //---------------------------------------------------------------
136
   // calculate indexSyndrome
137
   //---------------------------------------------------------------
138
   if (syndromeLength > 2047) {
139
      indexSyndrome = 11;
140
   }
141
   else if (syndromeLength > 1023) {
142
      indexSyndrome = 10;
143
   }
144
   else if (syndromeLength > 511) {
145
      indexSyndrome = 9;
146
   }
147
   else if (syndromeLength > 255) {
148
      indexSyndrome = 8;
149
   }
150
   else if (syndromeLength > 127) {
151
      indexSyndrome = 7;
152
   }
153
   else if  (syndromeLength > 63) {
154
      indexSyndrome = 6;
155
   }
156
   else if  (syndromeLength > 31) {
157
      indexSyndrome = 5;
158
   }
159
   else if  (syndromeLength > 15) {
160
      indexSyndrome = 4;
161
   }
162
   else if  (syndromeLength > 7) {
163
      indexSyndrome = 3;
164
   }
165
   else if  (syndromeLength > 3) {
166
      indexSyndrome = 2;
167
   }
168
   else {
169
      indexSyndrome = 1;
170
   }
171
 
172
 
173
   //---------------------------------------------------------------
174
   // open file
175
   //---------------------------------------------------------------
176
   strRsDecodeChien = (char *)calloc(lengthPath + 21,  sizeof(char));
177
   if (pathFlag == 0) {
178
        strRsDecodeChien[0] = '.';
179
   }else{
180
      for(ii=0; ii<lengthPath; ii++){
181
         strRsDecodeChien[ii] = rootFolderPath[ii];
182
      }
183
   }
184
   strcat(strRsDecodeChien, "/rtl/RsDecodeChien.v");
185
 
186
   OutFileDecodeChien = fopen(strRsDecodeChien,"w");
187
 
188
 
189
   //---------------------------------------------------------------
190
   // write File Header
191
   //---------------------------------------------------------------
192
   fprintf(OutFileDecodeChien, "//===================================================================\n");
193
   fprintf(OutFileDecodeChien, "// Module Name : RsDecodeChien\n");
194
   fprintf(OutFileDecodeChien, "// File Name   : RsDecodeChien.v\n");
195
   fprintf(OutFileDecodeChien, "// Function    : Rs Decoder Chien search algorithm Module\n");
196
   fprintf(OutFileDecodeChien, "// \n");
197
   fprintf(OutFileDecodeChien, "// Revision History:\n");
198
   fprintf(OutFileDecodeChien, "// Date          By           Version    Change Description\n");
199
   fprintf(OutFileDecodeChien, "//===================================================================\n");
200
   fprintf(OutFileDecodeChien, "// 2009/02/03  Gael Sapience     1.0       Original\n");
201
   fprintf(OutFileDecodeChien, "//\n");
202
   fprintf(OutFileDecodeChien, "//===================================================================\n");
203
   fprintf(OutFileDecodeChien, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
204
   fprintf(OutFileDecodeChien, "//\n\n\n");
205
 
206
   //---------------------------------------------------------------
207
   // Ports Declaration
208
   //---------------------------------------------------------------
209
   fprintf(OutFileDecodeChien, "module RsDecodeChien(\n");
210
   fprintf(OutFileDecodeChien, "   CLK,            // system clock\n");
211
   fprintf(OutFileDecodeChien, "   RESET,          // system reset\n");
212
   fprintf(OutFileDecodeChien, "   enable,         // enable signal\n");
213
   fprintf(OutFileDecodeChien, "   sync,           // sync signal\n");
214
   if (ErasureOption == 1) {
215
      fprintf(OutFileDecodeChien, "   erasureIn,      // erasure input\n");
216
   }
217
 
218
//   for (ii=0; ii<syndromeLength;ii++){
219
   for (ii=0; ii<lambdaPointer;ii++){
220
      if (ii < 10) {
221
         fprintf(OutFileDecodeChien, "   lambdaIn_%d,     // lambda polynom %d\n", ii, ii);
222
      }else{
223
         fprintf(OutFileDecodeChien, "   lambdaIn_%d,    // lambda polynom %d\n", ii, ii);
224
      }
225
   }
226
 
227
//   for (ii=0 ; ii<syndromeLength;ii++){
228
   for (ii=0 ; ii<omegaPointer;ii++){
229
      if (ii < 10) {
230
         fprintf(OutFileDecodeChien, "   omegaIn_%d,      // omega polynom %d\n", ii, ii);
231
      }else{
232
         fprintf(OutFileDecodeChien, "   omegaIn_%d,     // omega polynom %d\n", ii, ii);
233
      }
234
   }
235
 
236
   if (ErasureOption == 1) {
237
      for (ii=0; ii<(syndromeLength+1);ii++){
238
         if (ii < 10) {
239
            fprintf(OutFileDecodeChien, "   epsilonIn_%d,    // epsilon polynom %d\n", ii, ii);
240
         }else{
241
            fprintf(OutFileDecodeChien, "   epsilonIn_%d,   // epsilon polynom %d\n", ii, ii);
242
         }
243
      }
244
   }
245
 
246
   fprintf(OutFileDecodeChien, "   errorOut,       // error output\n");
247
   if ((errorStats!=0) || (passFailFlag!=0)) {
248
      fprintf(OutFileDecodeChien, "   numError,       // error amount\n");
249
   }
250
   fprintf(OutFileDecodeChien, "   done            // done signal\n");
251
   fprintf(OutFileDecodeChien, ");\n\n\n");
252
 
253
 
254
   //---------------------------------------------------------------
255
   // I/O instantiation
256
   //---------------------------------------------------------------
257
   fprintf(OutFileDecodeChien, "   input          CLK;            // system clock\n");
258
   fprintf(OutFileDecodeChien, "   input          RESET;          // system reset\n");
259
   fprintf(OutFileDecodeChien, "   input          enable;         // enable signal\n");
260
   fprintf(OutFileDecodeChien, "   input          sync;           // sync signal\n");
261
   if (ErasureOption == 1) {
262
      fprintf(OutFileDecodeChien, "   input          erasureIn;      // erasure input\n");
263
   }
264
 
265
//   for (ii=0;ii<(syndromeLength);ii++){
266
   for (ii=0;ii<(lambdaPointer);ii++){
267
      if (ii < 10){
268
         fprintf(OutFileDecodeChien, "   input  [%d:0]   lambdaIn_%d;     // lambda polynom %d\n", bitSymbol-1, ii, ii);
269
      }else{
270
         fprintf(OutFileDecodeChien, "   input  [%d:0]   lambdaIn_%d;    // lambda polynom %d\n", bitSymbol-1, ii, ii);
271
      }
272
   }
273
 
274
//   for (ii=0;ii<(syndromeLength);ii++){
275
   for (ii=0;ii<(omegaPointer);ii++){
276
      if (ii < 10) {
277
         fprintf(OutFileDecodeChien, "   input  [%d:0]   omegaIn_%d;      // omega polynom %d\n", bitSymbol-1, ii, ii);
278
      }else{
279
         fprintf(OutFileDecodeChien, "   input  [%d:0]   omegaIn_%d;     // omega polynom %d\n", bitSymbol-1, ii, ii);
280
      }
281
   }
282
   fprintf(OutFileDecodeChien, "\n");
283
 
284
   if (ErasureOption == 1) {
285
      for (ii=0; ii<(syndromeLength+1);ii++){
286
         if (ii < 10) {
287
            fprintf(OutFileDecodeChien, "   input  [%d:0]   epsilonIn_%d;    // epsilon polynom %d\n", bitSymbol-1, ii, ii);
288
         }else{
289
            fprintf(OutFileDecodeChien, "   input  [%d:0]   epsilonIn_%d;   // epsilon polynom %d\n", bitSymbol-1, ii, ii);
290
         }
291
      }
292
   }
293
   fprintf(OutFileDecodeChien, "   output [%d:0]   errorOut;       // error output\n", bitSymbol-1);
294
   if ((errorStats!=0) || (passFailFlag!=0)) {
295
      fprintf(OutFileDecodeChien, "   output [%d:0]   numError;       // error amount\n", indexSyndrome);
296
   }
297
   fprintf(OutFileDecodeChien, "   output         done;           // done signal\n");
298
   fprintf(OutFileDecodeChien, "\n\n\n");
299
 
300
 
301
   //------------------------------------------------------------------------
302
   //- registers instantiation
303
   //------------------------------------------------------------------------
304
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
305
   fprintf(OutFileDecodeChien, "   // + \n");
306
   fprintf(OutFileDecodeChien, "   //- registers\n");
307
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
308
 
309
   if (ErasureOption == 1) {
310
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaSum;\n", bitSymbol-1);
311
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaSumReg;\n", bitSymbol-1);
312
   }
313
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaEven;\n", bitSymbol-1);
314
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaEvenReg;\n", bitSymbol-1);
315
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaEvenReg2;\n", bitSymbol-1);
316
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaEvenReg3;\n", bitSymbol-1);
317
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaOdd;\n", bitSymbol-1);
318
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaOddReg;\n", bitSymbol-1);
319
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaOddReg2;\n", bitSymbol-1);
320
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaOddReg3;\n", bitSymbol-1);
321
   fprintf(OutFileDecodeChien, "   wire [%d:0]   denomE0;\n", bitSymbol-1);
322
 
323
   if (ErasureOption == 1){
324
      fprintf(OutFileDecodeChien, "   wire [%d:0]   denomE1;\n", bitSymbol-1);
325
   }
326
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   denomE0Reg;\n", bitSymbol-1);
327
   if (ErasureOption == 1){
328
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   denomE1Reg;\n", bitSymbol-1);
329
   }
330
   fprintf(OutFileDecodeChien, "   wire [%d:0]   denomE0Inv;\n", bitSymbol-1);
331
   if (ErasureOption == 1){
332
      fprintf(OutFileDecodeChien, "   wire [%d:0]   denomE1Inv;\n", bitSymbol-1);
333
   }
334
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   denomE0InvReg;\n", bitSymbol-1);
335
   if (ErasureOption == 1){
336
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   denomE1InvReg;\n", bitSymbol-1);
337
   }
338
 
339
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   omegaSum;\n", bitSymbol-1);
340
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   omegaSumReg;\n", bitSymbol-1);
341
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   numeReg;\n", bitSymbol-1);
342
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   numeReg2;\n", bitSymbol-1);
343
 
344
   if (ErasureOption == 1){
345
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   epsilonSum;\n", bitSymbol-1);
346
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   epsilonSumReg;\n", bitSymbol-1);
347
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   epsilonOdd;\n", bitSymbol-1);
348
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   epsilonOddReg;\n", bitSymbol-1);
349
   }
350
 
351
   fprintf(OutFileDecodeChien, "   wire [%d:0]   errorValueE0;\n", bitSymbol-1);
352
   if (ErasureOption == 1){
353
      fprintf(OutFileDecodeChien, "   wire [%d:0]   errorValueE1;\n", bitSymbol-1);
354
   }
355
 
356
//   fprintf(OutFileDecodeChien, "   reg  [%d:0]   count;\n", bitSymbol);
357
   fprintf(OutFileDecodeChien, "   reg  [%d:0]   count;\n", countSize-1);
358
   fprintf(OutFileDecodeChien, "   reg          doneOrg;\n");
359
   fprintf(OutFileDecodeChien, "\n\n");
360
 
361
 
362
   //------------------------------------------------------------------------
363
   //- coeffTab initialize
364
   //------------------------------------------------------------------------
365
   coeffTab [0] = 0;
366
   coeffTab [1] = MaxValue - TotalSize;
367
   param1 = MaxValue - TotalSize;
368
 
369
 
370
   //------------------------------------------------------------------------
371
   //- x1Tab initialize
372
   //------------------------------------------------------------------------
373
   x1Tab[0] = 1;
374
   for (ii=1;ii<bitSymbol;ii++){
375
      x1Tab[ii] = 0;
376
   }
377
 
378
 
379
   //------------------------------------------------------------------------
380
   //- x2Tab initialize
381
   //------------------------------------------------------------------------
382
   x2Tab[0] = 0;
383
   x2Tab[1] = 1;
384
   for (ii=2;ii<bitSymbol;ii++){
385
      x2Tab[ii] = 0;
386
   }
387
 
388
 
389
   //------------------------------------------------------------------------
390
   //- powerTab initialize
391
   //------------------------------------------------------------------------
392
   powerTab[0] = 1;
393
   for (ii=1; ii<bitSymbol;ii++){
394
      powerTab[ii] = 2*powerTab[ii-1];
395
   }
396
 
397
 
398
   //------------------------------------------------------------------------
399
   //- phase 1 : initTab calculation
400
   //------------------------------------------------------------------------
401
   for(ii=0;ii<MaxValue;ii++){
402
 
403
      //------------------------------------------------------------------------
404
      //- ppTab = x1Tab * x2Tab
405
      //------------------------------------------------------------------------
406
      RsGfMultiplier(ppTab, x1Tab, x2Tab, PrimPoly, bitSymbol);
407
 
408
 
409
      //------------------------------------------------------------------------
410
      //- reassign x1Tab
411
      //------------------------------------------------------------------------
412
      for (zz=0; zz<bitSymbol;zz++){
413
         x1Tab[zz]      = ppTab[zz];
414
      }
415
 
416
 
417
      //------------------------------------------------------------------------
418
      //- Binary To Decimal initValue[dec] = x1Tab[bin]
419
      //------------------------------------------------------------------------
420
      initValue = 0;
421
      for (zz=0; zz<bitSymbol;zz++){
422
         initValue = initValue + x1Tab[zz] * powerTab[zz];
423
      }
424
      initTab[ii] = initValue;
425
   }
426
 
427
 
428
   //------------------------------------------------------------------------
429
   //- Decimal To Binary x1Tab[bin] = x2Tab[bin] = tempix[dec]
430
   //------------------------------------------------------------------------
431
   tempix = initTab[param1-1];
432
 
433
   for (zz =bitSymbol-1; zz>=0;zz--) {
434
      if (tempix >= powerTab[zz]) {
435
         tempix = tempix - powerTab[zz];
436
         x1Tab [zz] = 1;
437
         x2Tab [zz] = 1;
438
      }else{
439
         x1Tab [zz] = 0;
440
         x2Tab [zz] = 0;
441
      }
442
   }
443
 
444
 
445
 
446
   //------------------------------------------------------------------------
447
   //- phase 2
448
   //------------------------------------------------------------------------
449
   for (ii = 1;ii<(syndromeLength+1); ii++){
450
 
451
      //------------------------------------------------------------------------
452
      //- ppTab = x1Tab * x2Tab
453
      //------------------------------------------------------------------------
454
      RsGfMultiplier(ppTab, x1Tab, x2Tab, PrimPoly, bitSymbol);
455
 
456
 
457
      //------------------------------------------------------------------------
458
      //- reassign x1Tab
459
      //------------------------------------------------------------------------
460
      for (zz=0; zz<bitSymbol;zz++){
461
         x2Tab[zz]      = ppTab[zz];
462
      }
463
 
464
 
465
      //------------------------------------------------------------------------
466
      //- Binary To Decimal initValue[dec] = x2Tab[bin]
467
      //------------------------------------------------------------------------
468
      initValue = 0;
469
      for (zz=0; zz<bitSymbol;zz++){
470
         initValue = initValue + x2Tab[zz] * powerTab[zz];
471
      }
472
      tempo2= initValue;
473
 
474
 
475
      //------------------------------------------------------------------------
476
      //- index search
477
      //------------------------------------------------------------------------
478
      index = 0;
479
      for (jj=0;jj<MaxValue;jj++){
480
         if (initTab[jj]==tempo2){
481
            if (jj == (MaxValue-1)){
482
               index = 0;
483
            }else{
484
               index = jj;
485
            }
486
         }
487
      }
488
      coeffTab[ii+1] = index+1;
489
   }
490
 
491
 
492
   fprintf(OutFileDecodeChien, "\n\n\n");
493
 
494
 
495
 
496
   //------------------------------------------------------------------
497
   // + count
498
   //------------------------------------------------------------------
499
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
500
   fprintf(OutFileDecodeChien, "   // + count\n");
501
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
502
   fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
503
   fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
504
//   fprintf(OutFileDecodeChien, "         count [%d:0] <= %d'd0;\n", bitSymbol, bitSymbol+1);
505
   fprintf(OutFileDecodeChien, "         count [%d:0] <= %d'd0;\n", countSize-1, countSize);
506
   fprintf(OutFileDecodeChien, "      end\n");
507
   fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
508
 
509
   fprintf(OutFileDecodeChien, "         if (sync == 1'b1) begin\n");
510
//   fprintf(OutFileDecodeChien, "            count[%d:0] <= %d'd1;\n", bitSymbol, bitSymbol+1);
511
   fprintf(OutFileDecodeChien, "            count[%d:0] <= %d'd1;\n", countSize-1, countSize);
512
   fprintf(OutFileDecodeChien, "         end\n");
513
//   fprintf(OutFileDecodeChien, "         else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n", bitSymbol, bitSymbol+1, bitSymbol, bitSymbol+1,TotalSize);
514
   fprintf(OutFileDecodeChien, "         else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n", countSize-1, countSize, countSize-1, countSize,TotalSize);
515
//   fprintf(OutFileDecodeChien, "            count[%d:0] <= %d'd0;\n", bitSymbol, bitSymbol+1);
516
   fprintf(OutFileDecodeChien, "            count[%d:0] <= %d'd0;\n", countSize-1, countSize);
517
   fprintf(OutFileDecodeChien, "         end\n");
518
   fprintf(OutFileDecodeChien, "         else begin\n");
519
//   fprintf(OutFileDecodeChien, "            count[%d:0] <= count[%d:0] + %d'd1;\n", bitSymbol, bitSymbol, bitSymbol+1);
520
   fprintf(OutFileDecodeChien, "            count[%d:0] <= count[%d:0] + %d'd1;\n", countSize-1, countSize-1, countSize);
521
   fprintf(OutFileDecodeChien, "         end\n");
522
   fprintf(OutFileDecodeChien, "      end\n");
523
   fprintf(OutFileDecodeChien, "   end\n");
524
   fprintf(OutFileDecodeChien, "\n\n\n");
525
 
526
 
527
   //------------------------------------------------------------------
528
   // + doneOrg
529
   //------------------------------------------------------------------
530
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
531
   fprintf(OutFileDecodeChien, "   // + doneOrg\n");
532
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
533
   fprintf(OutFileDecodeChien, "   always @(count) begin\n");
534
   fprintf(OutFileDecodeChien, "      if (count[%d:0] == %d'd%d) begin\n", countSize-1, countSize, TotalSize);
535
   fprintf(OutFileDecodeChien, "         doneOrg   = 1'b1;\n");
536
   fprintf(OutFileDecodeChien, "      end else begin\n");
537
   fprintf(OutFileDecodeChien, "         doneOrg   = 1'b0;\n");
538
   fprintf(OutFileDecodeChien, "      end\n");
539
   fprintf(OutFileDecodeChien, "   end\n");
540
   fprintf(OutFileDecodeChien, "\n");
541
   fprintf(OutFileDecodeChien, "   assign   done   = doneOrg;\n");
542
   fprintf(OutFileDecodeChien, "\n\n\n");
543
 
544
 
545
   //------------------------------------------------------------------------
546
   //- LAMBDA_INI = CHIEN_COEFF_LI * LAMBDA_IN
547
   //------------------------------------------------------------------------
548
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
549
   fprintf(OutFileDecodeChien, "   //- lambdaIni\n");
550
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
551
//   for (ii=0;ii<syndromeLength;ii++){
552
   for (ii=0;ii<lambdaPointer;ii++){
553
      fprintf(OutFileDecodeChien, "   wire [%d:0]   lambdaIni_%d;\n",bitSymbol-1,ii);
554
   }
555
   fprintf(OutFileDecodeChien, "\n\n");
556
 
557
 
558
 
559
 
560
//   for (zz=0;zz<syndromeLength;zz++){
561
   for (zz=0;zz<lambdaPointer;zz++){
562
      //------------------------------------------------------------------------
563
      //- mult Coeff Emulator
564
      //------------------------------------------------------------------------
565
      if (coeffTab[zz] ==0) {
566
         for (ii=0;ii<bitSymbol;ii++){
567
            fprintf(OutFileDecodeChien, "   assign lambdaIni_%d [%d] = lambdaIn_%d[%d];\n", zz, ii, zz, ii);
568
         }
569
      }else{
570
 
571
         //------------------------------------------------------------------------
572
         // initialize ttTab
573
         //------------------------------------------------------------------------
574
         ttTab[0] = 1;
575
         for (ii=1;ii<bitSymbol;ii++){
576
            ttTab[ii] = 0;
577
         }
578
 
579
 
580
         //------------------------------------------------------------------------
581
         // initialize bbTab
582
         //------------------------------------------------------------------------
583
         bbTab[0] = 0;
584
         bbTab[1] = 1;
585
         for (ii=2;ii<bitSymbol;ii++){
586
            bbTab[ii] = 0;
587
         }
588
 
589
 
590
         for(ii=1; ii<(coeffTab[zz]+1); ii++){
591
 
592
            //------------------------------------------------------------------------
593
            //- ppTab = ttTab * bbTab
594
            //------------------------------------------------------------------------
595
            RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
596
 
597
            //------------------------------------------------------------------------
598
            //- reassign ttTab
599
            //------------------------------------------------------------------------
600
            for (kk=0;kk<bitSymbol;kk++){
601
               ttTab[kk]        = ppTab[kk];
602
            }
603
 
604
            //------------------------------------------------------------------------
605
            // write P_OUT[0]
606
            //------------------------------------------------------------------------
607
            if (ii==coeffTab[zz]) {
608
               for (Pidx=0; Pidx<bitSymbol; Pidx++){
609
                  fprintf(OutFileDecodeChien, "   assign lambdaIni_%d [%d] =", zz,Pidx);
610
                  init = 0;
611
 
612
                  for (idx2=0; idx2<bitSymbol;idx2++){
613
                     bidon [idx2] = 0;
614
                  }
615
                  for (idx1=0; idx1<mmTabSize;idx1++){
616
                       tempNum = PrefTab [Pidx*mmTabSize+idx1];
617
                     if (tempNum == 1) {
618
                        //------------------------------------------------------------------------
619
                        // search
620
                        //------------------------------------------------------------------------
621
                        for (idx2=0; idx2<bitSymbol;idx2++){
622
                           tempNum = MrefTab[idx1*bitSymbol+idx2];
623
                           if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
624
                              if  (bidon [idx2] == 0) {
625
                                 bidon [idx2] = 1;
626
                              }
627
                              else {
628
                                 bidon [idx2] = 0;
629
                              }
630
                           }
631
                        }
632
                     }
633
                  }
634
                  //------------------------------------------------------------------------
635
                  // printf
636
                  //------------------------------------------------------------------------
637
                  for (idx2=0; idx2<bitSymbol; idx2++){
638
                     if (bidon[idx2] == 1) {
639
                        if (init == 0) {
640
                           fprintf(OutFileDecodeChien, " lambdaIn_%d[%d]", zz,idx2);
641
                           init = 1;
642
                        }
643
                        else {
644
                           fprintf(OutFileDecodeChien, " ^ lambdaIn_%d[%d]", zz,idx2);
645
                        }
646
                     }
647
                  }
648
                  fprintf(OutFileDecodeChien, ";\n");
649
               }
650
            }
651
         }
652
      }
653
   }
654
   fprintf(OutFileDecodeChien, "\n\n\n");
655
 
656
 
657
   //------------------------------------------------------------------------
658
   //- LAMBDA_NEW = CHIEN_COEFF_LN * LAMBDA_REG
659
   //------------------------------------------------------------------------
660
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
661
   fprintf(OutFileDecodeChien, "   //- lambdaNew\n");
662
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
663
//   for (ii=0;ii<syndromeLength;ii++){
664
   for (ii=0;ii<lambdaPointer;ii++){
665
      fprintf(OutFileDecodeChien, "   reg  [%d:0]   lambdaReg_%d;\n",bitSymbol-1, ii);
666
   }
667
 
668
 
669
//   for (ii=0;ii<syndromeLength;ii++){
670
   for (ii=0;ii<lambdaPointer;ii++){
671
      fprintf(OutFileDecodeChien, "   wire [%d:0]   lambdaUp_%d;\n",bitSymbol-1,ii);
672
   }
673
   fprintf(OutFileDecodeChien, "\n\n");
674
 
675
 
676
//   for (zz=0;zz<syndromeLength;zz++){
677
   for (zz=0;zz<lambdaPointer;zz++){
678
      if (zz ==0) {
679
         for (kk=0;kk<bitSymbol;kk++){
680
            fprintf(OutFileDecodeChien, "   assign lambdaUp_%d [%d] = lambdaReg_%d[%d];\n", zz, kk, zz, kk);
681
         }
682
      }else{
683
         //------------------------------------------------------------------------
684
         //- ttTab initialize
685
         //------------------------------------------------------------------------
686
         ttTab[0] = 1;
687
         for (kk=1;kk<bitSymbol;kk++){
688
            ttTab[kk] = 0;
689
         }
690
 
691
 
692
         //------------------------------------------------------------------------
693
         //- bbTab initialize
694
         //------------------------------------------------------------------------
695
         bbTab[0] = 0;
696
         bbTab[1] = 1;
697
         for (kk=2;kk<bitSymbol;kk++){
698
            bbTab[kk] = 0;
699
         }
700
 
701
 
702
         for(ii=1; ii<(zz+1); ii++){
703
            //------------------------------------------------------------------------
704
            //- ppTab = ttTab * bbTab
705
            //------------------------------------------------------------------------
706
            RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
707
 
708
            //------------------------------------------------------------------------
709
            // reassign ttTab
710
            //------------------------------------------------------------------------
711
            for (kk=0;kk<bitSymbol;kk++){
712
               ttTab[kk]        = ppTab[kk];
713
            }
714
 
715
            //------------------------------------------------------------------------
716
            // write P_OUT[0]
717
            //------------------------------------------------------------------------
718
            if (ii==zz) {
719
               for (Pidx=0; Pidx<bitSymbol; Pidx++){
720
                  fprintf(OutFileDecodeChien, "   assign lambdaUp_%d [%d] =", zz,Pidx);
721
                  init = 0;
722
 
723
                  for (idx2=0; idx2<bitSymbol;idx2++){
724
                     bidon [idx2] = 0;
725
                  }
726
                  for (idx1=0; idx1<mmTabSize;idx1++){
727
                     tempNum = PrefTab [Pidx*mmTabSize+idx1];
728
                     if (tempNum == 1) {
729
                        //------------------------------------------------------------------------
730
                        // search
731
                        //------------------------------------------------------------------------
732
                        for (idx2=0; idx2<bitSymbol;idx2++){
733
                           tempNum = MrefTab[idx1*bitSymbol+idx2];
734
                           if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
735
                              if  (bidon [idx2] == 0) {
736
                                 bidon [idx2] = 1;
737
                              }
738
                              else {
739
                                 bidon [idx2] = 0;
740
                              }
741
                           }
742
                        }
743
                     }
744
                  }
745
                  //------------------------------------------------------------------------
746
                  // printf
747
                  //------------------------------------------------------------------------
748
                  for (idx2=0; idx2<bitSymbol; idx2++){
749
                     if (bidon[idx2] == 1) {
750
                        if (init == 0) {
751
                           fprintf(OutFileDecodeChien, " lambdaReg_%d[%d]", zz,idx2);
752
                           init = 1;
753
                        }
754
                        else {
755
                           fprintf(OutFileDecodeChien, " ^ lambdaReg_%d[%d]", zz,idx2);
756
                        }
757
                     }
758
                  }
759
                  fprintf(OutFileDecodeChien, ";\n");
760
               }
761
            }
762
         }
763
      }
764
   }
765
   fprintf(OutFileDecodeChien, "\n\n\n");
766
 
767
 
768
   //------------------------------------------------------------------------
769
   // + lambdaReg_0,...,lambdaReg_
770
   //- registers
771
   //------------------------------------------------------------------------
772
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
773
   fprintf(OutFileDecodeChien, "   // + lambdaReg_0,...,lambdaReg_%d\n", lambdaPointer-1);
774
   fprintf(OutFileDecodeChien, "   //- registers\n");
775
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
776
   fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
777
   fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
778
 
779
//   for (ii=0;ii<syndromeLength;ii++){
780
   for (ii=0;ii<lambdaPointer;ii++){
781
      if (ii < 10){
782
         fprintf(OutFileDecodeChien, "         lambdaReg_%d [%d:0]  <= %d'd0;\n",ii, bitSymbol-1,bitSymbol);
783
      }else{
784
         fprintf(OutFileDecodeChien, "         lambdaReg_%d [%d:0] <=  %d'd0;\n",ii,bitSymbol-1,bitSymbol);
785
      }
786
   }
787
 
788
   fprintf(OutFileDecodeChien, "      end\n");
789
   fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
790
   fprintf(OutFileDecodeChien, "         if (sync == 1'b1) begin\n");
791
 
792
//   for (ii=0;ii<syndromeLength;ii++){
793
   for (ii=0;ii<lambdaPointer;ii++){
794
      if (ii < 10){
795
         fprintf(OutFileDecodeChien, "            lambdaReg_%d [%d:0]  <= lambdaIni_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
796
      }else{
797
         fprintf(OutFileDecodeChien, "            lambdaReg_%d [%d:0] <= lambdaIni_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
798
      }
799
   }
800
 
801
   fprintf(OutFileDecodeChien, "        end\n");
802
   fprintf(OutFileDecodeChien, "        else begin\n");
803
 
804
//   for (ii=0;ii<syndromeLength;ii++){
805
   for (ii=0;ii<lambdaPointer;ii++){
806
      if (ii < 10){
807
         fprintf(OutFileDecodeChien, "           lambdaReg_%d [%d:0]  <= lambdaUp_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
808
      }else{
809
         fprintf(OutFileDecodeChien, "           lambdaReg_%d [%d:0] <= lambdaUp_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
810
      }
811
   }
812
 
813
   fprintf(OutFileDecodeChien, "         end\n");
814
   fprintf(OutFileDecodeChien, "      end\n");
815
   fprintf(OutFileDecodeChien, "   end\n");
816
   fprintf(OutFileDecodeChien, "\n\n\n");
817
 
818
 
819
 
820
   //------------------------------------------------------------------------
821
   //- OMEGA_INI = CHIEN_COEFF_OI * OMEGA_IN
822
   //------------------------------------------------------------------------
823
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
824
   fprintf(OutFileDecodeChien, "   //- omegaIni\n");
825
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
826
 
827
//   for (ii=0;ii<syndromeLength;ii++){
828
   for (ii=0;ii<omegaPointer;ii++){
829
      fprintf(OutFileDecodeChien, "   wire [%d:0]  omegaIni_%d;\n",bitSymbol-1,ii);
830
   }
831
   fprintf(OutFileDecodeChien, "\n\n");
832
 
833
//   for (zz=0;zz<syndromeLength;zz++){
834
   for (zz=0;zz<omegaPointer;zz++){
835
      if (coeffTab[zz] ==0) {
836
         for (kk=0;kk<bitSymbol;kk++){
837
            fprintf(OutFileDecodeChien, "   assign omegaIni_%d [%d] = omegaIn_%d[%d];\n", zz, kk,zz, kk);
838
         }
839
      }else{
840
         //------------------------------------------------------------------------
841
         //- ttTab initialize
842
         //------------------------------------------------------------------------
843
         ttTab[0] = 1;
844
         for (kk=1;kk<bitSymbol;kk++){
845
            ttTab[kk] = 0;
846
         }
847
 
848
         //------------------------------------------------------------------------
849
         //- bbTab initialize
850
         //------------------------------------------------------------------------
851
         bbTab[0] = 0;
852
         bbTab[1] = 1;
853
         for (kk=2;kk<bitSymbol;kk++){
854
            bbTab[kk] = 0;
855
         }
856
 
857
         //------------------------------------------------------------------------
858
         //------------------------------------------------------------------------
859
         for(ii=1; ii<(coeffTab[zz]+1); ii++){
860
 
861
            //------------------------------------------------------------------------
862
            //- ppTab = ttTab * bbTab
863
            //------------------------------------------------------------------------
864
            RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
865
 
866
            //------------------------------------------------------------------------
867
            // reassign ttTab
868
            //------------------------------------------------------------------------
869
            for (kk=0;kk<bitSymbol;kk++){
870
               ttTab[kk]        = ppTab[kk];
871
            }
872
 
873
 
874
            //------------------------------------------------------------------------
875
            // write P_OUT[0]
876
            //------------------------------------------------------------------------
877
            if (ii==coeffTab[zz]) {
878
               for (Pidx=0; Pidx<bitSymbol; Pidx++){
879
                  fprintf(OutFileDecodeChien, "   assign omegaIni_%d [%d] =", zz,Pidx);
880
                  init = 0;
881
 
882
                  for (idx2=0; idx2<bitSymbol;idx2++){
883
                     bidon [idx2] = 0;
884
                  }
885
 
886
                  for (idx1=0; idx1<mmTabSize;idx1++){
887
                     tempNum = PrefTab [Pidx*mmTabSize+idx1];
888
                     if (tempNum == 1) {
889
                        //------------------------------------------------------------------------
890
                        // search
891
                        //------------------------------------------------------------------------
892
                        for (idx2=0; idx2<bitSymbol;idx2++){
893
                           tempNum = MrefTab[idx1*bitSymbol+idx2];
894
                           if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
895
                              if  (bidon [idx2] == 0) {
896
                                 bidon [idx2] = 1;
897
                              }
898
                              else {
899
                                 bidon [idx2] = 0;
900
                              }
901
                           }
902
                        }
903
                     }
904
                  }
905
                  //------------------------------------------------------------------------
906
                  // printf
907
                  //------------------------------------------------------------------------
908
                  for (idx2=0; idx2<bitSymbol; idx2++){
909
                     if (bidon[idx2] == 1) {
910
                        if (init == 0) {
911
                           fprintf(OutFileDecodeChien, " omegaIn_%d[%d]", zz,idx2);
912
                           init = 1;
913
                        }
914
                        else {
915
                           fprintf(OutFileDecodeChien, " ^ omegaIn_%d[%d]", zz,idx2);
916
                        }
917
                     }
918
                  }
919
                  fprintf(OutFileDecodeChien, ";\n");
920
               }
921
            }
922
         }
923
      }
924
   }
925
   fprintf(OutFileDecodeChien, "\n\n\n");
926
 
927
 
928
   //------------------------------------------------------------------------
929
   //- OMEGA_NEW = CHIEN_COEFF_ON * OMEGA_REG
930
   //------------------------------------------------------------------------
931
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
932
   fprintf(OutFileDecodeChien, "   //- omegaNew\n");
933
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
934
 
935
//   for (ii=0;ii<syndromeLength;ii++){
936
   for (ii=0;ii<omegaPointer;ii++){
937
      fprintf(OutFileDecodeChien, "   reg [%d:0]  omegaReg_%d;\n", bitSymbol -1,ii);
938
   }
939
//   for (ii=0;ii<syndromeLength;ii++){
940
   for (ii=0;ii<omegaPointer;ii++){
941
      fprintf(OutFileDecodeChien, "   wire [%d:0]  omegaNew_%d;\n", bitSymbol -1,ii);
942
   }
943
   fprintf(OutFileDecodeChien, "\n\n");
944
//   for (zz=0;zz<syndromeLength;zz++){
945
   for (zz=0;zz<omegaPointer;zz++){
946
      if (zz ==0) {
947
         for (kk=0;kk<bitSymbol;kk++){
948
            fprintf(OutFileDecodeChien, "   assign omegaNew_%d [%d] = omegaReg_%d[%d];\n", zz, kk, zz, kk);
949
         }
950
      }else{
951
         //------------------------------------------------------------------------
952
         // initialize ttTab
953
         //------------------------------------------------------------------------
954
         ttTab[0] = 1;
955
         for (kk=1;kk<bitSymbol;kk++){
956
            ttTab[kk] = 0;
957
         }
958
 
959
         //------------------------------------------------------------------------
960
         // initialize bbTab
961
         //------------------------------------------------------------------------
962
         bbTab[0] = 0;
963
         bbTab[1] = 1;
964
         for (kk=2;kk<bitSymbol;kk++){
965
            bbTab[kk] = 0;
966
         }
967
 
968
 
969
         //------------------------------------------------------------------------
970
         //------------------------------------------------------------------------
971
         for(ii=1; ii<(zz+1); ii++){
972
 
973
            //------------------------------------------------------------------------
974
            //- ppTab = ttTab * bbTab
975
            //------------------------------------------------------------------------
976
            RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
977
 
978
            //------------------------------------------------------------------------
979
            //- reassign ttTab
980
            //------------------------------------------------------------------------
981
            for (kk=0;kk<bitSymbol;kk++){
982
               ttTab[kk]        = ppTab[kk];
983
            }
984
 
985
 
986
            //------------------------------------------------------------------------
987
            // write P_OUT[0]
988
            //------------------------------------------------------------------------
989
            if (ii==zz) {
990
               for (Pidx=0; Pidx<bitSymbol; Pidx++){
991
                  fprintf(OutFileDecodeChien, "   assign omegaNew_%d [%d] =", zz,Pidx);
992
                  init = 0;
993
 
994
                  for (idx2=0; idx2<bitSymbol;idx2++){
995
                     bidon [idx2] = 0;
996
                  }
997
                  for (idx1=0; idx1<mmTabSize;idx1++){
998
                     tempNum = PrefTab [Pidx*mmTabSize+idx1];
999
                     if (tempNum == 1) {
1000
                        //------------------------------------------------------------------------
1001
                        // search
1002
                        //------------------------------------------------------------------------
1003
                        for (idx2=0; idx2<bitSymbol;idx2++){
1004
                           tempNum = MrefTab[idx1*bitSymbol+idx2];
1005
                           if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
1006
                              if  (bidon [idx2] == 0) {
1007
                                 bidon [idx2] = 1;
1008
                              }
1009
                              else {
1010
                                 bidon [idx2] = 0;
1011
                              }
1012
                           }
1013
                        }
1014
                     }
1015
                  }
1016
                  //------------------------------------------------------------------------
1017
                  // printf
1018
                  //------------------------------------------------------------------------
1019
                  for (idx2=0; idx2<bitSymbol; idx2++){
1020
                     if (bidon[idx2] == 1) {
1021
                        if (init == 0) {
1022
                           fprintf(OutFileDecodeChien, " omegaReg_%d[%d]", zz,idx2);
1023
                           init = 1;
1024
                        }
1025
                        else {
1026
                           fprintf(OutFileDecodeChien, " ^ omegaReg_%d[%d]", zz,idx2);
1027
                        }
1028
                     }
1029
                  }
1030
                  fprintf(OutFileDecodeChien, ";\n");
1031
               }
1032
            }
1033
         }
1034
      }
1035
   }
1036
   fprintf(OutFileDecodeChien, "\n\n\n");
1037
 
1038
 
1039
 
1040
   //------------------------------------------------------------------
1041
   // + omegaReg_0,..., omegaReg_19
1042
   //- registers
1043
   //------------------------------------------------------------------
1044
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1045
   fprintf(OutFileDecodeChien, "   // + omegaReg_0,..., omegaReg_%d\n", omegaPointer-1);
1046
   fprintf(OutFileDecodeChien, "   //- registers\n");
1047
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1048
   fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
1049
   fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
1050
//   for (ii=0;ii<syndromeLength;ii++){
1051
   for (ii=0;ii<omegaPointer;ii++){
1052
      if (ii < 10) {
1053
         fprintf(OutFileDecodeChien, "         omegaReg_%d [%d:0]  <= %d'd0;\n",ii, bitSymbol-1, bitSymbol);
1054
      }else{
1055
         fprintf(OutFileDecodeChien, "         omegaReg_%d [%d:0] <= %d'd0;\n",ii, bitSymbol-1, bitSymbol);
1056
      }
1057
   }
1058
 
1059
   fprintf(OutFileDecodeChien, "      end\n");
1060
   fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
1061
   fprintf(OutFileDecodeChien, "         if (sync == 1'b1) begin\n");
1062
 
1063
 
1064
//   for (ii=0;ii<syndromeLength;ii++){
1065
   for (ii=0;ii<omegaPointer;ii++){
1066
      if (ii < 10) {
1067
         fprintf(OutFileDecodeChien, "            omegaReg_%d [%d:0]  <= omegaIni_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1068
      }else{
1069
         fprintf(OutFileDecodeChien, "            omegaReg_%d [%d:0] <= omegaIni_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1070
      }
1071
   }
1072
 
1073
   fprintf(OutFileDecodeChien, "         end\n");
1074
   fprintf(OutFileDecodeChien, "         else begin\n");
1075
 
1076
//   for (ii=0;ii<syndromeLength;ii++){
1077
   for (ii=0;ii<omegaPointer;ii++){
1078
      if (ii < 10){
1079
         fprintf(OutFileDecodeChien, "            omegaReg_%d [%d:0]  <= omegaNew_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1080
      }else{
1081
         fprintf(OutFileDecodeChien, "            omegaReg_%d [%d:0] <= omegaNew_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1082
      }
1083
   }
1084
   fprintf(OutFileDecodeChien, "         end\n");
1085
   fprintf(OutFileDecodeChien, "      end\n");
1086
   fprintf(OutFileDecodeChien, "   end\n");
1087
   fprintf(OutFileDecodeChien, "\n\n\n");
1088
 
1089
 
1090
   //------------------------------------------------------------------------
1091
   //- EPSILON_INI = CHIEN_COEFF_EI * EPSILON_IN
1092
   //------------------------------------------------------------------------
1093
   if (ErasureOption == 1) {
1094
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1095
      fprintf(OutFileDecodeChien, "   //- epsilonIni\n");
1096
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1097
      for (ii=0;ii<(syndromeLength+1);ii++){
1098
         fprintf(OutFileDecodeChien, "   wire [%d:0]  epsilonIni_%d;\n", bitSymbol-1,ii);
1099
      }
1100
      fprintf(OutFileDecodeChien, "\n\n");
1101
      for (zz=0;zz<(syndromeLength+1);zz++){
1102
         if (coeffTab[zz] ==0) {
1103
            for (kk=0;kk<bitSymbol;kk++){
1104
               fprintf(OutFileDecodeChien, "   assign epsilonIni_%d [%d] = epsilonIn_%d[%d];\n", zz, kk, zz, kk);
1105
            }
1106
         }else{
1107
            //------------------------------------------------------------------------
1108
            //- initialize ttTab
1109
            //------------------------------------------------------------------------
1110
            ttTab[0] = 1;
1111
            for (kk=1;kk<bitSymbol;kk++){
1112
               ttTab[kk] = 0;
1113
            }
1114
 
1115
 
1116
            //------------------------------------------------------------------------
1117
            //- initialize bbTab
1118
            //------------------------------------------------------------------------
1119
            bbTab[0] = 0;
1120
            bbTab[1] = 1;
1121
            for (kk=2;kk<bitSymbol;kk++){
1122
               bbTab[kk] = 0;
1123
            }
1124
 
1125
 
1126
            //------------------------------------------------------------------------
1127
            //------------------------------------------------------------------------
1128
            for(ii=1; ii<(coeffTab[zz]+1); ii++){
1129
               //------------------------------------------------------------------------
1130
               //- ppTab = ttTab * bbTab
1131
               //------------------------------------------------------------------------
1132
               RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
1133
 
1134
 
1135
               //------------------------------------------------------------------------
1136
               // reassign ttTab = ppTab
1137
               //------------------------------------------------------------------------
1138
               for (kk=0;kk<bitSymbol;kk++){
1139
                  ttTab[kk]     = ppTab[kk];
1140
               }
1141
 
1142
 
1143
               //------------------------------------------------------------------------
1144
               // write P_OUT[0]
1145
               //------------------------------------------------------------------------
1146
               if (ii==coeffTab[zz]) {
1147
                  for (Pidx=0; Pidx<bitSymbol; Pidx++){
1148
                     fprintf(OutFileDecodeChien, "   assign epsilonIni_%d [%d] =", zz,Pidx);
1149
                     init = 0;
1150
 
1151
                     for (idx2=0; idx2<bitSymbol;idx2++){
1152
                        bidon [idx2] = 0;
1153
                     }
1154
                     for (idx1=0; idx1<mmTabSize;idx1++){
1155
                        tempNum = PrefTab [Pidx*mmTabSize+idx1];
1156
                        if (tempNum == 1) {
1157
                           //------------------------------------------------------------------------
1158
                           // search
1159
                           //------------------------------------------------------------------------
1160
                           for (idx2=0; idx2<bitSymbol;idx2++){
1161
                              tempNum = MrefTab[idx1*bitSymbol+idx2];
1162
                              if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
1163
                                 if  (bidon [idx2] == 0) {
1164
                                    bidon [idx2] = 1;
1165
                                 }else{
1166
                                    bidon [idx2] = 0;
1167
                                 }
1168
                              }
1169
                           }
1170
                        }
1171
                     }
1172
                     //------------------------------------------------------------------------
1173
                     // printf
1174
                     //------------------------------------------------------------------------
1175
                     for (idx2=0; idx2<bitSymbol; idx2++){
1176
                        if (bidon[idx2] == 1) {
1177
                           if (init == 0) {
1178
                              fprintf(OutFileDecodeChien, " epsilonIn_%d[%d]", zz,idx2);
1179
                              init = 1;
1180
                           }else{
1181
                              fprintf(OutFileDecodeChien, " ^ epsilonIn_%d[%d]", zz,idx2);
1182
                           }
1183
                        }
1184
                     }
1185
                     fprintf(OutFileDecodeChien, ";\n");
1186
                  }
1187
               }
1188
            }
1189
         }
1190
      }
1191
      fprintf(OutFileDecodeChien, "\n\n\n");
1192
   }
1193
 
1194
 
1195
   //------------------------------------------------------------------------
1196
   //- EPSILON_NEW = CHIEN_COEFF_EN * EPSILON_REG
1197
   //------------------------------------------------------------------------
1198
   if (ErasureOption == 1) {
1199
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1200
      fprintf(OutFileDecodeChien, "   //- epsilonNew\n");
1201
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1202
      for (ii=0; ii<(syndromeLength+1);ii++){
1203
        fprintf(OutFileDecodeChien, "   reg  [%d:0]  epsilonReg_%d;\n", bitSymbol-1,ii);
1204
      }
1205
      for (ii=0;ii<(syndromeLength+1);ii++){
1206
         fprintf(OutFileDecodeChien, "   wire [%d:0]  epsilonNew_%d;\n", bitSymbol-1, ii);
1207
      }
1208
      fprintf(OutFileDecodeChien, "\n\n");
1209
      for (zz=0;zz<(syndromeLength+1);zz++){
1210
         if (zz ==0) {
1211
            for (kk=0;kk<bitSymbol;kk++){
1212
               fprintf(OutFileDecodeChien, "   assign epsilonNew_%d [%d] = epsilonReg_%d[%d];\n", zz, kk, zz, kk);
1213
            }
1214
         }else{
1215
            //------------------------------------------------------------------------
1216
            // initialize ttTab
1217
            //------------------------------------------------------------------------
1218
            ttTab[0] = 1;
1219
            for (kk=1;kk<bitSymbol;kk++){
1220
               ttTab[kk] = 0;
1221
            }
1222
 
1223
            //------------------------------------------------------------------------
1224
            // initialize bbTab
1225
            //------------------------------------------------------------------------
1226
            bbTab[0] = 0;
1227
            bbTab[1] = 1;
1228
            for (kk=2;kk<bitSymbol;kk++){
1229
               bbTab[kk] = 0;
1230
            }
1231
 
1232
            //------------------------------------------------------------------------
1233
            //------------------------------------------------------------------------
1234
            for(ii=1; ii<(zz+1); ii++){
1235
 
1236
               //------------------------------------------------------------------------
1237
               //- ppTab = ttTab * bbTab
1238
               //------------------------------------------------------------------------
1239
               RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
1240
 
1241
               //------------------------------------------------------------------------
1242
               // reassign ttTab
1243
               //------------------------------------------------------------------------
1244
               for (kk=0;kk<bitSymbol;kk++){
1245
                  ttTab[kk]     = ppTab[kk];
1246
               }
1247
 
1248
 
1249
               //------------------------------------------------------------------------
1250
               // write P_OUT[0]
1251
               //------------------------------------------------------------------------
1252
               if (ii==zz) {
1253
                  for (Pidx=0; Pidx<bitSymbol; Pidx++){
1254
                     fprintf(OutFileDecodeChien, "   assign epsilonNew_%d [%d] =", zz,Pidx);
1255
                     init = 0;
1256
 
1257
                     for (idx2=0; idx2<bitSymbol;idx2++){
1258
                        bidon [idx2] = 0;
1259
                     }
1260
                     for (idx1=0; idx1<mmTabSize;idx1++){
1261
                        tempNum = PrefTab [Pidx*mmTabSize+idx1];
1262
                        if (tempNum == 1) {
1263
                           //------------------------------------------------------------------------
1264
                           // search
1265
                           //------------------------------------------------------------------------
1266
                           for (idx2=0; idx2<bitSymbol;idx2++){
1267
                              tempNum = MrefTab[idx1*bitSymbol+idx2];
1268
                              if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
1269
                                 if  (bidon [idx2] == 0) {
1270
                                    bidon [idx2] = 1;
1271
                                 }else{
1272
                                    bidon [idx2] = 0;
1273
                                 }
1274
                              }
1275
                           }
1276
                        }
1277
                     }
1278
                     //------------------------------------------------------------------------
1279
                     // printf
1280
                     //------------------------------------------------------------------------
1281
                     for (idx2=0; idx2<bitSymbol; idx2++){
1282
                        if (bidon[idx2] == 1) {
1283
                           if (init == 0) {
1284
                              fprintf(OutFileDecodeChien, " epsilonReg_%d[%d]", zz,idx2);
1285
                              init = 1;
1286
                           }else{
1287
                              fprintf(OutFileDecodeChien, " ^ epsilonReg_%d[%d]", zz,idx2);
1288
                           }
1289
                        }
1290
                     }
1291
                     fprintf(OutFileDecodeChien, ";\n");
1292
                  }
1293
               }
1294
            }
1295
         }
1296
      }
1297
      fprintf(OutFileDecodeChien, "\n\n\n");
1298
   }
1299
 
1300
 
1301
   //------------------------------------------------------------------
1302
   // + epsilonReg_0,..., epsilonReg_20
1303
   //- registers
1304
   //------------------------------------------------------------------
1305
   if (ErasureOption == 1) {
1306
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1307
      fprintf(OutFileDecodeChien, "   // + epsilonReg_0,..., epsilonReg_%d\n", syndromeLength);
1308
      fprintf(OutFileDecodeChien, "   //- registers\n");
1309
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1310
      fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
1311
      fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
1312
      for (ii=0;ii<(syndromeLength+1);ii++){
1313
         if (ii<10){
1314
            fprintf(OutFileDecodeChien, "         epsilonReg_%d [%d:0]  <= %d'd0;\n",ii, bitSymbol-1,bitSymbol);
1315
         }else{
1316
            fprintf(OutFileDecodeChien, "         epsilonReg_%d [%d:0] <= %d'd0;\n",ii, bitSymbol-1,bitSymbol);
1317
         }
1318
      }
1319
 
1320
      fprintf(OutFileDecodeChien, "      end\n");
1321
      fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
1322
      fprintf(OutFileDecodeChien, "         if (sync == 1'b1) begin\n");
1323
      for (ii=0;ii<(syndromeLength+1);ii++){
1324
         if (ii<10){
1325
            fprintf(OutFileDecodeChien, "            epsilonReg_%d [%d:0]  <= epsilonIni_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1326
         }else{
1327
            fprintf(OutFileDecodeChien, "            epsilonReg_%d [%d:0] <= epsilonIni_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1328
         }
1329
      }
1330
 
1331
      fprintf(OutFileDecodeChien, "         end\n");
1332
      fprintf(OutFileDecodeChien, "         else begin\n");
1333
 
1334
      for (ii=0;ii<(syndromeLength+1);ii++){
1335
         if (ii<10) {
1336
            fprintf(OutFileDecodeChien, "            epsilonReg_%d [%d:0]  <= epsilonNew_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1337
         }else{
1338
            fprintf(OutFileDecodeChien, "            epsilonReg_%d [%d:0] <= epsilonNew_%d [%d:0];\n",ii, bitSymbol-1,ii, bitSymbol-1);
1339
         }
1340
      }
1341
 
1342
      fprintf(OutFileDecodeChien, "         end\n");
1343
      fprintf(OutFileDecodeChien, "      end\n");
1344
      fprintf(OutFileDecodeChien, "   end\n");
1345
      fprintf(OutFileDecodeChien, "\n\n\n");
1346
   }
1347
 
1348
 
1349
   //------------------------------------------------------------------------
1350
   // Generate Error Pattern: Lambda
1351
   //------------------------------------------------------------------------
1352
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1353
   fprintf(OutFileDecodeChien, "   // Generate Error Pattern: Lambda\n");
1354
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1355
 
1356
   fprintf(OutFileDecodeChien, "   always @( lambdaReg_0");
1357
 
1358
//   for (ii=1;ii<syndromeLength;ii++){
1359
   for (ii=1;ii<lambdaPointer;ii++){
1360
      fprintf(OutFileDecodeChien, "   or lambdaReg_%d", ii);
1361
   }
1362
   fprintf(OutFileDecodeChien, " ) begin\n");
1363
 
1364
   if (ErasureOption == 1){
1365
      fprintf(OutFileDecodeChien, "      lambdaSum [%d:0] = lambdaReg_0[%d:0]", bitSymbol-1, bitSymbol-1);
1366
      for (ii=1;ii<syndromeLength;ii++){
1367
         fprintf(OutFileDecodeChien, "   ^ lambdaReg_%d[%d:0]",ii, bitSymbol-1);
1368
      }
1369
      fprintf(OutFileDecodeChien, ";\n");
1370
   }
1371
 
1372
 
1373
   fprintf(OutFileDecodeChien, "      lambdaEven [%d:0] = lambdaReg_0[%d:0]", bitSymbol-1, bitSymbol-1);
1374
//   for (ii=2;ii<(syndromeLength-1);ii=ii+2){
1375
 
1376
   if (ErasureOption == 1){
1377
      for (ii=2;ii<(syndromeLength-1);ii=ii+2){
1378
         fprintf(OutFileDecodeChien, "   ^ lambdaReg_%d[%d:0]",ii, bitSymbol-1);
1379
      }
1380
   }else{
1381
      for (ii=2;ii<(lambdaPointer+1);ii=ii+2){
1382
         if (ii < lambdaPointer) {
1383
            fprintf(OutFileDecodeChien, "   ^ lambdaReg_%d[%d:0]",ii, bitSymbol-1);
1384
         }
1385
      }
1386
   }
1387
 
1388
 
1389
 
1390
   fprintf(OutFileDecodeChien, ";\n");
1391
 
1392
 
1393
   fprintf(OutFileDecodeChien, "      lambdaOdd [%d:0] =  lambdaReg_1[%d:0]", bitSymbol-1, bitSymbol-1);
1394
//   for (ii=3;ii<(syndromeLength);ii=ii+2){
1395
   for (ii=3;ii<(lambdaPointer);ii=ii+2){
1396
      fprintf(OutFileDecodeChien, "   ^ lambdaReg_%d[%d:0]",ii, bitSymbol-1);
1397
   }
1398
   fprintf(OutFileDecodeChien, ";\n");
1399
   fprintf(OutFileDecodeChien, "   end\n");
1400
   fprintf(OutFileDecodeChien, "\n\n\n");
1401
 
1402
 
1403
   //------------------------------------------------------------------------
1404
   // Generate Error Pattern: Omega
1405
   //------------------------------------------------------------------------
1406
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1407
   fprintf(OutFileDecodeChien, "   // Generate Error Pattern: Omega\n");
1408
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1409
 
1410
   fprintf(OutFileDecodeChien, "   always @( omegaReg_0");
1411
//   for (ii=1;ii<syndromeLength;ii++){
1412
   for (ii=1;ii<omegaPointer;ii++){
1413
      fprintf(OutFileDecodeChien, "   or omegaReg_%d", ii);
1414
   }
1415
 
1416
   fprintf(OutFileDecodeChien, " ) begin\n");
1417
   fprintf(OutFileDecodeChien, "      omegaSum [%d:0] = omegaReg_0[%d:0]", bitSymbol-1, bitSymbol-1);
1418
 
1419
//   for (ii=1;ii<syndromeLength;ii++){
1420
   for (ii=1;ii<omegaPointer;ii++){
1421
      fprintf(OutFileDecodeChien, "   ^ omegaReg_%d[%d:0]", ii, bitSymbol-1);
1422
   }
1423
 
1424
   fprintf(OutFileDecodeChien, ";\n");
1425
   fprintf(OutFileDecodeChien, "   end\n");
1426
   fprintf(OutFileDecodeChien, "\n\n\n");
1427
 
1428
 
1429
   //------------------------------------------------------------------------
1430
   // Generate Error Pattern: Epsilon
1431
   //------------------------------------------------------------------------
1432
   if (ErasureOption == 1) {
1433
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1434
      fprintf(OutFileDecodeChien, "   //- Generate Error Pattern: Epsilon\n");
1435
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1436
      fprintf(OutFileDecodeChien, "   always @( epsilonReg_0");
1437
      for (ii=1;ii<(syndromeLength+1);ii++){
1438
         fprintf(OutFileDecodeChien, "   or epsilonReg_%d", ii);
1439
      }
1440
      fprintf(OutFileDecodeChien, " ) begin\n");
1441
      fprintf(OutFileDecodeChien, "      epsilonSum [%d:0] = epsilonReg_0[%d:0]", bitSymbol-1, bitSymbol-1);
1442
      for (ii=1;ii<(syndromeLength+1);ii++){
1443
         fprintf(OutFileDecodeChien, "   ^ epsilonReg_%d[%d:0]", ii, bitSymbol-1);
1444
      }
1445
      fprintf(OutFileDecodeChien, ";\n");
1446
      fprintf(OutFileDecodeChien, "      epsilonOdd [%d:0] =  epsilonReg_1[%d:0]", bitSymbol-1, bitSymbol-1);
1447
      for (ii=3;ii<syndromeLength;ii=ii+2){
1448
         fprintf(OutFileDecodeChien, "   ^ epsilonReg_%d[%d:0]",ii, bitSymbol-1);
1449
      }
1450
      fprintf(OutFileDecodeChien, ";\n");
1451
      fprintf(OutFileDecodeChien, "   end\n");
1452
      fprintf(OutFileDecodeChien, "\n\n\n");
1453
   }
1454
 
1455
 
1456
   //------------------------------------------------------------------------
1457
   // RsDecodeMult instantiation
1458
   //------------------------------------------------------------------------
1459
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1460
   fprintf(OutFileDecodeChien, "   //- RsDecodeMult instantiation, RsDecodeMult_MuldE0 && RsDecodeMult_MuldE1\n");
1461
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1462
   if (ErasureOption == 1){
1463
      fprintf(OutFileDecodeChien, "   RsDecodeMult RsDecodeMult_MuldE0 (.A(lambdaOddReg[%d:0]), .B(epsilonSumReg[%d:0]), .P(denomE0[%d:0]));\n", bitSymbol-1, bitSymbol-1, bitSymbol-1);
1464
   }else{
1465
      fprintf(OutFileDecodeChien, "   assign denomE0[%d:0] = lambdaOddReg[%d:0];\n", bitSymbol-1, bitSymbol-1);
1466
   }
1467
 
1468
   if (ErasureOption == 1){
1469
      fprintf(OutFileDecodeChien, "   RsDecodeMult RsDecodeMult_MuldE1 (.A(lambdaSumReg[%d:0]), .B(epsilonOddReg[%d:0]), .P(denomE1[%d:0]));\n", bitSymbol-1, bitSymbol-1, bitSymbol-1);
1470
   }
1471
 
1472
   fprintf(OutFileDecodeChien, "\n\n");
1473
 
1474
 
1475
   //------------------------------------------------------------------------
1476
   // RsDecodeInv instantiation
1477
   //------------------------------------------------------------------------
1478
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1479
   fprintf(OutFileDecodeChien, "   //- RsDecodeInv instantiation, RsDecodeInv_InvE0 && RsDecodeInv_InvE1\n");
1480
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1481
   fprintf(OutFileDecodeChien, "   RsDecodeInv RsDecodeInv_InvE0 (.B(denomE0Reg[%d:0]), .R(denomE0Inv[%d:0]));\n", bitSymbol-1, bitSymbol-1);
1482
   if (ErasureOption == 1){
1483
      fprintf(OutFileDecodeChien, "   RsDecodeInv RsDecodeInv_InvE1 (.B(denomE1Reg[%d:0]), .R(denomE1Inv[%d:0]));\n", bitSymbol-1, bitSymbol-1);
1484
   }
1485
 
1486
   fprintf(OutFileDecodeChien, "\n\n");
1487
 
1488
 
1489
   //------------------------------------------------------------------------
1490
   // RsDecodeMult instantiation
1491
   //------------------------------------------------------------------------
1492
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1493
   fprintf(OutFileDecodeChien, "   //- RsDecodeMult instantiation, RsDecodeMult_MulE0 && RsDecodeMult_MulE1 \n");
1494
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1495
   fprintf(OutFileDecodeChien, "   RsDecodeMult RsDecodeMult_MulE0 (.A(numeReg2[%d:0]), .B(denomE0InvReg[%d:0]), .P(errorValueE0[%d:0]));\n", bitSymbol-1, bitSymbol-1, bitSymbol-1);
1496
   if (ErasureOption == 1){
1497
      fprintf(OutFileDecodeChien, "   RsDecodeMult RsDecodeMult_MulE1 (.A(numeReg2[%d:0]), .B(denomE1InvReg[%d:0]), .P(errorValueE1[%d:0]));\n", bitSymbol-1, bitSymbol-1, bitSymbol-1);
1498
   }
1499
 
1500
   fprintf(OutFileDecodeChien, "\n\n\n\n");
1501
 
1502
 
1503
   //------------------------------------------------------------------------
1504
   // registers
1505
   //------------------------------------------------------------------------
1506
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1507
   if (ErasureOption == 1){
1508
      fprintf(OutFileDecodeChien, "   // + lambdaSumReg, denomE1Reg, denomE1InvReg, epsilonSumReg, epsilonOddReg\n");
1509
   }
1510
   fprintf(OutFileDecodeChien, "   // + lambdaEvenReg, lambdaEvenReg2, lambdaEvenReg3, lambdaOddReg, lambdaOddReg2, lambdaOddReg3, denomE0Reg, denomE0InvReg\n");
1511
   fprintf(OutFileDecodeChien, "   // + omegaSumReg, numeReg, numeReg2\n");
1512
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1513
   fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
1514
   fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
1515
   if (ErasureOption == 1){
1516
      fprintf(OutFileDecodeChien, "         lambdaSumReg   [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1517
   }
1518
 
1519
   fprintf(OutFileDecodeChien, "         lambdaEvenReg  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1520
   fprintf(OutFileDecodeChien, "         lambdaEvenReg2 [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1521
   fprintf(OutFileDecodeChien, "         lambdaEvenReg3 [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1522
   fprintf(OutFileDecodeChien, "         lambdaOddReg   [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1523
   fprintf(OutFileDecodeChien, "         lambdaOddReg2  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1524
   fprintf(OutFileDecodeChien, "         lambdaOddReg3  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1525
   fprintf(OutFileDecodeChien, "         denomE0Reg     [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1526
 
1527
   if (ErasureOption == 1){
1528
      fprintf(OutFileDecodeChien, "         denomE1Reg     [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1529
   }
1530
   fprintf(OutFileDecodeChien, "         denomE0InvReg  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1531
   if (ErasureOption == 1){
1532
      fprintf(OutFileDecodeChien, "         denomE1InvReg  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1533
   }
1534
   fprintf(OutFileDecodeChien, "         omegaSumReg    [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1535
   fprintf(OutFileDecodeChien, "         numeReg        [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1536
   fprintf(OutFileDecodeChien, "         numeReg2       [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1537
 
1538
   if (ErasureOption == 1){
1539
      fprintf(OutFileDecodeChien, "         epsilonSumReg  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1540
      fprintf(OutFileDecodeChien, "         epsilonOddReg  [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
1541
   }
1542
 
1543
   fprintf(OutFileDecodeChien, "      end\n");
1544
   fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
1545
   if (ErasureOption == 1){
1546
      fprintf(OutFileDecodeChien, "         lambdaSumReg   <= lambdaSum;\n");
1547
   }
1548
 
1549
   fprintf(OutFileDecodeChien, "         lambdaEvenReg3 <= lambdaEvenReg2;\n");
1550
   fprintf(OutFileDecodeChien, "         lambdaEvenReg2 <= lambdaEvenReg;\n");
1551
   fprintf(OutFileDecodeChien, "         lambdaEvenReg  <= lambdaEven;\n");
1552
   fprintf(OutFileDecodeChien, "         lambdaOddReg3  <= lambdaOddReg2;\n");
1553
   fprintf(OutFileDecodeChien, "         lambdaOddReg2  <= lambdaOddReg;\n");
1554
   fprintf(OutFileDecodeChien, "         lambdaOddReg   <= lambdaOdd;\n");
1555
   fprintf(OutFileDecodeChien, "         denomE0Reg     <= denomE0;\n");
1556
   if (ErasureOption == 1){
1557
      fprintf(OutFileDecodeChien, "         denomE1Reg     <= denomE1;\n");
1558
   }
1559
 
1560
   fprintf(OutFileDecodeChien, "         denomE0InvReg  <= denomE0Inv;\n");
1561
   if (ErasureOption == 1){
1562
      fprintf(OutFileDecodeChien, "         denomE1InvReg  <= denomE1Inv;\n");
1563
   }
1564
 
1565
   fprintf(OutFileDecodeChien, "         numeReg2       <= numeReg;\n");
1566
   fprintf(OutFileDecodeChien, "         numeReg        <= omegaSumReg;\n");
1567
   fprintf(OutFileDecodeChien, "         omegaSumReg    <= omegaSum;\n");
1568
   if (ErasureOption == 1){
1569
      fprintf(OutFileDecodeChien, "         epsilonSumReg  <= epsilonSum;\n");
1570
      fprintf(OutFileDecodeChien, "         epsilonOddReg  <= epsilonOdd;\n");
1571
   }
1572
   fprintf(OutFileDecodeChien, "      end\n");
1573
   fprintf(OutFileDecodeChien, "   end\n");
1574
   fprintf(OutFileDecodeChien, "\n\n\n");
1575
 
1576
 
1577
   //------------------------------------------------------------------
1578
   // + errorOut
1579
   //- 
1580
   //------------------------------------------------------------------
1581
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1582
   fprintf(OutFileDecodeChien, "   // + errorOut\n");
1583
   fprintf(OutFileDecodeChien, "   //- \n");
1584
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1585
   fprintf(OutFileDecodeChien, "   reg   [%d:0]  errorOut;\n", bitSymbol-1);
1586
 
1587
   if (ErasureOption == 1){
1588
      fprintf(OutFileDecodeChien, "   always @(erasureIn or lambdaEvenReg3 or lambdaOddReg3 or errorValueE0 or errorValueE1) begin\n");
1589
   }else{
1590
      fprintf(OutFileDecodeChien, "   always @(lambdaEvenReg3 or lambdaOddReg3 or errorValueE0) begin\n");
1591
   }
1592
 
1593
   if (ErasureOption == 1){
1594
      fprintf(OutFileDecodeChien, "      if (erasureIn == 1'b1) begin\n");
1595
      fprintf(OutFileDecodeChien, "         errorOut = errorValueE1;\n");
1596
      fprintf(OutFileDecodeChien, "      end\n");
1597
      fprintf(OutFileDecodeChien, "      else if (lambdaEvenReg3 == lambdaOddReg3) begin\n");
1598
      fprintf(OutFileDecodeChien, "         errorOut = errorValueE0;\n");
1599
      fprintf(OutFileDecodeChien, "      end\n");
1600
   }else{
1601
      fprintf(OutFileDecodeChien, "      if (lambdaEvenReg3 == lambdaOddReg3) begin\n");
1602
      fprintf(OutFileDecodeChien, "         errorOut = errorValueE0;\n");
1603
      fprintf(OutFileDecodeChien, "      end\n");
1604
   }
1605
 
1606
   fprintf(OutFileDecodeChien, "      else begin\n");
1607
   fprintf(OutFileDecodeChien, "         errorOut = %d'd0;\n", bitSymbol);
1608
   fprintf(OutFileDecodeChien, "      end\n");
1609
   fprintf(OutFileDecodeChien, "   end\n");
1610
   fprintf(OutFileDecodeChien, "\n\n\n");
1611
 
1612
 
1613
   //------------------------------------------------------------------------
1614
   // + numErrorReg
1615
   //- Count Error
1616
   //------------------------------------------------------------------------
1617
   if ((errorStats!=0) || (passFailFlag!=0)) {
1618
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1619
      fprintf(OutFileDecodeChien, "   // + numErrorReg\n");
1620
      fprintf(OutFileDecodeChien, "   //- Count Error\n");
1621
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1622
      fprintf(OutFileDecodeChien, "   reg    [%d:0]   numErrorReg;\n", indexSyndrome);
1623
      fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
1624
      fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
1625
      fprintf(OutFileDecodeChien, "         numErrorReg [%d:0]   <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
1626
      fprintf(OutFileDecodeChien, "      end\n");
1627
      fprintf(OutFileDecodeChien, "      else if (enable == 1'b1) begin\n");
1628
      fprintf(OutFileDecodeChien, "         if (sync == 1'b1) begin\n");
1629
      fprintf(OutFileDecodeChien, "            numErrorReg <= %d'd0;\n", indexSyndrome+1);
1630
      fprintf(OutFileDecodeChien, "         end\n");
1631
      fprintf(OutFileDecodeChien, "         else if (lambdaEven == lambdaOdd) begin\n");
1632
      fprintf(OutFileDecodeChien, "            numErrorReg <= numErrorReg + %d'd1;\n", indexSyndrome+1);
1633
      fprintf(OutFileDecodeChien, "         end\n");
1634
      fprintf(OutFileDecodeChien, "      end\n");
1635
      fprintf(OutFileDecodeChien, "   end\n");
1636
      fprintf(OutFileDecodeChien, "\n\n\n");
1637
   }
1638
 
1639
   //------------------------------------------------------------------
1640
   // + numErrorReg2
1641
   //------------------------------------------------------------------
1642
   if ((errorStats!=0) || (passFailFlag!=0)) {
1643
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1644
      fprintf(OutFileDecodeChien, "   // + numErrorReg2\n");
1645
      fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------\n");
1646
      fprintf(OutFileDecodeChien, "   reg    [%d:0]   numErrorReg2;\n", indexSyndrome);
1647
      fprintf(OutFileDecodeChien, "   always @(posedge CLK or negedge RESET) begin\n");
1648
      fprintf(OutFileDecodeChien, "      if (~RESET) begin\n");
1649
      fprintf(OutFileDecodeChien, "         numErrorReg2 <=  %d'd0;\n", indexSyndrome+1);
1650
      fprintf(OutFileDecodeChien, "      end\n");
1651
      fprintf(OutFileDecodeChien, "      else if ((enable == 1'b1) && (doneOrg == 1'b1)) begin\n");
1652
      fprintf(OutFileDecodeChien, "         if (lambdaEven == lambdaOdd) begin\n");
1653
      fprintf(OutFileDecodeChien, "            numErrorReg2 <= numErrorReg + %d'd1;\n", indexSyndrome+1);
1654
      fprintf(OutFileDecodeChien, "         end\n");
1655
      fprintf(OutFileDecodeChien, "         else begin\n");
1656
      fprintf(OutFileDecodeChien, "            numErrorReg2 <= numErrorReg;\n");
1657
      fprintf(OutFileDecodeChien, "         end\n");
1658
      fprintf(OutFileDecodeChien, "      end\n");
1659
      fprintf(OutFileDecodeChien, "   end\n");
1660
   }
1661
 
1662
   //------------------------------------------------------------------------
1663
   //- Output Ports
1664
   //------------------------------------------------------------------------
1665
   if ((errorStats!=0) || (passFailFlag!=0)) {
1666
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1667
   fprintf(OutFileDecodeChien, "   //- Output Ports\n");
1668
   fprintf(OutFileDecodeChien, "   //------------------------------------------------------------------------\n");
1669
   fprintf(OutFileDecodeChien, "   assign   numError = numErrorReg2;\n");
1670
   }
1671
 
1672
   fprintf(OutFileDecodeChien, "\n\n");
1673
   fprintf(OutFileDecodeChien, "endmodule\n");
1674
 
1675
 
1676
   //---------------------------------------------------------------
1677
   // close file
1678
   //---------------------------------------------------------------
1679
   fclose(OutFileDecodeChien);
1680
 
1681
 
1682
  //---------------------------------------------------------------
1683
  // Free memory
1684
  //---------------------------------------------------------------
1685
   delete[] coeffTab;
1686
   delete[] initTab;
1687
   delete[] x1Tab;
1688
   delete[] x2Tab;
1689
   delete[] ppTab;
1690
   delete[] powerTab;
1691
   delete[] bbTab;
1692
   delete[] ttTab;
1693
   delete[] bidon;
1694
 
1695
 
1696
   //---------------------------------------------------------------
1697
   // automatically convert Dos mode To Unix mode
1698
   //---------------------------------------------------------------
1699
        char ch;
1700
        char temp[MAX_PATH]="\0";
1701
 
1702
        //Open the file for reading in binarymode.
1703
        ifstream fp_read(strRsDecodeChien, ios_base::in | ios_base::binary);
1704
        sprintf(temp, "%s.temp", strRsDecodeChien);
1705
        //Create a temporary file for writing in the binary mode. This
1706
        //file will be created in the same directory as the input file.
1707
        ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
1708
 
1709
        while(fp_read.eof() != true)
1710
        {
1711
                fp_read.get(ch);
1712
                //Check for CR (carriage return)
1713
                if((int)ch == 0x0D)
1714
                        continue;
1715
                if (!fp_read.eof())fp_write.put(ch);
1716
        }
1717
 
1718
        fp_read.close();
1719
        fp_write.close();
1720
        //Delete the existing input file.
1721
        remove(strRsDecodeChien);
1722
        //Rename the temporary file to the input file.
1723
        rename(temp, strRsDecodeChien);
1724
        //Delete the temporary file.
1725
        remove(temp);
1726
 
1727
 
1728
   //---------------------------------------------------------------
1729
   // clean string
1730
   //---------------------------------------------------------------
1731
   free(strRsDecodeChien);
1732
 
1733
 
1734
}

powered by: WebSVN 2.1.0

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