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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeErasureEmulator
3
// File Name   : RsDecodeErasureEmulator.cpp
4
// Function    : RS Decoder erasure emulator
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
 
18
//FILE  *OutFileErasureDebug;
19
 
20
 
21
void RsGfMultiplier( int*, int*,int*, int, int);
22
 
23
void RsDecodeErasureEmulator(int failErasure, int numErasure, int *epsilonRegTab, int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int *MrefTab, int *PrefTab, int *erasureTab) {
24
 
25
 
26
   //---------------------------------------------------------------
27
   //---------------------------------------------------------------
28
//   OutFileErasureDebug = fopen("RsEmulatorErasureDebug.txt","w");
29
 
30
 
31
   //---------------------------------------------------------------
32
   // C++ variables
33
   //---------------------------------------------------------------
34
   int syndromeLength;
35
   int ii, kk, zz ,aa;
36
   int Pidx;
37
   int init;
38
   int idx2;
39
   int idx1;
40
   int mmTabSize = (bitSymbol*2) -1;
41
   int tempNum;
42
   int tempix;
43
 
44
   int MaxValue;
45
   int initValue;
46
   int numErasureWidth;
47
   syndromeLength = TotalSize - DataSize;
48
 
49
   int *powerInitialNewTab;
50
   int *powerNewTab;
51
   int *bbTab;
52
   int *ppTab;
53
   int *ttTab;
54
   int *erasureInitialPowerTab;
55
   int *powerRegTab;
56
   int *powerTab;
57
   int *bidon;
58
   int *tempixTab;
59
   int *numErasureBinary;
60
 
61
 
62
   powerInitialNewTab     = new int[bitSymbol*bitSymbol];
63
   powerNewTab            = new int[bitSymbol*bitSymbol];
64
   bbTab                  = new int[bitSymbol];
65
   ppTab                  = new int[bitSymbol];
66
   ttTab                  = new int[bitSymbol];
67
   bidon                  = new int[bitSymbol];
68
   tempixTab              = new int[bitSymbol];
69
   erasureInitialPowerTab = new int[bitSymbol];
70
   powerRegTab            = new int[bitSymbol];
71
   powerTab               = new int[bitSymbol];
72
   numErasureBinary       = new int[bitSymbol];
73
 
74
 
75
   //---------------------------------------------------------------
76
   // MaxValue calculation
77
   //---------------------------------------------------------------
78
   MaxValue = 2;
79
   for(ii=0; ii<(bitSymbol-1); ii++){
80
      MaxValue = MaxValue*2;
81
   }
82
 
83
 
84
   //---------------------------------------------------------------
85
   // param1 calculation
86
   //---------------------------------------------------------------
87
   int param1 = MaxValue - TotalSize;
88
 
89
 
90
   //---------------------------------------------------------------
91
   // powerTab calculation
92
   //---------------------------------------------------------------
93
   powerTab[0] = 1;
94
   for (ii=1; ii<bitSymbol;ii++){
95
      powerTab[ii] = 2*powerTab[ii-1];
96
   }
97
 
98
 
99
   //---------------------------------------------------------------
100
   // initialize ttTab
101
   //---------------------------------------------------------------
102
   ttTab[0] = 1;
103
   for (ii=1;ii<bitSymbol;ii++){
104
      ttTab[ii] = 0;
105
   }
106
 
107
 
108
  //---------------------------------------------------------------
109
  // initialize bbTab
110
  //---------------------------------------------------------------
111
   bbTab[0] = 0;
112
   bbTab[1] = 1;
113
   for (ii=2;ii<bitSymbol;ii++){
114
      bbTab[ii] = 0;
115
   }
116
 
117
 
118
  //---------------------------------------------------------------
119
  //---------------------------------------------------------------
120
   for (ii=1;ii < (param1+1);ii++){
121
      RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
122
 
123
      for (kk=0; kk<bitSymbol;kk++){
124
         ttTab[kk]      = ppTab[kk];
125
      }
126
   }
127
 
128
   initValue = 0;
129
   for (kk=0; kk<bitSymbol;kk++){
130
      initValue = initValue + ttTab[kk] * powerTab[kk];
131
      erasureInitialPowerTab [kk] = ttTab[kk];
132
   }
133
 
134
 
135
   //------------------------------------------------------------------------
136
   // RsDecodeMakeMultErasure Emulation
137
   //------------------------------------------------------------------------
138
   ttTab[0] = 1;
139
   for (ii=1;ii<bitSymbol;ii++){
140
      ttTab[ii] = 0;
141
   }
142
 
143
 
144
   bbTab[0] = 0;
145
   bbTab[1] = 1;
146
   for (ii=2;ii<bitSymbol;ii++){
147
      bbTab[ii] = 0;
148
   }
149
 
150
 
151
   //------------------------------------------------------------------------
152
   // ppTab = ttTab * bbTab
153
   //------------------------------------------------------------------------
154
   RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
155
 
156
 
157
   //------------------------------------------------------------------------
158
   // reassign ttTab
159
   //------------------------------------------------------------------------
160
   for (kk=0; kk<bitSymbol;kk++){
161
      ttTab[kk] = ppTab[kk];
162
   }
163
 
164
 
165
   //------------------------------------------------------------------------
166
   // initialize powerInitialNewTab
167
   //------------------------------------------------------------------------
168
   for (kk=0; kk<bitSymbol*bitSymbol;kk++){
169
      powerInitialNewTab[kk] = 0;
170
   }
171
 
172
 
173
   //------------------------------------------------------------------------
174
   // powerInitialNewTab generation
175
   //------------------------------------------------------------------------
176
    for (Pidx=0; Pidx<bitSymbol; Pidx++){
177
       init = 0;
178
 
179
       for (idx2=0; idx2<bitSymbol;idx2++){
180
          bidon [idx2] = 0;
181
       }
182
       for (idx1=0; idx1<mmTabSize;idx1++){
183
          tempNum = PrefTab [Pidx*mmTabSize+idx1];
184
          if (tempNum == 1) {
185
             //------------------------------------------------------------------------
186
             // search
187
             //------------------------------------------------------------------------
188
             for (idx2=0; idx2<bitSymbol;idx2++){
189
                tempNum = MrefTab[idx1*bitSymbol+idx2];
190
                if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
191
                   if  (bidon [idx2] == 0) {
192
                      bidon [idx2] = 1;
193
                   }
194
                   else {
195
                      bidon [idx2] = 0;
196
                   }
197
                }
198
             }
199
          }
200
       }
201
       //------------------------------------------------------------------------
202
       // printf
203
       //------------------------------------------------------------------------
204
       for (idx2=0; idx2<bitSymbol; idx2++){
205
          if (bidon[idx2] == 1) {
206
             powerInitialNewTab [Pidx*bitSymbol + idx2] = 1;
207
          }
208
       }
209
   }
