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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeShiftOmega
3
// File Name   : RsDecodeShiftOmega.cpp
4
// Function    : RTL Decoder Shit Omega 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  *OutFileShiftOmega;
23
 
24
 
25
void RsDecodeShiftOmega(int DataSize, int TotalSize, int PrimPoly, int ErasureOption, int bitSymbol, int pathFlag, int lengthPath, char *rootFolderPath) {
26
 
27
 
28
   //---------------------------------------------------------------
29
   // C++ variables
30
   //---------------------------------------------------------------
31
   int syndromeLength;
32
   int startPointer;
33
   int endPointer;
34
   int ii;
35
   int jj;
36
   int index;
37
   char *strRsDecodeShiftOmega;
38
 
39
   syndromeLength = TotalSize - DataSize;
40
 
41
 
42
   //------------------------------------------------------------------------
43
   // omega shift register core
44
   //------------------------------------------------------------------------
45
   if (ErasureOption == 0) {
46
      startPointer = syndromeLength/2;
47
   }else{
48
      startPointer = 0;
49
   }
50
   if (ErasureOption == 0){
51
      endPointer = (syndromeLength/2);
52
   }else{
53
      endPointer = syndromeLength;
54
   }
55
   //---------------------------------------------------------------
56
   // open file
57
   //---------------------------------------------------------------
58
   strRsDecodeShiftOmega = (char *)calloc(lengthPath + 26,  sizeof(char));
59
   if (pathFlag == 0) {
60
        strRsDecodeShiftOmega[0] = '.';
61
   }else{
62
      for(ii=0; ii<lengthPath; ii++){
63
         strRsDecodeShiftOmega[ii] = rootFolderPath[ii];
64
      }
65
   }
66
   strcat(strRsDecodeShiftOmega, "/rtl/RsDecodeShiftOmega.v");
67
 
68
   OutFileShiftOmega = fopen(strRsDecodeShiftOmega,"w");
69
 
70
 
71
 
72
   //---------------------------------------------------------------
73
   // Ports Declaration
74
   //---------------------------------------------------------------
75
   fprintf(OutFileShiftOmega, "//===================================================================\n");
76
   fprintf(OutFileShiftOmega, "// Module Name : RsDecodeShiftOmega\n");
77
   fprintf(OutFileShiftOmega, "// File Name   : RsDecodeShiftOmega.v\n");
78
   fprintf(OutFileShiftOmega, "// Function    : Rs Decoder Shift Omega Module\n");
79
   fprintf(OutFileShiftOmega, "// \n");
80
   fprintf(OutFileShiftOmega, "// Revision History:\n");
81
   fprintf(OutFileShiftOmega, "// Date          By           Version    Change Description\n");
82
   fprintf(OutFileShiftOmega, "//===================================================================\n");
83
   fprintf(OutFileShiftOmega, "// 2009/02/03  Gael Sapience     1.0       Original\n");
84
   fprintf(OutFileShiftOmega, "//\n");
85
   fprintf(OutFileShiftOmega, "//===================================================================\n");
86
   fprintf(OutFileShiftOmega, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
87
   fprintf(OutFileShiftOmega, "//\n\n\n");
88
 
89
 
90
   fprintf(OutFileShiftOmega, "module RsDecodeShiftOmega(\n");
91
 
92
 
93
   for(ii=startPointer; ii<syndromeLength; ii++){
94
      if (ii < 10){
95
         fprintf(OutFileShiftOmega, "   omega_%d,           // omega polynom %d\n", ii, ii);
96
      }else{
97
         fprintf(OutFileShiftOmega, "   omega_%d,          // omega polynom %d\n", ii, ii);
98
      }
99
   }
100
 
101
 
102
 
103
 
104
//   fprintf(OutFileShiftOmega, "   numShifted,        // shift amount\n");
105
/*   for(ii=0; ii<(syndromeLength-1); ii++){
106
      if (ii < 10){
107
         fprintf(OutFileShiftOmega, "   omegaShifted_%d,    // omega shifted polynom %d\n", ii, ii);
108
      }else{
109
         fprintf(OutFileShiftOmega, "   omegaShifted_%d,   // omega shifted polynom %d\n", ii, ii);
110
      }
111
   }
112
   if ((syndromeLength-1) < 10){
113
         fprintf(OutFileShiftOmega, "   omegaShifted_%d     // omega shifted polynom %d\n", (syndromeLength-1), (syndromeLength-1));
114
   }else{
115
         fprintf(OutFileShiftOmega, "   omegaShifted_%d    // omega shifted polynom %d\n", (syndromeLength-1), (syndromeLength-1));
116
   }*/
117
   for(ii=0; ii<endPointer; ii++){
118
      if (ii < 10){
119
         fprintf(OutFileShiftOmega, "   omegaShifted_%d,    // omega shifted polynom %d\n", ii, ii);
120
      }else{
121
         fprintf(OutFileShiftOmega, "   omegaShifted_%d,   // omega shifted polynom %d\n", ii, ii);
122
      }
123
   }
124
 
125
   fprintf(OutFileShiftOmega, "   numShifted         // shift amount\n");
126
 
127
 
128
   fprintf(OutFileShiftOmega, ");\n\n\n");
129
 
130
/*   for(ii=0; ii<syndromeLength; ii++){
131
      if (ii < 10){
132
         fprintf(OutFileShiftOmega, "   input [%d:0] omega_%d;            // omega polynom %d\n", bitSymbol-1, ii, ii);
133
      }else{
134
         fprintf(OutFileShiftOmega, "   input [%d:0] omega_%d;           // omega polynom %d\n", bitSymbol-1, ii, ii);
135
      }
136
   }*/
137
   for(ii=startPointer; ii<syndromeLength; ii++){
138
      if (ii < 10){
139
         fprintf(OutFileShiftOmega, "   input [%d:0] omega_%d;            // omega polynom %d\n", bitSymbol-1, ii, ii);
140
      }else{
141
         fprintf(OutFileShiftOmega, "   input [%d:0] omega_%d;           // omega polynom %d\n", bitSymbol-1, ii, ii);
142
      }
143
   }
144
 
145
 
146
   if (syndromeLength > 2047) {
147
      fprintf(OutFileShiftOmega, "   input [11:0] numShifted;         // shift amount\n\n");
148
   }
149
   else if (syndromeLength > 1023) {
150
      fprintf(OutFileShiftOmega, "   input [10:0] numShifted;         // shift amount\n\n");
151
   }
152
   else if (syndromeLength > 511) {
153
      fprintf(OutFileShiftOmega, "   input [9:0] numShifted;         // shift amount\n\n");
154
   }
155
   else if (syndromeLength > 255) {
156
      fprintf(OutFileShiftOmega, "   input [8:0] numShifted;         // shift amount\n\n");
157
   }
158
   else if (syndromeLength > 127) {
159
      fprintf(OutFileShiftOmega, "   input [7:0] numShifted;         // shift amount\n\n");
160
   }
161
   else if (syndromeLength > 63) {
162
      fprintf(OutFileShiftOmega, "   input [6:0] numShifted;         // shift amount\n\n");
163
   }
164
   else if (syndromeLength > 31) {
165
      fprintf(OutFileShiftOmega, "   input [5:0] numShifted;         // shift amount\n\n");
166
   }
167
   else if (syndromeLength > 15) {
168
      fprintf(OutFileShiftOmega, "   input [4:0] numShifted;         // shift amount\n\n");
169
   }
170
   else if (syndromeLength > 7) {
171
      fprintf(OutFileShiftOmega, "   input [3:0] numShifted;         // shift amount\n\n");
172
   }
173
   else if (syndromeLength > 3) {
174
      fprintf(OutFileShiftOmega, "   input [2:0] numShifted;         // shift amount\n\n");
175
   }
176
   else {
177
      fprintf(OutFileShiftOmega, "   input [1:0] numShifted;         // shift amount\n\n");
178
   }
179
 
180
 
181
/*   for(ii=0; ii<syndromeLength; ii++){
182
      if (ii < 10){
183
         fprintf(OutFileShiftOmega, "   output [%d:0] omegaShifted_%d;    // omega shifted polynom %d\n", bitSymbol-1, ii, ii);
184
      }else{
185
         fprintf(OutFileShiftOmega, "   output [%d:0] omegaShifted_%d;   // omega shifted polynom %d\n", bitSymbol-1, ii, ii);
186
      }
187
   }*/
188
   for(ii=0; ii<endPointer; ii++){
189
      if (ii < 10){
190
         fprintf(OutFileShiftOmega, "   output [%d:0] omegaShifted_%d;    // omega shifted polynom %d\n", bitSymbol-1, ii, ii);
191
      }else{
192
         fprintf(OutFileShiftOmega, "   output [%d:0] omegaShifted_%d;   // omega shifted polynom %d\n", bitSymbol-1, ii, ii);
193
      }
194
   }
195
 
196
   fprintf(OutFileShiftOmega, "\n\n\n");
197
 
198
 
199
   //------------------------------------------------------------------------
200
   //+ omegaShifted_0 ... omegaShifted_xxx
201
   //- omegaShifted registers
202
   //------------------------------------------------------------------------
203
   fprintf(OutFileShiftOmega, "   //------------------------------------------------------------------------\n");
204
   fprintf(OutFileShiftOmega, "   //+ omegaShifted_0,..., omegaShifted_%d\n", syndromeLength-1);
205
   fprintf(OutFileShiftOmega, "   //- omegaShifted registers\n");
206
   fprintf(OutFileShiftOmega, "   //------------------------------------------------------------------------\n");
207
/*   for(ii=0; ii<syndromeLength; ii++){
208
      fprintf(OutFileShiftOmega, "   reg [%d:0]   omegaShiftedInner_%d;\n", bitSymbol-1, ii);
209
   }*/
210
   for(ii=0; ii<endPointer; ii++){
211
      fprintf(OutFileShiftOmega, "   reg [%d:0]   omegaShiftedInner_%d;\n", bitSymbol-1, ii);
212
   }
213
 
214
 
215
   fprintf(OutFileShiftOmega, "\n\n");
216
 
217
   fprintf(OutFileShiftOmega, "   always @ (numShifted");
218
/*   for(ii=0; ii<syndromeLength; ii++){
219
      fprintf(OutFileShiftOmega, " or omega_%d", ii);
220
   }*/
221
   for(ii=startPointer; ii<syndromeLength; ii++){
222
      fprintf(OutFileShiftOmega, " or omega_%d", ii);
223
   }
224
   fprintf(OutFileShiftOmega, " ) begin\n");
225
   fprintf(OutFileShiftOmega, "      case (numShifted)\n");
226
 
227
 
228
 
229
 
230
 
231
 
232
 
233
   //------------------------------------------------------------------------
234
   // omega shift register core
235
   //------------------------------------------------------------------------
236
//   for(ii=0; ii<syndromeLength; ii++){
237
   for(ii=startPointer; ii<syndromeLength; ii++){
238
      if (syndromeLength > 2047) {
239
         fprintf(OutFileShiftOmega, "         (12'd%d): begin\n", ii);
240
      }
241
      else if (syndromeLength > 1023) {
242
         fprintf(OutFileShiftOmega, "         (11'd%d): begin\n", ii);
243
      }
244
      else if (syndromeLength > 511) {
245
         fprintf(OutFileShiftOmega, "         (10'd%d): begin\n", ii);
246
      }
247
      else if (syndromeLength > 255) {
248
         fprintf(OutFileShiftOmega, "         (9'd%d): begin\n", ii);
249
      }
250
      else if (syndromeLength > 127) {
251
         fprintf(OutFileShiftOmega, "         (8'd%d): begin\n", ii);
252
      }
253
      else if (syndromeLength > 63) {
254
         fprintf(OutFileShiftOmega, "         (7'd%d): begin\n", ii);
255
      }
256
      else if (syndromeLength > 31) {
257
         fprintf(OutFileShiftOmega, "         (6'd%d): begin\n", ii);
258
      }
259
      else if (syndromeLength > 15) {
260
         fprintf(OutFileShiftOmega, "         (5'd%d): begin\n", ii);
261
      }
262
      else if (syndromeLength > 7) {
263
         fprintf(OutFileShiftOmega, "         (4'd%d): begin\n", ii);
264
      }
265
      else if (syndromeLength > 3) {
266
         fprintf(OutFileShiftOmega, "         (3'd%d): begin\n", ii);
267
      }
268
      else {
269
         fprintf(OutFileShiftOmega, "         (2'd%d): begin\n", ii);
270
      }
271
 
272
      index = ii;
273
//      for(jj=0; jj<syndromeLength; jj++){
274
      for(jj=0; jj<endPointer; jj++){
275
         if (jj < 10){
276
            fprintf(OutFileShiftOmega, "            omegaShiftedInner_%d [%d:0]  = ", jj, bitSymbol-1);
277
         }else{
278
            fprintf(OutFileShiftOmega, "            omegaShiftedInner_%d [%d:0] = ", jj, bitSymbol-1);
279
         }
280
         if (index < syndromeLength) {
281
            fprintf(OutFileShiftOmega, "omega_%d", index);
282
            fprintf(OutFileShiftOmega, " [%d:0];\n", bitSymbol-1);
283
            index ++;
284
         }else{
285
            fprintf(OutFileShiftOmega, "%d'd0;\n",bitSymbol);
286
         }
287
      }
288
      fprintf(OutFileShiftOmega, "         end\n", ii);
289
   }
290
 
291
 
292
   fprintf(OutFileShiftOmega, "         default: begin\n");
293
//   for(ii=0; ii<syndromeLength; ii++){
294
   for(ii=0; ii<endPointer; ii++){
295
      if (ii < 10){
296
         fprintf(OutFileShiftOmega, "            omegaShiftedInner_%d [%d:0]  = %d'd0;\n", ii, bitSymbol-1, bitSymbol);
297
      }else{
298
         fprintf(OutFileShiftOmega, "            omegaShiftedInner_%d [%d:0] = %d'd0;\n", ii, bitSymbol-1, bitSymbol);
299
      }
300
   }
301
 
302
   fprintf(OutFileShiftOmega, "         end\n");
303
   fprintf(OutFileShiftOmega, "        endcase\n");
304
   fprintf(OutFileShiftOmega, "    end\n");
305
   fprintf(OutFileShiftOmega, "\n\n\n");
306
 
307
 
308
  //---------------------------------------------------------------
309
  // Output Ports
310
  //---------------------------------------------------------------
311
   fprintf(OutFileShiftOmega, "   //------------------------------------------------------------------------\n");
312
   fprintf(OutFileShiftOmega, "   //- Output Ports\n");
313
   fprintf(OutFileShiftOmega, "   //------------------------------------------------------------------------\n");
314
//   for(ii=0; ii<syndromeLength; ii++){
315
   for(ii=0; ii<endPointer; ii++){
316
      if (ii < 10){
317
         fprintf(OutFileShiftOmega, "   assign omegaShifted_%d   = omegaShiftedInner_%d;\n", ii, ii);
318
      }else{
319
         fprintf(OutFileShiftOmega, "   assign omegaShifted_%d  = omegaShiftedInner_%d;\n", ii, ii);
320
      }
321
   }
322
   fprintf(OutFileShiftOmega, "\n\n\n");
323
   fprintf(OutFileShiftOmega, "endmodule\n");
324
 
325
 
326
  //---------------------------------------------------------------
327
  // close file
328
  //---------------------------------------------------------------
329
   fclose(OutFileShiftOmega);
330
 
331
 
332
   //---------------------------------------------------------------
333
   // automatically convert Dos mode To Unix mode
334
   //---------------------------------------------------------------
335
        char ch;
336
        char temp[MAX_PATH]="\0";
337
 
338
        //Open the file for reading in binarymode.
339
        ifstream fp_read(strRsDecodeShiftOmega, ios_base::in | ios_base::binary);
340
        sprintf(temp, "%s.temp", strRsDecodeShiftOmega);
341
        //Create a temporary file for writing in the binary mode. This
342
        //file will be created in the same directory as the input file.
343
        ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
344
 
345
        while(fp_read.eof() != true)
346
        {
347
                fp_read.get(ch);
348
                //Check for CR (carriage return)
349
                if((int)ch == 0x0D)
350
                        continue;
351
                if (!fp_read.eof())fp_write.put(ch);
352
        }
353
 
354
        fp_read.close();
355
        fp_write.close();
356
        //Delete the existing input file.
357
        remove(strRsDecodeShiftOmega);
358
        //Rename the temporary file to the input file.
359
        rename(temp, strRsDecodeShiftOmega);
360
        //Delete the temporary file.
361
        remove(temp);
362
 
363
 
364
   //---------------------------------------------------------------
365
   // clean string
366
   //---------------------------------------------------------------
367
   free(strRsDecodeShiftOmega);
368
 
369
 
370
}

powered by: WebSVN 2.1.0

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