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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeSyndromeEmulator
3
// File Name   : RsDecodeSyndromeEmulator.cpp
4
// Function    : RS Decoder syndrome 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
 
19
 
20
void RsGfMultiplier( int*, int*,int*, int, int);
21
void RsDecodeSyndromeEmulator(int *regSyndrome, int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int *MrefTab, int *PrefTab, int *DataIn) {
22
 
23
 
24
   //---------------------------------------------------------------
25
   // C++ variables
26
   //---------------------------------------------------------------
27
   int aa, bb, kk, ii,ff, zz, tt;
28
   int syndromeLength;
29
   int tempix;
30
   int LoopSize;
31
   int Pidx;
32
   int init;
33
   int idx1;
34
   int idx2;
35
   int tempNum;
36
   int mmTabSize = (bitSymbol*2) -1;
37
 
38
   //---------------------------------------------------------------
39
   // calculate syndrome polynom length
40
   //---------------------------------------------------------------
41
   syndromeLength = TotalSize - DataSize;
42
 
43
   int *powerTab;
44
   int *DataInBin;
45
   int *productTab;
46
   int *bbTab;
47
   int *ppTab;
48
   int *ttTab;
49
   int *bidon;
50
 
51
   powerTab        = new int[bitSymbol];
52
   DataInBin       = new int[bitSymbol];
53
   productTab      = new int[syndromeLength*bitSymbol];
54
   bbTab           = new int[bitSymbol];
55
   ppTab           = new int[bitSymbol];
56
   ttTab           = new int[bitSymbol];
57
   bidon           = new int[bitSymbol];
58
 
59
 
60
   //---------------------------------------------------------------
61
   //+ initialize powerTab
62
   //---------------------------------------------------------------
63
   powerTab[0] = 1;
64
   for (ii=1; ii<bitSymbol;ii++){
65
      powerTab[ii] = 2*powerTab[ii-1];
66
   }
67
 
68
 
69
   //---------------------------------------------------------------
70
   // Dec2Bin Datain[0]
71
   //---------------------------------------------------------------
72
   tempix = DataIn[0];
73
 
74
   for (zz =bitSymbol-1; zz>=0;zz=zz-1) {
75
      if (tempix >= powerTab[zz]) {
76
         tempix = tempix - powerTab[zz];
77
         DataInBin [zz] = 1;
78
      }else{
79
         DataInBin [zz] = 0;
80
      }
81
   }
82
 
83
 
84
   //---------------------------------------------------------------
85
   // assign regSyndrome
86
   //---------------------------------------------------------------
87
   for (ii=0; ii < syndromeLength; ii++) {
88
      for (zz=0; zz < bitSymbol; zz++) {
89
         regSyndrome[ii*bitSymbol+zz] = DataInBin [zz];
90
      }
91
   }
92
 
93
 
94
 
95
 
96
   //---------------------------------------------------------------
97
   // calculate regSyndrome
98
   //---------------------------------------------------------------
99
   for (ii=1; ii < TotalSize; ii++) {
100
 
101
 
102
      //---------------------------------------------------------------
103
      // reset productTab
104
      //---------------------------------------------------------------
105
      for (tt=0; tt < syndromeLength*bitSymbol; tt++) {
106
         productTab [tt] = 0;
107
      }
108
 
109
      //---------------------------------------------------------------
110
      // update productTab
111
      //---------------------------------------------------------------
112
      for (zz=0; zz < syndromeLength; zz++) {
113
         if (zz == 0) {
114
            for (bb = 0; bb <bitSymbol;bb++){
115
               productTab[zz*bitSymbol+bb] = regSyndrome[zz*bitSymbol+bb];
116
            }
117
         }else{
118
         ttTab[0] = 1;
119
 
120
         for (kk = 1; kk <bitSymbol;kk++){
121
            ttTab[kk] = 0;
122
         }
123
 
124
         bbTab[0] = 0;
125
         bbTab[1] = 1;
126
 
127
         for (kk = 2; kk <bitSymbol;kk++){
128
           bbTab[kk] = 0;
129
         }
130
 
131
         //------------------------------------------------------------------------
132
         //------------------------------------------------------------------------
133
         for(ff=1; ff<zz+1; ff++){
134
            //------------------------------------------------------------------------
135
            // ppTab = ttTab * bbTab
136
            //------------------------------------------------------------------------
137
            RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
138
 
139
            //------------------------------------------------------------------------
140
            // reassign ttTab
141
            //------------------------------------------------------------------------
142
            for (kk = 0; kk <bitSymbol;kk++){
143
               ttTab[kk]        = ppTab[kk];
144
            }
145
 
146
 
147
            //------------------------------------------------------------------------
148
            // write P_OUT[0]
149
            //------------------------------------------------------------------------
150
            if (ff==zz) {
151
               for (Pidx=0; Pidx<bitSymbol; Pidx++){
152
                  init = 0;
153
 
154
                  for (idx2=0; idx2<bitSymbol;idx2++){
155
                     bidon [idx2] = 0;
156
                  }
157
                  for (idx1=0; idx1<mmTabSize;idx1++){
158
                     tempNum = PrefTab [Pidx*mmTabSize+idx1];
159
                     if (tempNum == 1) {
160
                        //------------------------------------------------------------------------
161
                        // search
162
                        //------------------------------------------------------------------------
163
                        for (idx2=0; idx2<bitSymbol;idx2++){
164
                           tempNum = MrefTab[idx1*bitSymbol+idx2];
165
                           if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
166
                              if  (bidon [idx2] == 0) {
167
                                 bidon [idx2] = 1;
168
                              }
169
                              else {
170
                                 bidon [idx2] = 0;
171
                              }
172
                           }
173
                        }
174
                     }
175
                  }
176
                  //------------------------------------------------------------------------
177
                  // printf
178
                  //------------------------------------------------------------------------
179
                  for (idx2=0; idx2<bitSymbol; idx2++){
180
                     if (bidon[idx2] == 1) {
181
                        productTab[zz*bitSymbol+Pidx] = productTab[zz*bitSymbol+Pidx] ^ regSyndrome[zz*bitSymbol+idx2];
182
                     }
183
                  }
184
               }
185
            }
186
         }
187
      }
188
      }
189
 
190
 
191
      //---------------------------------------------------------------
192
      // Dec2Bin Datain[0]
193
      //---------------------------------------------------------------
194
      tempix = DataIn[ii];
195
      for (zz =bitSymbol-1; zz>=0;zz=zz-1) {
196
         if (tempix >= powerTab[zz]) {
197
            tempix = tempix - powerTab[zz];
198
            DataInBin [zz] = 1;
199
         }else{
200
            DataInBin [zz] = 0;
201
         }
202
      }
203
 
204
 
205
      //---------------------------------------------------------------
206
      // assign regSyndrome
207
      //---------------------------------------------------------------
208
      for (aa=0; aa < syndromeLength; aa++) {
209
         for (zz=0; zz < bitSymbol; zz++) {
210
            regSyndrome[aa*bitSymbol+zz] = DataInBin [zz] ^ productTab[aa*bitSymbol+zz];
211
         }
212
      }
213
   }
214
 
215
 
216
 
217
 
218
 
219
   //---------------------------------------------------------------
220
   // Free memory
221
   //---------------------------------------------------------------
222
   delete[] powerTab;
223
   delete[] DataInBin;
224
   delete[] productTab;
225
   delete[] bbTab;
226
   delete[] ppTab;
227
   delete[] ttTab;
228
   delete[] bidon;
229
 
230
 
231
}

powered by: WebSVN 2.1.0

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