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

powered by: WebSVN 2.1.0

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