210
 
211
 
212
   //------------------------------------------------------------------------
213
   // initialize powerNewTab
214
   //------------------------------------------------------------------------
215
   for (kk=0; kk<bitSymbol*bitSymbol;kk++){
216
      powerNewTab[kk] = 0;
217
   }
218
 
219
 
220
   //------------------------------------------------------------------------
221
   // powerNewTab generation
222
   //------------------------------------------------------------------------
223
   for (Pidx=0; Pidx<bitSymbol; Pidx++){
224
       init = 0;
225
       for (idx2=0; idx2<bitSymbol;idx2++){
226
          bidon [idx2] = 0;
227
       }
228
       for (idx1=0; idx1<mmTabSize;idx1++){
229
          tempNum = PrefTab [Pidx*mmTabSize+idx1];
230
          if (tempNum == 1) {
231
             //------------------------------------------------------------------------
232
             // search
233
             //------------------------------------------------------------------------
234
             for (idx2=0; idx2<bitSymbol;idx2++){
235
                tempNum = MrefTab[idx1*bitSymbol+idx2];
236
                if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
237
                   if  (bidon [idx2] == 0) {
238
                      bidon [idx2] = 1;
239
                   }
240
                   else {
241
                      bidon [idx2] = 0;
242
                   }
243
                }
244
             }
245
          }
246
       }
