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/] [RsDecodeErasure.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeErasure
3
// File Name   : RsDecodeErasure.cpp
4
// Function    : RTL Decoder Erasure polynomial 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  *OutFileDecodeErasure;
23
 
24
void RsGfMultiplier( int*, int*,int*, int, int);
25
 
26
void RsDecodeErasure(int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int passFailFlag, int ErasureOption, int *MrefTab, int *PrefTab, int *coeffTab, int pathFlag, int lengthPath, char *rootFolderPath) {
27
 
28
 
29
   //---------------------------------------------------------------
30
   // c++ variables
31
   //---------------------------------------------------------------
32
   int syndromeLength;
33
   int ii;
34
   int MaxValue;
35
   int initValue;
36
   int Pidx;
37
   int init;
38
   int idx1;
39
   int idx2;
40
   int countSize;
41
   int mmTabSize = (bitSymbol*2) -1;
42
   int tempNum;
43
   int *bbTab;
44
   int *ppTab;
45
   int *ttTab;
46
   int *powerTab;
47
   int *bidon;
48
   char *strRsDecodeErasure;
49
 
50
   bbTab    =new int[bitSymbol];
51
   ppTab    =new int[bitSymbol];
52
   ttTab    =new int[bitSymbol];
53
   powerTab =new int[bitSymbol];
54
   bidon    =new int[bitSymbol];
55
 
56
   //---------------------------------------------------------------
57
   // syndrome Length calculation
58
   //---------------------------------------------------------------
59
   syndromeLength = TotalSize - DataSize;
60
 
61
 
62
   countSize = 0;
63
 
64
   if (TotalSize > 2047) {
65
      countSize = 12;
66
   } else{
67
      if (TotalSize > 1023) {
68
         countSize = 11;
69
      } else{
70
         if (TotalSize > 511) {
71
            countSize = 10;
72
         }else{
73
            if (TotalSize > 255) {
74
               countSize = 9;
75
            }else{
76
               if (TotalSize > 127) {
77
                  countSize = 8;
78
               }else{
79
                  if (TotalSize > 63) {
80
                     countSize = 7;
81
                  }else{
82
                     if (TotalSize > 31) {
83
                        countSize = 6;
84
                     }else{
85
                        if (TotalSize > 15) {
86
                           countSize = 5;
87
                        }else{
88
                           if (TotalSize > 7) {
89
                              countSize = 4;
90
                           }else{
91
                              if (TotalSize > 3) {
92
                                 countSize = 3;
93
                              }else{
94
                                 countSize = 2;
95
                              }
96
                           }
97
                        }
98
                     }
99
                  }
100
               }
101
            }
102
         }
103
      }
104
   }
105
 
106
 
107
   //---------------------------------------------------------------
108
   // MaxValue calculation
109
   //---------------------------------------------------------------
110
   MaxValue = 2;
111
   for(ii=0; ii<(bitSymbol-1); ii++){
112
      MaxValue = MaxValue*2;
113
   }
114
 
115
   int param1 = MaxValue - TotalSize;
116
 
117
 
118
   //---------------------------------------------------------------
119
   // powerTab calculation
120
   //---------------------------------------------------------------
121
   powerTab[0] = 1;
122
   for (ii=1; ii<bitSymbol;ii++){
123
      powerTab[ii] = 2*powerTab[ii-1];
124
   }
125
 
126
 
127
   //---------------------------------------------------------------
128
   // open file
129
   //---------------------------------------------------------------
130
   strRsDecodeErasure = (char *)calloc(lengthPath + 23,  sizeof(char));
131
   if (pathFlag == 0) {
132
        strRsDecodeErasure[0] = '.';
133
   }else{
134
      for(ii=0; ii<lengthPath; ii++){
135
         strRsDecodeErasure[ii] = rootFolderPath[ii];
136
      }
137
   }
138
   strcat(strRsDecodeErasure, "/rtl/RsDecodeErasure.v");
139
 
140
   OutFileDecodeErasure = fopen(strRsDecodeErasure,"w");
141
 
142
 
143
 
144
   //---------------------------------------------------------------
145
   // header file
146
   //---------------------------------------------------------------
147
   fprintf(OutFileDecodeErasure, "//===================================================================\n");
148
   fprintf(OutFileDecodeErasure, "// Module Name : RsDecodeErasure\n");
149
   fprintf(OutFileDecodeErasure, "// File Name   : RsDecodeErasure.v\n");
150
   fprintf(OutFileDecodeErasure, "// Function    : Rs Decoder Erasure polynomial calculation Module\n");
151
   fprintf(OutFileDecodeErasure, "// \n");
152
   fprintf(OutFileDecodeErasure, "// Revision History:\n");
153
   fprintf(OutFileDecodeErasure, "// Date          By           Version    Change Description\n");
154
   fprintf(OutFileDecodeErasure, "//===================================================================\n");
155
   fprintf(OutFileDecodeErasure, "// 2009/02/03  Gael Sapience     1.0       Original\n");
156
   fprintf(OutFileDecodeErasure, "//\n");
157
   fprintf(OutFileDecodeErasure, "//===================================================================\n");
158
   fprintf(OutFileDecodeErasure, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
159
   fprintf(OutFileDecodeErasure, "//\n\n\n");
160
 
161
 
162
   //---------------------------------------------------------------
163
   // Ports Declaration
164
   //---------------------------------------------------------------
165
   fprintf(OutFileDecodeErasure, "module RsDecodeErasure(\n");
166
   fprintf(OutFileDecodeErasure, "   CLK,          // system clock\n");
167
   fprintf(OutFileDecodeErasure, "   RESET,        // system reset\n");
168
   fprintf(OutFileDecodeErasure, "   enable,       // enable signal\n");
169
   fprintf(OutFileDecodeErasure, "   sync,         // sync signal\n");
170
   fprintf(OutFileDecodeErasure, "   erasureIn,    // erasure input\n");
171
 
172
   for (ii=0; ii<(syndromeLength+1); ii++){
173
      if (ii < 10) {
174
         fprintf(OutFileDecodeErasure, "   epsilon_%d,    // epsilon polynom %d\n",ii,ii);
175
      }else{
176
         fprintf(OutFileDecodeErasure, "   epsilon_%d,   // epsilon polynom %d\n",ii,ii);
177
      }
178
   }
179
 
180
   fprintf(OutFileDecodeErasure, "   numErasure,   // erasure amount\n");
181
   if (passFailFlag == 1){
182
      fprintf(OutFileDecodeErasure, "   fail,         // decoder failure signal\n");
183
   }
184
   fprintf(OutFileDecodeErasure, "   done          // done signal\n");
185
   fprintf(OutFileDecodeErasure, ");\n\n\n");
186
 
187
   fprintf(OutFileDecodeErasure, "   input          CLK;           // system clock\n");
188
   fprintf(OutFileDecodeErasure, "   input          RESET;         // system reset\n");
189
   fprintf(OutFileDecodeErasure, "   input          enable;        // enable signal\n");
190
   fprintf(OutFileDecodeErasure, "   input          sync;          // sync signal\n");
191
   fprintf(OutFileDecodeErasure, "   input          erasureIn;     // erasure input\n");
192
 
193
   for (ii=0; ii<(syndromeLength+1);ii++){
194
      if (ii < 10) {
195
         fprintf(OutFileDecodeErasure,  "   output [%d:0]   epsilon_%d;     // syndrome polynom %d\n",(bitSymbol-1), ii, ii);
196
      }else{
197
         fprintf(OutFileDecodeErasure,  "   output [%d:0]   epsilon_%d;    // syndrome polynom %d\n",(bitSymbol-1), ii, ii);
198
      }
199
   }
200
 
201
  if (syndromeLength > 2047) {
202
     fprintf(OutFileDecodeErasure, "   output [11:0]   numErasure;    // erasure amount\n");
203
  }else{
204
     if (syndromeLength > 1023) {
205
        fprintf(OutFileDecodeErasure, "   output [10:0]   numErasure;    // erasure amount\n");
206
     }else{
207
        if (syndromeLength > 511) {
208
           fprintf(OutFileDecodeErasure, "   output [9:0]   numErasure;    // erasure amount\n");
209
        }else{
210
           if (syndromeLength > 255) {
211
               fprintf(OutFileDecodeErasure, "   output [8:0]   numErasure;    // erasure amount\n");
212
           }else{
213
              if (syndromeLength > 127) {
214
                 fprintf(OutFileDecodeErasure, "   output [7:0]   numErasure;    // erasure amount\n");
215
              }else{
216
                 if (syndromeLength > 63) {
217
                    fprintf(OutFileDecodeErasure, "   output [6:0]   numErasure;    // erasure amount\n");
218
                 }else{
219
                    if (syndromeLength > 31) {
220
                       fprintf(OutFileDecodeErasure, "   output [5:0]   numErasure;    // erasure amount\n");
221
                    }else{
222
                       if (syndromeLength > 15) {
223
                          fprintf(OutFileDecodeErasure, "   output [4:0]   numErasure;    // erasure amount\n");
224
                       }else{
225
                          if (syndromeLength > 7) {
226
                             fprintf(OutFileDecodeErasure, "   output [3:0]   numErasure;    // erasure amount\n");
227
                          }else{
228
                             if (syndromeLength > 3) {
229
                                fprintf(OutFileDecodeErasure, "   output [2:0]   numErasure;    // erasure amount\n");
230
                             }else{
231
                                fprintf(OutFileDecodeErasure, "   output [1:0]   numErasure;    // erasure amount\n");
232
                             }
233
                          }
234
                       }
235
                    }
236
                 }
237
              }
238
           }
239
        }
240
     }
241
  }
242
 
243
   if (passFailFlag == 1){
244
      fprintf(OutFileDecodeErasure, "   output         fail;          // decoder failure signal\n");
245
   }
246
   fprintf(OutFileDecodeErasure, "   output         done;          // done signal\n");
247
 
248
 
249
  //---------------------------------------------------------------
250
  // initialize ttTab
251
  //---------------------------------------------------------------
252
   ttTab[0] = 1;
253
   for (ii=1;ii<bitSymbol;ii++){
254
      ttTab[ii] = 0;
255
   }
256
 
257
 
258
  //---------------------------------------------------------------
259
  // initialize bbTab
260
  //---------------------------------------------------------------
261
   bbTab[0] = 0;
262
   bbTab[1] = 1;
263
   for (ii=2;ii<bitSymbol;ii++){
264
      bbTab[ii] = 0;
265
   }
266
   int kk;
267
 
268
 
269
  //---------------------------------------------------------------
270
  //---------------------------------------------------------------
271
   for (ii=1;ii < (param1+1);ii++){
272
      RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
273
 
274
      for (kk=0; kk<bitSymbol;kk++){
275
         ttTab[kk]      = ppTab[kk];
276
      }
277
   }
278
 
279
   initValue = 0;
280
   for (kk=0; kk<bitSymbol;kk++){
281
      initValue = initValue + ttTab[kk] * powerTab[kk];
282
   }
283
 
284
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------\n");
285
   fprintf(OutFileDecodeErasure, "   // - parameters\n");
286
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------\n");
287
//   fprintf(OutFileDecodeErasure, "   parameter erasurePower     = %d'd1;\n", bitSymbol);
288
   fprintf(OutFileDecodeErasure, "   parameter erasureInitialPower = %d'd%d;\n", bitSymbol, initValue);
289
   fprintf(OutFileDecodeErasure, "\n\n\n");
290
 
291
 
292
   //------------------------------------------------------------------------
293
   // + count
294
   //- Counter
295
   //------------------------------------------------------------------------
296
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
297
   fprintf(OutFileDecodeErasure, "   // + count\n");
298
   fprintf(OutFileDecodeErasure, "   //- Counter\n");
299
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
300
//   fprintf(OutFileDecodeErasure, "  reg    [%d:0]   count;\n",bitSymbol);
301
   fprintf(OutFileDecodeErasure, "  reg    [%d:0]   count;\n",countSize-1);
302
   fprintf(OutFileDecodeErasure, "   always @(posedge CLK or negedge RESET) begin\n");
303
   fprintf(OutFileDecodeErasure, "      if (~RESET) begin\n");
304
//   fprintf(OutFileDecodeErasure, "         count [%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
305
   fprintf(OutFileDecodeErasure, "         count [%d:0] <= %d'd0;\n",countSize-1,countSize);
306
   fprintf(OutFileDecodeErasure, "      end\n");
307
   fprintf(OutFileDecodeErasure, "      else if (enable == 1'b1) begin\n");
308
   fprintf(OutFileDecodeErasure, "         if (sync == 1'b1) begin\n");
309
//   fprintf(OutFileDecodeErasure, "            count[%d:0] <= %d'd1;\n",bitSymbol,bitSymbol+1);
310
   fprintf(OutFileDecodeErasure, "            count[%d:0] <= %d'd1;\n",countSize-1,countSize);
311
   fprintf(OutFileDecodeErasure, "         end\n");
312
//   fprintf(OutFileDecodeErasure, "         else if ( (count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n",bitSymbol,bitSymbol+1,bitSymbol,bitSymbol+1, TotalSize);
313
   fprintf(OutFileDecodeErasure, "         else if ( (count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n",countSize-1,countSize,countSize-1,countSize, TotalSize);
314
//   fprintf(OutFileDecodeErasure, "            count[%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
315
   fprintf(OutFileDecodeErasure, "            count[%d:0] <= %d'd0;\n",countSize-1,countSize);
316
   fprintf(OutFileDecodeErasure, "         end\n");
317
   fprintf(OutFileDecodeErasure, "         else begin\n");
318
//   fprintf(OutFileDecodeErasure, "            count[%d:0] <= count[%d:0] + %d'd1;\n",bitSymbol,bitSymbol,bitSymbol+1);
319
   fprintf(OutFileDecodeErasure, "            count[%d:0] <= count[%d:0] + %d'd1;\n",countSize-1,countSize-1,countSize);
320
   fprintf(OutFileDecodeErasure, "         end\n");
321
   fprintf(OutFileDecodeErasure, "      end\n");
322
   fprintf(OutFileDecodeErasure, "   end\n");
323
   fprintf(OutFileDecodeErasure, "\n\n\n");
324
 
325
 
326
   //------------------------------------------------------------------------
327
   // + done
328
   //------------------------------------------------------------------------
329
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
330
   fprintf(OutFileDecodeErasure, "   // + done\n");
331
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
332
   fprintf(OutFileDecodeErasure, "   reg         done;\n");
333
   fprintf(OutFileDecodeErasure, "   always @(count) begin\n");
334
//   fprintf(OutFileDecodeErasure, "      if (count ==%d'd%d) begin\n",bitSymbol+1,TotalSize);
335
   fprintf(OutFileDecodeErasure, "      if (count ==%d'd%d) begin\n",countSize,TotalSize);
336
   fprintf(OutFileDecodeErasure, "         done = 1'b1;\n");
337
   fprintf(OutFileDecodeErasure, "      end\n");
338
   fprintf(OutFileDecodeErasure, "      else begin\n");
339
   fprintf(OutFileDecodeErasure, "         done = 1'b0;\n");
340
   fprintf(OutFileDecodeErasure, "      end\n");
341
   fprintf(OutFileDecodeErasure, "   end\n");
342
   fprintf(OutFileDecodeErasure, "\n\n");
343
 
344
 
345
   //------------------------------------------------------------------------
346
   // + erasureCount
347
   //- Erasure Counter
348
   //------------------------------------------------------------------------
349
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
350
   fprintf(OutFileDecodeErasure, "   // + erasureCount\n");
351
   fprintf(OutFileDecodeErasure, "   //- Erasure Counter\n");
352
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
353
//   fprintf(OutFileDecodeErasure, "   reg    [%d:0]   erasureCount;\n",bitSymbol);
354
   fprintf(OutFileDecodeErasure, "   reg    [%d:0]   erasureCount;\n",countSize-1);
355
   fprintf(OutFileDecodeErasure, "   always @(posedge CLK or negedge RESET) begin\n");
356
   fprintf(OutFileDecodeErasure, "      if (~RESET) begin\n");
357
//   fprintf(OutFileDecodeErasure, "         erasureCount [%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
358
   fprintf(OutFileDecodeErasure, "         erasureCount [%d:0] <= %d'd0;\n",countSize-1,countSize);
359
   fprintf(OutFileDecodeErasure, "      end\n");
360
   fprintf(OutFileDecodeErasure, "      else if (enable == 1'b1) begin\n");
361
   fprintf(OutFileDecodeErasure, "         if (sync == 1'b1) begin\n");
362
   fprintf(OutFileDecodeErasure, "            if (erasureIn == 1'b1) begin\n");
363
//   fprintf(OutFileDecodeErasure, "               erasureCount [%d:0] <= %d'd1;\n",bitSymbol,bitSymbol+1);
364
   fprintf(OutFileDecodeErasure, "               erasureCount [%d:0] <= %d'd1;\n",countSize-1,countSize);
365
   fprintf(OutFileDecodeErasure, "            end\n");
366
   fprintf(OutFileDecodeErasure, "            else begin\n");
367
//   fprintf(OutFileDecodeErasure, "               erasureCount [%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
368
   fprintf(OutFileDecodeErasure, "               erasureCount [%d:0] <= %d'd0;\n",countSize-1,countSize);
369
   fprintf(OutFileDecodeErasure, "            end\n");
370
   fprintf(OutFileDecodeErasure, "         end\n");
371
   fprintf(OutFileDecodeErasure, "         else if (erasureIn == 1'b1) begin\n");
372
//   fprintf(OutFileDecodeErasure, "            erasureCount [%d:0] <= erasureCount [%d:0] + %d'd1;\n",bitSymbol,bitSymbol,bitSymbol+1);
373
   fprintf(OutFileDecodeErasure, "            erasureCount [%d:0] <= erasureCount [%d:0] + %d'd1;\n",countSize-1,countSize-1,countSize);
374
   fprintf(OutFileDecodeErasure, "         end\n");
375
   fprintf(OutFileDecodeErasure, "      end\n");
376
   fprintf(OutFileDecodeErasure, "   end\n");
377
   fprintf(OutFileDecodeErasure, "\n\n");
378
 
379
 
380
   //------------------------------------------------------------------------
381
   // + fail
382
   //- If Erasure amount > CHECK_LEN -> fail is ON
383
   //------------------------------------------------------------------------
384
   if (passFailFlag == 1){
385
      fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
386
      fprintf(OutFileDecodeErasure, "   // + fail\n");
387
      fprintf(OutFileDecodeErasure, "   //- If Erasure amount > %d -> fail is ON\n", syndromeLength);
388
      fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
389
      fprintf(OutFileDecodeErasure, "   reg         fail;\n");
390
      fprintf(OutFileDecodeErasure, "   always @(erasureCount) begin\n");
391
//      fprintf(OutFileDecodeErasure, "      if (erasureCount [%d:0]> %d'd%d) begin\n",bitSymbol,bitSymbol+1,syndromeLength);
392
      fprintf(OutFileDecodeErasure, "      if (erasureCount [%d:0]> %d'd%d) begin\n",countSize-1,countSize,syndromeLength);
393
      fprintf(OutFileDecodeErasure, "         fail = 1'b1;\n");
394
      fprintf(OutFileDecodeErasure, "      end\n");
395
      fprintf(OutFileDecodeErasure, "      else begin\n");
396
      fprintf(OutFileDecodeErasure, "         fail = 1'b0;\n");
397
      fprintf(OutFileDecodeErasure, "      end\n");
398
      fprintf(OutFileDecodeErasure, "   end\n");
399
      fprintf(OutFileDecodeErasure, "\n\n");
400
   }
401
 
402
   //------------------------------------------------------------------------
403
   // Erasure Polynominal Generator
404
   //------------------------------------------------------------------------
405
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
406
   fprintf(OutFileDecodeErasure, "   // Erasure Polynominal Generator\n");
407
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
408
   fprintf(OutFileDecodeErasure, "   reg    [%d:0]    powerReg;\n",bitSymbol-1);
409
   fprintf(OutFileDecodeErasure, "   wire    [%d:0]   powerNew;\n",bitSymbol-1);
410
   fprintf(OutFileDecodeErasure, "   wire    [%d:0]   powerInitialNew;\n",bitSymbol-1);
411
   fprintf(OutFileDecodeErasure, "\n");
412
 
413
 
414
   //------------------------------------------------------------------------
415
   // RsDecodeMakeMultErasure Emulation
416
   //------------------------------------------------------------------------
417
   ttTab[0] = 1;
418
   for (ii=1;ii<bitSymbol;ii++){
419
      ttTab[ii] = 0;
420
   }
421
 
422
   bbTab[0] = 0;
423
   bbTab[1] = 1;
424
   for (ii=2;ii<bitSymbol;ii++){
425
      bbTab[ii] = 0;
426
   }
427
 
428
 
429
   //------------------------------------------------------------------------
430
   // ppTab = ttTab * bbTab
431
   //------------------------------------------------------------------------
432
   RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
433
 
434
   //------------------------------------------------------------------------
435
   // reassign ttTab
436
   //------------------------------------------------------------------------
437
   for (kk=0; kk<bitSymbol;kk++){
438
      ttTab[kk] = ppTab[kk];
439
   }
440
 
441
   //------------------------------------------------------------------------
442
   //------------------------------------------------------------------------
443
    for (Pidx=0; Pidx<bitSymbol; Pidx++){
444
       fprintf(OutFileDecodeErasure, "   assign powerInitialNew [%d] =",Pidx);
445
       init = 0;
446
 
447
       for (idx2=0; idx2<bitSymbol;idx2++){
448
          bidon [idx2] = 0;
449
       }
450
       for (idx1=0; idx1<mmTabSize;idx1++){
451
          tempNum = PrefTab [Pidx*mmTabSize+idx1];
452
          if (tempNum == 1) {
453
             //------------------------------------------------------------------------
454
             // search
455
             //------------------------------------------------------------------------
456
             for (idx2=0; idx2<bitSymbol;idx2++){
457
                tempNum = MrefTab[idx1*bitSymbol+idx2];
458
                if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
459
                   if  (bidon [idx2] == 0) {
460
                      bidon [idx2] = 1;
461
                   }
462
                   else {
463
                      bidon [idx2] = 0;
464
                   }
465
                }
466
             }
467
          }
468
       }
469
       //------------------------------------------------------------------------
470
       // printf
471
       //------------------------------------------------------------------------
472
       for (idx2=0; idx2<bitSymbol; idx2++){
473
          if (bidon[idx2] == 1) {
474
             if (init == 0) {
475
                fprintf(OutFileDecodeErasure, " erasureInitialPower[%d]", idx2);
476
                init = 1;
477
             }
478
             else {
479
                fprintf(OutFileDecodeErasure, " ^ erasureInitialPower[%d]", idx2);
480
             }
481
          }
482
       }
483
       fprintf(OutFileDecodeErasure, ";\n");
484
   }
485
 
486
 
487
    for (Pidx=0; Pidx<bitSymbol; Pidx++){
488
       fprintf(OutFileDecodeErasure, "   assign powerNew [%d] =",Pidx);
489
       init = 0;
490
 
491
       for (idx2=0; idx2<bitSymbol;idx2++){
492
          bidon [idx2] = 0;
493
       }
494
       for (idx1=0; idx1<mmTabSize;idx1++){
495
          tempNum = PrefTab [Pidx*mmTabSize+idx1];
496
          if (tempNum == 1) {
497
             //------------------------------------------------------------------------
498
             // search
499
             //------------------------------------------------------------------------
500
             for (idx2=0; idx2<bitSymbol;idx2++){
501
                tempNum = MrefTab[idx1*bitSymbol+idx2];
502
                if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
503
                   if  (bidon [idx2] == 0) {
504
                      bidon [idx2] = 1;
505
                   }
506
                   else {
507
                      bidon [idx2] = 0;
508
                   }
509
                }
510
             }
511
          }
512
       }
513
       //------------------------------------------------------------------------
514
       // printf
515
       //------------------------------------------------------------------------
516
       for (idx2=0; idx2<bitSymbol; idx2++){
517
          if (bidon[idx2] == 1) {
518
             if (init == 0) {
519
                fprintf(OutFileDecodeErasure, " powerReg[%d]", idx2);
520
                init = 1;
521
             }
522
             else {
523
                fprintf(OutFileDecodeErasure, " ^ powerReg[%d]", idx2);
524
             }
525
          }
526
       }
527
       fprintf(OutFileDecodeErasure, ";\n");
528
   }
529
 
530
   fprintf(OutFileDecodeErasure, "\n\n");
531
 
532
 
533
   //------------------------------------------------------------------
534
   // + powerReg
535
   //------------------------------------------------------------------
536
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------\n");
537
   fprintf(OutFileDecodeErasure, "   // + powerReg\n");
538
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------\n");
539
   fprintf(OutFileDecodeErasure, "   always @(posedge CLK or negedge RESET) begin\n");
540
   fprintf(OutFileDecodeErasure, "      if (~RESET) begin\n");
541
   fprintf(OutFileDecodeErasure, "         powerReg [%d:0] <= %d'd0;\n", bitSymbol-1, bitSymbol);
542
   fprintf(OutFileDecodeErasure, "      end\n");
543
   fprintf(OutFileDecodeErasure, "      else if (enable == 1'b1) begin\n");
544
   fprintf(OutFileDecodeErasure, "         if (sync == 1'b1) begin\n");
545
   fprintf(OutFileDecodeErasure, "            powerReg[%d:0] <= powerInitialNew[%d:0];\n", bitSymbol-1, bitSymbol-1);
546
   fprintf(OutFileDecodeErasure, "         end\n");
547
   fprintf(OutFileDecodeErasure, "         else begin\n");
548
   fprintf(OutFileDecodeErasure, "            powerReg[%d:0] <= powerNew[%d:0];\n", bitSymbol-1, bitSymbol-1);
549
   fprintf(OutFileDecodeErasure, "         end\n");
550
   fprintf(OutFileDecodeErasure, "      end\n");
551
   fprintf(OutFileDecodeErasure, "   end\n");
552
   fprintf(OutFileDecodeErasure, "\n\n");
553
 
554
 
555
   //------------------------------------------------------------------------
556
   // + product_0,..., product_xxx
557
   //- Erasure Polynominal Generator
558
   //------------------------------------------------------------------------
559
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
560
   fprintf(OutFileDecodeErasure, "   // + product_0,..., product_%d\n", syndromeLength);
561
   fprintf(OutFileDecodeErasure, "   //- Erasure Polynominal Generator\n");
562
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
563
 
564
   for (ii=0;ii<(syndromeLength+1);ii++){
565
       fprintf(OutFileDecodeErasure, "   wire [%d:0]   product_%d;\n", bitSymbol-1, ii);
566
   }
567
   fprintf(OutFileDecodeErasure, "\n");
568
 
569
 
570
   for (ii=0;ii<(syndromeLength+1);ii++){
571
      fprintf(OutFileDecodeErasure, "   reg  [%d:0]    epsilonReg_%d;\n", bitSymbol-1, ii);
572
   }
573
   fprintf(OutFileDecodeErasure, "\n\n");
574
 
575
 
576
   for (ii=0;ii<(syndromeLength+1);ii++){
577
    fprintf(OutFileDecodeErasure,  "   RsDecodeMult   RsDecodeMult_%d (.A(powerReg[%d:0]), .B(epsilonReg_%d[%d:0]), .P(product_%d[%d:0]));\n", ii, bitSymbol-1, ii, bitSymbol-1, ii, bitSymbol-1);
578
   }
579
   fprintf(OutFileDecodeErasure, "\n\n\n");
580
 
581
 
582
   //------------------------------------------------------------------------
583
   // + epsilonReg_0,..., epsilonReg_xxx
584
   //------------------------------------------------------------------------
585
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
586
   fprintf(OutFileDecodeErasure, "   // + epsilonReg_0,..., epsilonReg_%d\n", syndromeLength-1);
587
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
588
   fprintf(OutFileDecodeErasure, "   always @(posedge CLK or negedge RESET) begin\n");
589
   fprintf(OutFileDecodeErasure, "      if (~RESET) begin\n");
590
 
591
 
592
   for (ii=0;ii<(syndromeLength+1);ii++){
593
      if (ii < 10) {
594
         fprintf(OutFileDecodeErasure, "         epsilonReg_%d [%d:0]  <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
595
      }else{
596
         fprintf(OutFileDecodeErasure, "         epsilonReg_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
597
      }
598
   }
599
 
600
   fprintf(OutFileDecodeErasure, "      end\n");
601
   fprintf(OutFileDecodeErasure, "      else if (enable == 1'b1) begin\n");
602
   fprintf(OutFileDecodeErasure, "         if (sync == 1'b1) begin\n");
603
   fprintf(OutFileDecodeErasure, "            if (erasureIn == 1'b1) begin\n");
604
   fprintf(OutFileDecodeErasure, "               epsilonReg_0 [%d:0]   <= erasureInitialPower[%d:0];\n",bitSymbol-1,bitSymbol-1);
605
   fprintf(OutFileDecodeErasure, "               epsilonReg_1 [%d:0]   <= %d'd1;\n",bitSymbol-1,bitSymbol);
606
 
607
 
608
   for (ii=2;ii<(syndromeLength+1);ii++){
609
      if (ii < 10) {
610
         fprintf(OutFileDecodeErasure, "               epsilonReg_%d [%d:0]   <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
611
      }else{
612
         fprintf(OutFileDecodeErasure, "               epsilonReg_%d [%d:0]  <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
613
      }
614
   }
615
   fprintf(OutFileDecodeErasure, "            end\n");
616
   fprintf(OutFileDecodeErasure, "            else begin\n");
617
   fprintf(OutFileDecodeErasure, "               epsilonReg_0 [%d:0]  <= %d'd1;\n",bitSymbol-1,bitSymbol);
618
 
619
 
620
   for (ii=1;ii<(syndromeLength+1);ii++){
621
      if (ii < 10) {
622
         fprintf(OutFileDecodeErasure, "               epsilonReg_%d [%d:0]  <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
623
      }else{
624
        fprintf(OutFileDecodeErasure, "               epsilonReg_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
625
      }
626
   }
627
 
628
   fprintf(OutFileDecodeErasure, "            end\n");
629
   fprintf(OutFileDecodeErasure, "         end\n");
630
   fprintf(OutFileDecodeErasure, "         else if (erasureIn == 1'b1) begin\n");
631
   fprintf(OutFileDecodeErasure, "            epsilonReg_0 [%d:0]  <= product_0[%d:0];\n",bitSymbol-1,bitSymbol-1);
632
 
633
   for (ii=1;ii<(syndromeLength+1);ii++){
634
      if (ii < 10){
635
         fprintf(OutFileDecodeErasure, "            epsilonReg_%d [%d:0]  <= epsilonReg_%d [%d:0] ^ product_%d[%d:0];\n", ii,bitSymbol-1, (ii-1),bitSymbol-1, ii,bitSymbol-1);
636
      }else{
637
        fprintf(OutFileDecodeErasure, "            epsilonReg_%d [%d:0] <= epsilonReg_%d [%d:0] ^ product_%d[%d:0];\n", ii,bitSymbol-1, (ii-1),bitSymbol-1, ii,bitSymbol-1);
638
      }
639
   }
640
 
641
   fprintf(OutFileDecodeErasure, "         end\n");
642
   fprintf(OutFileDecodeErasure, "      end\n");
643
   fprintf(OutFileDecodeErasure, "   end\n");
644
   fprintf(OutFileDecodeErasure, "\n\n\n");
645
 
646
 
647
   //------------------------------------------------------------------------
648
   //- Output Ports
649
   //------------------------------------------------------------------------
650
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
651
   fprintf(OutFileDecodeErasure, "   //- Output Ports\n");
652
   fprintf(OutFileDecodeErasure, "   //------------------------------------------------------------------------\n");
653
 
654
 
655
   for (ii=0;ii<(syndromeLength+1);ii++){
656
      if (ii < 10){
657
        fprintf(OutFileDecodeErasure, "   assign epsilon_%d [%d:0]   = epsilonReg_%d[%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
658
      }else{
659
        fprintf(OutFileDecodeErasure, "   assign epsilon_%d [%d:0]  = epsilonReg_%d[%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
660
      }
661
   }
662
   fprintf(OutFileDecodeErasure, "\n");
663
 
664
 
665
 
666
   if (syndromeLength > 2047) {
667
      fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[11:0];\n");
668
   }else{
669
      if (syndromeLength > 1023) {
670
         fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[10:0];\n");
671
      }else{
672
         if (syndromeLength > 511) {
673
            fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[9:0];\n");
674
         }else{
675
            if (syndromeLength > 255) {
676
               fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[8:0];\n");
677
            }else{
678
               if (syndromeLength > 127) {
679
                  fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[7:0];\n");
680
               }else{
681
                  if (syndromeLength > 63) {
682
                     fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[6:0];\n");
683
                  }else{
684
                     if (syndromeLength > 31){
685
                        fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[5:0];\n");
686
                     }else{
687
                        if (syndromeLength > 15){
688
                           fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[4:0];\n");
689
                        }else{
690
                           if (syndromeLength > 7){
691
                              fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[3:0];\n");
692
                           }else{
693
                              if (syndromeLength > 3){
694
                                 fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[2:0];\n");
695
                              }else{
696
                                 fprintf(OutFileDecodeErasure, "   assign numErasure   = erasureCount[1:0];\n");
697
                              }
698
                           }
699
                        }
700
                     }
701
                  }
702
               }
703
            }
704
         }
705
      }
706
   }
707
 
708
 
709
   fprintf(OutFileDecodeErasure, "\n");
710
   fprintf(OutFileDecodeErasure, "endmodule\n");
711
 
712
 
713
   //---------------------------------------------------------------
714
   // close file
715
   //---------------------------------------------------------------
716
   fclose(OutFileDecodeErasure);
717
 
718
 
719
  //---------------------------------------------------------------
720
  // Free memory
721
  //---------------------------------------------------------------
722
   delete[] ttTab;
723
   delete[] bbTab;
724
   delete[] ppTab;
725
   delete[] powerTab;
726
   delete[] bidon;
727
 
728
 
729
 
730
   //---------------------------------------------------------------
731
   // automatically convert Dos mode To Unix mode
732
   //---------------------------------------------------------------
733
        char ch;
734
        char temp[MAX_PATH]="\0";
735
 
736
        //Open the file for reading in binarymode.
737
        ifstream fp_read(strRsDecodeErasure, ios_base::in | ios_base::binary);
738
        sprintf(temp, "%s.temp", strRsDecodeErasure);
739
 
740
        //Create a temporary file for writing in the binary mode. This
741
        //file will be created in the same directory as the input file.
742
        ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
743
 
744
        while(fp_read.eof() != true)
745
        {
746
                fp_read.get(ch);
747
                //Check for CR (carriage return)
748
                if((int)ch == 0x0D)
749
                        continue;
750
                if (!fp_read.eof())fp_write.put(ch);
751
        }
752
 
753
        fp_read.close();
754
        fp_write.close();
755
        //Delete the existing input file.
756
        remove(strRsDecodeErasure);
757
        //Rename the temporary file to the input file.
758
        rename(temp, strRsDecodeErasure);
759
        //Delete the temporary file.
760
        remove(temp);
761
 
762
 
763
   //---------------------------------------------------------------
764
   // clean string
765
   //---------------------------------------------------------------
766
   free(strRsDecodeErasure);
767
 
768
 
769
}

powered by: WebSVN 2.1.0

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