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

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

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodePolymul
3
// File Name   : RsDecodePolymul.cpp
4
// Function    : RTL Decoder polymul 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
FILE  *OutFilePolymul;
22
 
23
 
24
void RsDecodePolymul(int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int pathFlag, int lengthPath, char *rootFolderPath) {
25
 
26
 
27
  //---------------------------------------------------------------
28
  // c++ variables
29
  //---------------------------------------------------------------
30
  int syndromeLength;
31
  int ii;
32
  int countSize;
33
  char *strRsDecodePolymul;
34
 
35
 
36
  syndromeLength = TotalSize - DataSize;
37
 
38
 
39
  //---------------------------------------------------------------
40
  // open file
41
  //---------------------------------------------------------------
42
   strRsDecodePolymul = (char *)calloc(lengthPath + 24,  sizeof(char));
43
   if (pathFlag == 0) {
44
        strRsDecodePolymul[0] = '.';
45
   }else{
46
      for(ii=0; ii<lengthPath; ii++){
47
         strRsDecodePolymul[ii] = rootFolderPath[ii];
48
      }
49
   }
50
   strcat(strRsDecodePolymul, "/rtl/RsDecodePolymul.v");
51
 
52
   OutFilePolymul = fopen(strRsDecodePolymul,"w");
53
 
54
 
55
  //---------------------------------------------------------------
56
  // Ports Declaration
57
  //---------------------------------------------------------------
58
   fprintf(OutFilePolymul, "//===================================================================\n");
59
   fprintf(OutFilePolymul, "// Module Name : RsDecodePolymul\n");
60
   fprintf(OutFilePolymul, "// File Name   : RsDecodePolymul.v\n");
61
   fprintf(OutFilePolymul, "// Function    : Rs Decoder polymul calculation Module\n");
62
   fprintf(OutFilePolymul, "// \n");
63
   fprintf(OutFilePolymul, "// Revision History:\n");
64
   fprintf(OutFilePolymul, "// Date          By           Version    Change Description\n");
65
   fprintf(OutFilePolymul, "//===================================================================\n");
66
   fprintf(OutFilePolymul, "// 2009/02/03  Gael Sapience     1.0       Original\n");
67
   fprintf(OutFilePolymul, "//\n");
68
   fprintf(OutFilePolymul, "//===================================================================\n");
69
   fprintf(OutFilePolymul, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
70
   fprintf(OutFilePolymul, "//\n\n\n");
71
 
72
 
73
   fprintf(OutFilePolymul, "module RsDecodePolymul(\n");
74
   fprintf(OutFilePolymul, "   CLK,              // system clock\n");
75
   fprintf(OutFilePolymul, "   RESET,            // system reset\n");
76
   fprintf(OutFilePolymul, "   enable,           // enable signal\n");
77
   fprintf(OutFilePolymul, "   sync,             // sync signal\n");
78
 
79
   for(ii=0; ii<syndromeLength; ii++){
80
      if (ii < 10) {
81
         fprintf(OutFilePolymul, "   syndromeIn_%d,     // syndrome polynom %d\n", ii, ii);
82
      }else{
83
         fprintf(OutFilePolymul, "   syndromeIn_%d,    // syndrome polynom %d\n", ii, ii);
84
      }
85
   }
86
   for(ii=0; ii<(syndromeLength+1); ii++){
87
      if (ii < 10) {
88
         fprintf(OutFilePolymul, "   epsilon_%d,        // epsilon polynom %d\n", ii, ii);
89
      }else{
90
         fprintf(OutFilePolymul, "   epsilon_%d,       // epsilon polynom %d\n", ii, ii);
91
      }
92
   }
93
   for(ii=0; ii<syndromeLength; ii++){
94
      if (ii < 10) {
95
         fprintf(OutFilePolymul, "   syndromeOut_%d,    // modified syndrome polynom %d\n", ii, ii);
96
      }else{
97
         fprintf(OutFilePolymul, "   syndromeOut_%d,   // modified syndrome polynom %d\n", ii, ii);
98
      }
99
   }
100
 
101
   fprintf(OutFilePolymul, "   done              // done signal\n");
102
   fprintf(OutFilePolymul, ");\n\n\n");
103
 
104
 
105
   fprintf(OutFilePolymul, "   input          CLK;              // system clock\n");
106
   fprintf(OutFilePolymul, "   input          RESET;            // system reset\n");
107
   fprintf(OutFilePolymul, "   input          enable;           // enable signal\n");
108
   fprintf(OutFilePolymul, "   input          sync;             // sync signal\n");
109
 
110
   for(ii=0; ii<syndromeLength; ii++){
111
      if (ii < 10) {
112
         fprintf(OutFilePolymul, "   input  [%d:0]   syndromeIn_%d;     // syndrome polynom %d\n",bitSymbol-1, ii, ii);
113
      }else{
114
         fprintf(OutFilePolymul, "   input  [%d:0]   syndromeIn_%d;    // syndrome polynom %d\n",bitSymbol-1, ii, ii);
115
      }
116
   }
117
   for(ii=0; ii<(syndromeLength+1); ii++){
118
      if (ii < 10) {
119
         fprintf(OutFilePolymul, "   input  [%d:0]   epsilon_%d;        // epsilon polynom %d\n",bitSymbol-1, ii, ii);
120
      }else{
121
         fprintf(OutFilePolymul, "   input  [%d:0]   epsilon_%d;       // epsilon polynom %d\n",bitSymbol-1, ii, ii);
122
      }
123
   }
124
   fprintf(OutFilePolymul, "\n");
125
 
126
   for(ii=0; ii<syndromeLength; ii++){
127
      if (ii < 10) {
128
         fprintf(OutFilePolymul, "   output [%d:0]   syndromeOut_%d;    // modified syndrome polynom %d\n",bitSymbol-1, ii, ii);
129
      }else{
130
         fprintf(OutFilePolymul, "   output [%d:0]   syndromeOut_%d;   // modified syndrome polynom %d\n",bitSymbol-1, ii, ii);
131
      }
132
   }
133
 
134
   fprintf(OutFilePolymul, "   output         done;             // done signal\n\n\n");
135
   fprintf(OutFilePolymul, "\n\n\n");
136
 
137
 
138
   //------------------------------------------------------------------------
139
   // + count
140
   //- Counter
141
   //------------------------------------------------------------------------
142
   countSize = 0;
143
 
144
   if ((syndromeLength+1) > 2047) {
145
      countSize = 12;
146
   } else{
147
      if ((syndromeLength+1) > 1023) {
148
         countSize = 11;
149
      } else{
150
         if ((syndromeLength+1) > 511) {
151
            countSize = 10;
152
         }else{
153
            if ((syndromeLength+1) > 255) {
154
               countSize = 9;
155
            }else{
156
               if ((syndromeLength+1) > 127) {
157
                  countSize = 8;
158
               }else{
159
                  if ((syndromeLength+1) > 63) {
160
                     countSize = 7;
161
                  }else{
162
                     if ((syndromeLength+1) > 31) {
163
                        countSize = 6;
164
                     }else{
165
                        if ((syndromeLength+1) > 15) {
166
                           countSize = 5;
167
                        }else{
168
                           if ((syndromeLength+1) > 7) {
169
                              countSize = 4;
170
                           }else{
171
                              if ((syndromeLength+1) > 3) {
172
                                 countSize = 3;
173
                              }else{
174
                                 countSize = 2;
175
                              }
176
                           }
177
                        }
178
                     }
179
                  }
180
               }
181
            }
182
         }
183
      }
184
   }
185
 
186
 
187
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
188
   fprintf(OutFilePolymul, "   // + count\n");
189
   fprintf(OutFilePolymul, "   //- Counter\n");
190
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
191
//   fprintf(OutFilePolymul, "   reg    [%d:0]   count;\n",bitSymbol);
192
   fprintf(OutFilePolymul, "   reg    [%d:0]   count;\n",countSize -1);
193
   fprintf(OutFilePolymul, "   always @(posedge CLK or negedge RESET) begin\n");
194
   fprintf(OutFilePolymul, "      if (~RESET) begin\n");
195
//   fprintf(OutFilePolymul, "         count [%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
196
   fprintf(OutFilePolymul, "         count [%d:0] <= %d'd0;\n",countSize-1,countSize);
197
   fprintf(OutFilePolymul, "      end\n");
198
   fprintf(OutFilePolymul, "      else if (enable == 1'b1) begin\n");
199
   fprintf(OutFilePolymul, "         if (sync == 1'b1) begin\n");
200
//   fprintf(OutFilePolymul, "            if (count[%d:0]==%d'd0) begin\n",bitSymbol,bitSymbol+1);
201
/*   fprintf(OutFilePolymul, "            if (count[%d:0]==%d'd0) begin\n",countSize-1,countSize);
202
//   fprintf(OutFilePolymul, "               count[%d:0] <= %d'd1;\n",bitSymbol,bitSymbol+1);
203
   fprintf(OutFilePolymul, "               count[%d:0] <= %d'd1;\n",countSize-1,countSize);
204
   fprintf(OutFilePolymul, "            end\n");
205
   fprintf(OutFilePolymul, "            else begin\n");
206
//   fprintf(OutFilePolymul, "               count[%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
207
   fprintf(OutFilePolymul, "               count[%d:0] <= %d'd0;\n",countSize-1,countSize);
208
   fprintf(OutFilePolymul, "            end\n");*/
209
   fprintf(OutFilePolymul, "            count[%d:0] <= %d'd1;\n",countSize-1,countSize);
210
   fprintf(OutFilePolymul, "         end\n");
211
//   fprintf(OutFilePolymul, "         else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n",bitSymbol,bitSymbol+1,bitSymbol,bitSymbol+1, (syndromeLength+1));
212
   fprintf(OutFilePolymul, "         else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n",countSize-1,countSize,countSize-1,countSize, (syndromeLength+1));
213
//   fprintf(OutFilePolymul, "            count[%d:0] <= %d'd0;\n",bitSymbol,bitSymbol+1);
214
   fprintf(OutFilePolymul, "            count[%d:0] <= %d'd0;\n",countSize-1,countSize);
215
   fprintf(OutFilePolymul, "         end\n");
216
   fprintf(OutFilePolymul, "         else begin\n");
217
//   fprintf(OutFilePolymul, "            count[%d:0] <= count[%d:0] + %d'd1;\n",bitSymbol,bitSymbol,bitSymbol+1);
218
   fprintf(OutFilePolymul, "            count[%d:0] <= count[%d:0] + %d'd1;\n",countSize-1,countSize-1,countSize);
219
   fprintf(OutFilePolymul, "         end\n");
220
   fprintf(OutFilePolymul, "      end\n");
221
   fprintf(OutFilePolymul, "   end\n");
222
   fprintf(OutFilePolymul, "\n\n");
223
 
224
 
225
   //------------------------------------------------------------------------
226
   // + done
227
   //------------------------------------------------------------------------
228
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
229
   fprintf(OutFilePolymul, "   // + done\n");
230
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
231
   fprintf(OutFilePolymul, "   reg         done;\n");
232
   fprintf(OutFilePolymul, "   always @(count) begin\n");
233
//   fprintf(OutFilePolymul, "      if (count[%d:0] == %d'd%d) begin\n",bitSymbol,bitSymbol+1,(syndromeLength+1));
234
   fprintf(OutFilePolymul, "      if (count[%d:0] == %d'd%d) begin\n",countSize-1,countSize,(syndromeLength+1));
235
   fprintf(OutFilePolymul, "         done = 1'b1;\n");
236
   fprintf(OutFilePolymul, "      end\n");
237
   fprintf(OutFilePolymul, "      else begin\n");
238
   fprintf(OutFilePolymul, "         done = 1'b0;\n");
239
   fprintf(OutFilePolymul, "      end\n");
240
   fprintf(OutFilePolymul, "   end\n");
241
   fprintf(OutFilePolymul, "\n\n");
242
 
243
 
244
   //------------------------------------------------------------------------
245
   // + syndromeReg_0,..., syndromeReg_xxx
246
   //------------------------------------------------------------------------
247
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
248
   fprintf(OutFilePolymul, "   // + syndromeReg_0,..., syndromeReg_%d\n", syndromeLength-1);
249
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
250
   for(ii=0; ii<syndromeLength; ii++){
251
      fprintf(OutFilePolymul, "   reg [%d:0]   syndromeReg_%d;\n",bitSymbol-1,ii);
252
   }
253
   fprintf(OutFilePolymul, "\n\n");
254
 
255
 
256
   fprintf(OutFilePolymul, "   always @(posedge CLK or negedge RESET) begin\n");
257
   fprintf(OutFilePolymul, "      if (~RESET) begin\n");
258
   for(ii=0; ii<syndromeLength; ii++){
259
      if (ii < 10) {
260
         fprintf(OutFilePolymul, "         syndromeReg_%d [%d:0]  <= %d'd0;\n",ii,bitSymbol-1,bitSymbol);
261
      }else{
262
         fprintf(OutFilePolymul, "         syndromeReg_%d [%d:0] <= %d'd0;\n",ii,bitSymbol-1,bitSymbol);
263
      }
264
   }
265
   fprintf(OutFilePolymul, "      end \n");
266
   fprintf(OutFilePolymul, "      else if ((enable == 1'b1) && (sync == 1'b1)) begin\n");
267
   for(ii=0; ii<syndromeLength; ii++){
268
      if (ii < 10) {
269
         fprintf(OutFilePolymul, "         syndromeReg_%d [%d:0]  <= syndromeIn_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
270
      }else{
271
         fprintf(OutFilePolymul, "         syndromeReg_%d [%d:0] <= syndromeIn_%d [%d:0];\n",ii,bitSymbol-1,ii,bitSymbol-1);
272
      }
273
   }
274
   fprintf(OutFilePolymul, "      end\n");
275
   fprintf(OutFilePolymul, "   end\n");
276
 
277
 
278
   //------------------------------------------------------------------------
279
   // + epsilonReg_0,..., epsilonReg_xxx
280
   //------------------------------------------------------------------------
281
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
282
   fprintf(OutFilePolymul, "   // + epsilonReg_0,..., epsilonReg_%d\n", syndromeLength);
283
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
284
 
285
   for(ii=0; ii<(syndromeLength+1); ii++){
286
      fprintf(OutFilePolymul, "   reg [%d:0]   epsilonReg_%d;\n",bitSymbol-1,ii);
287
   }
288
   fprintf(OutFilePolymul, "\n");
289
 
290
   fprintf(OutFilePolymul, "   always @(posedge CLK or negedge RESET) begin\n");
291
   fprintf(OutFilePolymul, "      if (~RESET) begin\n");
292
   for(ii=0; ii<(syndromeLength+1); ii++){
293
      if (ii < 10) {
294
         fprintf(OutFilePolymul, "         epsilonReg_%d [%d:0]  <= %d'd0;\n",ii,bitSymbol-1,bitSymbol);
295
      }else{
296
         fprintf(OutFilePolymul, "         epsilonReg_%d [%d:0] <= %d'd0;\n",ii,bitSymbol-1,bitSymbol);
297
      }
298
   }
299
   fprintf(OutFilePolymul, "      end\n");
300
   fprintf(OutFilePolymul, "      else if (enable == 1'b1) begin\n");
301
   fprintf(OutFilePolymul, "         if (sync == 1'b1) begin\n");
302
   fprintf(OutFilePolymul, "            epsilonReg_0 [%d:0]  <= %d'd0;\n",bitSymbol-1,bitSymbol);
303
   for(ii=1; ii<(syndromeLength+1); ii++){
304
      if (ii < 10) {
305
         fprintf(OutFilePolymul, "            epsilonReg_%d [%d:0]  <= epsilon_%d[%d:0];\n",ii,bitSymbol-1,(ii-1),bitSymbol-1);
306
      }else{
307
         fprintf(OutFilePolymul, "            epsilonReg_%d [%d:0] <= epsilon_%d[%d:0];\n",ii,bitSymbol-1,(ii-1),bitSymbol-1);
308
      }
309
   }
310
   fprintf(OutFilePolymul, "         end\n");
311
   fprintf(OutFilePolymul, "         else begin\n");
312
   fprintf(OutFilePolymul, "            epsilonReg_0 [%d:0]  <= %d'd0;\n",bitSymbol-1,bitSymbol);
313
   for(ii=1; ii<(syndromeLength+1); ii++){
314
      if (ii < 10) {
315
         fprintf(OutFilePolymul, "            epsilonReg_%d [%d:0]  <= epsilonReg_%d[%d:0];\n",ii,bitSymbol-1,(ii-1),bitSymbol-1);
316
      }else{
317
         fprintf(OutFilePolymul, "            epsilonReg_%d [%d:0] <= epsilonReg_%d[%d:0];\n",ii,bitSymbol-1,(ii-1),bitSymbol-1);
318
      }
319
   }
320
   fprintf(OutFilePolymul, "         end\n");
321
   fprintf(OutFilePolymul, "      end\n");
322
   fprintf(OutFilePolymul, "   end\n");
323
   fprintf(OutFilePolymul, "\n\n");
324
 
325
 
326
   //------------------------------------------------------------------------
327
   // + epsilonMsb
328
   //------------------------------------------------------------------------
329
   fprintf(OutFilePolymul, "    //------------------------------------------------------------------------\n");
330
   fprintf(OutFilePolymul, "    // + epsilonMsb\n");
331
   fprintf(OutFilePolymul, "    //------------------------------------------------------------------------\n");
332
   fprintf(OutFilePolymul, "    reg [%d:0]   epsilonMsb;\n",bitSymbol-1);
333
   fprintf(OutFilePolymul, "\n");
334
   fprintf(OutFilePolymul, "   always @(sync");
335
   fprintf(OutFilePolymul, " or epsilon_%d",syndromeLength);
336
   fprintf(OutFilePolymul, " or epsilonReg_%d",syndromeLength);
337
   fprintf(OutFilePolymul, " ) begin\n");
338
   fprintf(OutFilePolymul, "      if (sync == 1'b1) begin\n");
339
   fprintf(OutFilePolymul, "         epsilonMsb [%d:0] = epsilon_%d [%d:0];\n",bitSymbol-1, syndromeLength,bitSymbol-1);
340
   fprintf(OutFilePolymul, "      end\n");
341
   fprintf(OutFilePolymul, "      else begin\n");
342
   fprintf(OutFilePolymul, "         epsilonMsb [%d:0] = epsilonReg_%d [%d:0];\n",bitSymbol-1, syndromeLength,bitSymbol-1);
343
   fprintf(OutFilePolymul, "      end\n");
344
   fprintf(OutFilePolymul, "   end\n");
345
   fprintf(OutFilePolymul, "\n\n");
346
 
347
 
348
   //------------------------------------------------------------------------
349
   // + product_0,..., product_xxx
350
   //------------------------------------------------------------------------
351
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
352
   fprintf(OutFilePolymul, "   // + product_0,..., product_%d\n", syndromeLength-1);
353
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
354
 
355
   for(ii=0; ii<(syndromeLength); ii++){
356
      fprintf(OutFilePolymul, "   wire [%d:0]   product_%d;\n",bitSymbol-1, ii);
357
   }
358
   fprintf(OutFilePolymul, "\n\n");
359
 
360
 
361
   for(ii=0; ii<(syndromeLength); ii++){
362
      if (ii < 10) {
363
         fprintf(OutFilePolymul, "    RsDecodeMult  RsDecodeMult_%d  (  .A(epsilonMsb[%d:0]), .B(syndromeReg_%d[%d:0]), .P(product_%d[%d:0]));\n", ii,bitSymbol-1, ii,bitSymbol-1, ii,bitSymbol-1);
364
      }else{
365
         fprintf(OutFilePolymul, "    RsDecodeMult  RsDecodeMult_%d (  .A(epsilonMsb[%d:0]), .B(syndromeReg_%d[%d:0]), .P(product_%d[%d:0]));\n", ii,bitSymbol-1, ii,bitSymbol-1, ii,bitSymbol-1);
366
      }
367
   }
368
   fprintf(OutFilePolymul, "\n\n\n");
369
 
370
 
371
   //------------------------------------------------------------------------
372
   // + sumReg_0,..., sumReg_xxx
373
   //------------------------------------------------------------------------
374
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
375
   fprintf(OutFilePolymul, "   // + sumReg_0,..., sumReg_%d\n", syndromeLength-1);
376
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
377
   for(ii=0; ii<(syndromeLength); ii++){
378
      fprintf(OutFilePolymul, "   reg [%d:0]   sumReg_%d;\n",bitSymbol-1, ii);
379
   }
380
 
381
   fprintf(OutFilePolymul, "\n\n");
382
 
383
   fprintf(OutFilePolymul, "   always @(posedge CLK or negedge RESET) begin\n");
384
   fprintf(OutFilePolymul, "      if (~RESET) begin\n");
385
   for(ii=0; ii<(syndromeLength); ii++){
386
      if (ii < 10) {
387
         fprintf(OutFilePolymul, "         sumReg_%d [%d:0]  <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
388
      }else{
389
         fprintf(OutFilePolymul, "         sumReg_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
390
      }
391
   }
392
   fprintf(OutFilePolymul, "      end\n");
393
   fprintf(OutFilePolymul, "      else if (enable == 1'b1) begin\n");
394
   fprintf(OutFilePolymul, "         if (sync == 1'b1) begin\n");
395
   fprintf(OutFilePolymul, "            if (epsilon_%d[%d:0] != %d'd0) begin\n", syndromeLength,bitSymbol-1,bitSymbol);
396
   for(ii=0; ii<(syndromeLength); ii++){
397
      if (ii < 10) {
398
         fprintf(OutFilePolymul, "               sumReg_%d [%d:0]  <= syndromeIn_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
399
      }else{
400
         fprintf(OutFilePolymul, "               sumReg_%d [%d:0] <= syndromeIn_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
401
      }
402
   }
403
 
404
   fprintf(OutFilePolymul, "            end\n");
405
   fprintf(OutFilePolymul, "            else begin\n");
406
 
407
   for(ii=0; ii<(syndromeLength); ii++){
408
      if (ii < 10) {
409
         fprintf(OutFilePolymul, "               sumReg_%d [%d:0]  <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
410
      }else{
411
         fprintf(OutFilePolymul, "               sumReg_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
412
      }
413
   }
414
 
415
   fprintf(OutFilePolymul, "            end\n");
416
   fprintf(OutFilePolymul, "         end\n");
417
   fprintf(OutFilePolymul, "         else begin\n");
418
   fprintf(OutFilePolymul, "            sumReg_0 [%d:0]  <= product_0 [%d:0];\n",bitSymbol-1,bitSymbol-1);
419
 
420
   for(ii=1; ii<(syndromeLength); ii++){
421
      if (ii<10){
422
         fprintf(OutFilePolymul, "            sumReg_%d  [%d:0] <= sumReg_%d  [%d:0] ^ product_%d  [%d:0];\n", ii,bitSymbol-1, (ii-1),bitSymbol-1, ii,bitSymbol-1);
423
      }else{
424
         fprintf(OutFilePolymul, "            sumReg_%d [%d:0] <= sumReg_%d [%d:0] ^ product_%d [%d:0];\n", ii,bitSymbol-1, (ii-1),bitSymbol-1, ii,bitSymbol-1);
425
      }
426
   }
427
 
428
   fprintf(OutFilePolymul, "         end\n");
429
   fprintf(OutFilePolymul, "      end\n");
430
   fprintf(OutFilePolymul, "   end\n");
431
   fprintf(OutFilePolymul, "\n\n\n");
432
 
433
 
434
   //------------------------------------------------------------------------
435
   //- Output Ports
436
   //------------------------------------------------------------------------
437
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
438
   fprintf(OutFilePolymul, "   // Output signals\n");
439
   fprintf(OutFilePolymul, "   //------------------------------------------------------------------------\n");
440
 
441
   for(ii=0; ii<(syndromeLength); ii++){
442
      if (ii<10){
443
         fprintf(OutFilePolymul, "   assign   syndromeOut_%d  [%d:0] = sumReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
444
      }else{
445
         fprintf(OutFilePolymul, "   assign   syndromeOut_%d [%d:0] = sumReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
446
      }
447
   }
448
   fprintf(OutFilePolymul, "\n\n");
449
   fprintf(OutFilePolymul, "endmodule\n");
450
 
451
  //---------------------------------------------------------------
452
  // close file
453
  //---------------------------------------------------------------
454
   fclose(OutFilePolymul);
455
 
456
 
457
   //---------------------------------------------------------------
458
   // automatically convert Dos mode To Unix mode
459
   //---------------------------------------------------------------
460
        char ch;
461
        char temp[MAX_PATH]="\0";
462
 
463
        //Open the file for reading in binarymode.
464
        ifstream fp_read(strRsDecodePolymul, ios_base::in | ios_base::binary);
465
        sprintf(temp, "%s.temp", strRsDecodePolymul);
466
        //Create a temporary file for writing in the binary mode. This
467
        //file will be created in the same directory as the input file.
468
        ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
469
 
470
        while(fp_read.eof() != true)
471
        {
472
                fp_read.get(ch);
473
                //Check for CR (carriage return)
474
                if((int)ch == 0x0D)
475
                        continue;
476
                if (!fp_read.eof())fp_write.put(ch);
477
        }
478
 
479
        fp_read.close();
480
        fp_write.close();
481
        //Delete the existing input file.
482
        remove(strRsDecodePolymul);
483
        //Rename the temporary file to the input file.
484
        rename(temp, strRsDecodePolymul);
485
        //Delete the temporary file.
486
        remove(temp);
487
 
488
 
489
   //---------------------------------------------------------------
490
   // clean string
491
   //---------------------------------------------------------------
492
   free(strRsDecodePolymul);
493
 
494
 
495
}

powered by: WebSVN 2.1.0

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