247
       //------------------------------------------------------------------------
248
       // printf
249
       //------------------------------------------------------------------------
250
       for (idx2=0; idx2<bitSymbol; idx2++){
251
          if (bidon[idx2] == 1) {
252
             powerNewTab[Pidx*bitSymbol+idx2] = 1;
253
          }
254
       }
255
   }
256
 
257
 
258
   //---------------------------------------------------------------
259
   // initialize epsilonRegTab
260
   //---------------------------------------------------------------
261
   for (kk=0; kk<((syndromeLength+1)*bitSymbol); kk++){
262
      epsilonRegTab[kk] = 0;
263
   }
264
 
265
 
266
   //---------------------------------------------------------------
267
   // calculate epsilonRegTab
268
   //---------------------------------------------------------------
269
   for (kk=0; kk<TotalSize; kk++){
270
      //---------------------------------------------------------------
271
      // sync
272
      //---------------------------------------------------------------
273
      if (kk == 0){
274
         if (erasureTab[0] == 1){
275
            for (zz=0;zz<bitSymbol;zz++){
276
               epsilonRegTab[zz] = erasureInitialPowerTab [zz];
277
            }
278
            epsilonRegTab[bitSymbol] = 1;
279
         }else{
280
            epsilonRegTab[0] = 1;
281
         }
282
         for (zz=0;zz<bitSymbol;zz++){
283
            powerRegTab [zz] = 0;
284
            for (aa=0;aa<bitSymbol;aa++){
285
               powerRegTab [zz] = powerRegTab [zz] ^ (erasureInitialPowerTab[aa] & powerInitialNewTab[zz*bitSymbol+aa]);
286
            }
287
         }
288
         for (zz=0; zz<syndromeLength; zz++){
289
            tempNum = 0;
290
            for (aa=0; aa<bitSymbol; aa++){
291
               tempNum = tempNum + epsilonRegTab[zz*bitSymbol+aa] * powerTab[aa];
292
            }
293
         }
294
      } else {
295
         //---------------------------------------------------------------
296
         // NOT sync
297
         //---------------------------------------------------------------
298
         if (erasureTab[kk] == 1){
299
            for (zz=syndromeLength; zz>=0; zz--){
300
               for (aa=0; aa<bitSymbol; aa++){
301
                  bbTab[aa] = epsilonRegTab[zz*bitSymbol+aa];
302
               }
303
               RsGfMultiplier(ppTab, powerRegTab, bbTab, PrimPoly, bitSymbol);
304
 
305
               if (zz>0){
306
                  for (aa=0; aa<bitSymbol; aa++){
307
                     epsilonRegTab[zz*bitSymbol+aa] = epsilonRegTab[(zz-1)*bitSymbol+aa] ^ ppTab[aa];
308
                  }
309
               }else{
310
                 //---------------------------------------------------------------
311
                 // epsilonReg0
312
                 //---------------------------------------------------------------
313
                  for (aa=0; aa<bitSymbol; aa++){
314
                     epsilonRegTab[zz*bitSymbol+aa] = ppTab[aa];
315
                  }
316
               }
317
            }
318
         }
319
 
320
 
321
         //---------------------------------------------------------------
322
         // update powerReg
323
         //---------------------------------------------------------------
324
         for (zz=0;zz<bitSymbol;zz++){
325
            tempixTab[zz] = powerRegTab [zz];
326
         }
327
         for (zz=0;zz<bitSymbol;zz++){
328
            powerRegTab [zz] = 0;
329
            for (aa=0;aa<bitSymbol;aa++){
330
               powerRegTab [zz] = powerRegTab [zz] ^ (tempixTab [aa] & powerNewTab[zz*bitSymbol+aa]);
331
            }
332
         }
333
      }
334
   }
335
 
336
 
337
   //---------------------------------------------------------------
338
   // calculate numErasure
339
   //---------------------------------------------------------------
340
   numErasure = 0;
341
 
342
   for (kk=0; kk<TotalSize; kk++){
343
      if (erasureTab [kk] == 1) {
344
         numErasure = numErasure + 1;
345
      }
346
   }
347
 
348
 
349
   //---------------------------------------------------------------
350
   // convert numErasure (Decimal to binary)
351
   //---------------------------------------------------------------
352
   tempix = numErasure;
353
   for (zz =bitSymbol-1; zz>=0;zz--) {
354
      if (tempix >= powerTab[zz]) {
355
         tempix = tempix - powerTab[zz];
356
         numErasureBinary [zz] = 1;
357
      }else{
358
         numErasureBinary [zz] = 0;
359
      }
360
   }
361
 
362
 
363
   //---------------------------------------------------------------
364
   // numErasureWidth: allowed size for numErasure register
365
   //---------------------------------------------------------------
366
   if (syndromeLength > 2047) {
367
      numErasureWidth = 12;
368
   }else{
369
      if (syndromeLength > 1023) {
370
         numErasureWidth = 11;
371
      }else{
372
         if (syndromeLength > 511) {
373
            numErasureWidth = 10;
374
         }else{
375
            if (syndromeLength > 255) {
376
               numErasureWidth = 9;
377
            }else{
378
               if (syndromeLength > 127) {
379
                  numErasureWidth = 8;
380
               }else{
381
                  if (syndromeLength > 63) {
382
                     numErasureWidth = 7;
383
                  }else{
384
                     if (syndromeLength > 31){
385
                        numErasureWidth = 6;
386
                     }else{
387
                        if (syndromeLength > 15){
388
                           numErasureWidth = 5;
389
                        }else{
390
                           if (syndromeLength > 7){
391
                              numErasureWidth = 4;
392
                           }else{
393
                              if (syndromeLength > 3){
394
                                 numErasureWidth = 3;
395
                              }else{
396
                                 numErasureWidth = 2;
397
                              }
398
                           }
399
                        }
400
                     }
401
                  }
402
               }
403
            }
404
         }
405
      }
406
   }
407
 
408
 
409
   //---------------------------------------------------------------
410
   //---------------------------------------------------------------
411
//   fprintf(OutFileErasureDebug, "numErasure       = %d\n", numErasure);
412
//   fprintf(OutFileErasureDebug, "numErasureWidth  = %d\n", numErasureWidth);
413
//   fprintf(OutFileErasureDebug, "numErasureBinary = ");
414
//   for (zz =0; zz<bitSymbol;zz++) {
415
//      fprintf(OutFileErasureDebug, "%d_", numErasureBinary[zz]);
416
//   }
417
//   fprintf(OutFileErasureDebug, "\n");
418
 
419
 
420
   //---------------------------------------------------------------
421
   // adjust numErasure to numErasureWidth size
422
   //---------------------------------------------------------------
423
   numErasure = 0;
424
 
425
   for (zz = 0; zz <numErasureWidth; zz++){
426
      numErasure = numErasure + numErasureBinary[zz] * powerTab[zz];
427
   }
428
 
429
//   fprintf(OutFileErasureDebug, "numErasure Fixed = %d\n", numErasure);
430
 
431
   //---------------------------------------------------------------
432
   // calculate numErasure
433
   //---------------------------------------------------------------
434
   failErasure = 0;
435
 
436
   if (numErasure > syndromeLength) {
437
   failErasure = 1;
438
   }
439
 
440
//   fclose(OutFileErasureDebug);
441
 
442
 
443
   //---------------------------------------------------------------
444
   // Free memory
445
   //---------------------------------------------------------------
446
   delete[] powerInitialNewTab;
447
   delete[] powerNewTab;
448
   delete[] bbTab;
449
   delete[] ppTab;
450
   delete[] ttTab;
451
   delete[] erasureInitialPowerTab;
452
   delete[] powerRegTab;
453
   delete[] powerTab;
454
   delete[] bidon;
455
   delete[] tempixTab;
456
   delete[] numErasureBinary;
457
 
458
}

powered by: WebSVN 2.1.0

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