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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 issei
//===================================================================
2
// Module Name : RsDecodeTop
3
// File Name   : RsDecodeTop.cpp
4
// Function    : RTL Decoder Top 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  *OutFileTop;
22
 
23
 
24
void RsDecodeTop(int DataSize, int TotalSize, int PrimPoly, int ErasureOption, int bitSymbol, int errorStats, int passFailFlag, int delayDataIn, int pathFlag, int lengthPath, char *rootFolderPath) {
25
 
26
 
27
   //---------------------------------------------------------------
28
   // C++ variables
29
   //---------------------------------------------------------------
30
   int syndromeLength;
31
   int indexSyndrome;
32
   int startPointer;
33
   int endPointer;
34
   int shiftPointer;
35
   syndromeLength = TotalSize - DataSize;
36
 
37
   int ii;
38
   int degreeTemp;
39
   char *strRsDecodeTop;
40
 
41
   //---------------------------------------------------------------
42
   // open file
43
   //---------------------------------------------------------------
44
   strRsDecodeTop = (char *)calloc(lengthPath + 19,  sizeof(char));
45
   if (pathFlag == 0) {
46
        strRsDecodeTop[0] = '.';
47
   }else{
48
      for(ii=0; ii<lengthPath; ii++){
49
         strRsDecodeTop[ii] = rootFolderPath[ii];
50
      }
51
   }
52
   strcat(strRsDecodeTop, "/rtl/RsDecodeTop.v");
53
 
54
   OutFileTop = fopen(strRsDecodeTop,"w");
55
 
56
 
57
   //---------------------------------------------------------------
58
   // Ports Declaration
59
   //---------------------------------------------------------------
60
   fprintf(OutFileTop, "//===================================================================\n");
61
   fprintf(OutFileTop, "// Module Name : RsDecodeTop\n");
62
   fprintf(OutFileTop, "// File Name   : RsDecodeTop.v\n");
63
   fprintf(OutFileTop, "// Function    : Rs Decoder Top Module\n");
64
   fprintf(OutFileTop, "// \n");
65
   fprintf(OutFileTop, "// Revision History:\n");
66
   fprintf(OutFileTop, "// Date          By           Version    Change Description\n");
67
   fprintf(OutFileTop, "//===================================================================\n");
68
   fprintf(OutFileTop, "// 2009/02/03  Gael Sapience     1.0       Original\n");
69
   fprintf(OutFileTop, "//\n");
70
   fprintf(OutFileTop, "//===================================================================\n");
71
   fprintf(OutFileTop, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
72
   fprintf(OutFileTop, "//\n\n\n");
73
 
74
 
75
   fprintf(OutFileTop, "module RsDecodeTop(\n");
76
   fprintf(OutFileTop, "   // Inputs\n");
77
   fprintf(OutFileTop, "   CLK,            // system clock\n");
78
   fprintf(OutFileTop, "   RESET,          // system reset\n");
79
   fprintf(OutFileTop, "   enable,         // system enable\n");
80
   fprintf(OutFileTop, "   startPls,       // sync signal\n");
81
   if (ErasureOption == 1) {
82
      fprintf(OutFileTop, "   erasureIn,      // erasure input\n");
83
   }
84
 
85
 
86
   fprintf(OutFileTop, "   dataIn,         // data input\n");
87
   fprintf(OutFileTop, "   // Outputs\n");
88
   fprintf(OutFileTop, "   outEnable,      // data out valid signal\n");
89
   fprintf(OutFileTop, "   outStartPls,    // first decoded symbol trigger\n");
90
   fprintf(OutFileTop, "   outDone,        // last symbol decoded trigger\n");
91
 
92
   if (errorStats == 1) {
93
   fprintf(OutFileTop, "   errorNum,       // number of errors corrected\n");
94
      if (ErasureOption == 1) {
95
         fprintf(OutFileTop, "   erasureNum,     // number of erasure corrected\n");
96
      }
97
   }
98
 
99
   if (passFailFlag == 1){
100
      fprintf(OutFileTop, "   fail,           // decoding failure signal\n");
101
   }
102
   if (delayDataIn == 1){
103
      fprintf(OutFileTop, "   delayedData,    // decoding failure signal\n");
104
   }
105
 
106
   fprintf(OutFileTop, "   outData         // data output\n");
107
   fprintf(OutFileTop, ");\n\n\n");
108
 
109
 
110
   //---------------------------------------------------------------
111
   // I/O instantiation
112
   //---------------------------------------------------------------
113
   fprintf(OutFileTop, "   input          CLK;            // system clock\n");
114
   fprintf(OutFileTop, "   input          RESET;          // system reset\n");
115
   fprintf(OutFileTop, "   input          enable;         // system enable\n");
116
   fprintf(OutFileTop, "   input          startPls;       // sync signal\n");
117
   if (ErasureOption == 1) {
118
      fprintf(OutFileTop, "   input          erasureIn;      // erasure input\n");
119
   }
120
 
121
   fprintf(OutFileTop, "   input  [%d:0]   dataIn;         // data input\n", bitSymbol-1);
122
   fprintf(OutFileTop, "   output         outEnable;      // data out valid signal\n");
123
   fprintf(OutFileTop, "   output         outStartPls;    // first decoded symbol trigger\n");
124
   fprintf(OutFileTop, "   output         outDone;        // last symbol decoded trigger\n");
125
 
126
   if (errorStats == 1) {
127
      fprintf(OutFileTop, "   output [%d:0]   errorNum;       // number of errors corrected\n", bitSymbol-1);
128
      if (ErasureOption == 1) {
129
         fprintf(OutFileTop, "   output [%d:0]   erasureNum;     // number of erasure corrected\n", bitSymbol-1);
130
      }
131
   }
132
 
133
 
134
   if (passFailFlag == 1){
135
      fprintf(OutFileTop, "   output         fail;           // decoding failure signal\n");
136
   }
137
   if (delayDataIn == 1){
138
      fprintf(OutFileTop, "   output [%d:0]   delayedData;    // delayed input data\n", bitSymbol-1);
139
   }
140
 
141
   fprintf(OutFileTop, "   output [%d:0]   outData;        // data output\n", bitSymbol-1);
142
 
143
 
144
   fprintf(OutFileTop, "\n\n\n");
145
 
146
 
147
   //------------------------------------------------------------------------
148
   // + dataInCheck
149
   //- assign to 0 if Erasure
150
   //------------------------------------------------------------------------
151
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
152
   fprintf(OutFileTop, "   // + dataInCheck\n");
153
   fprintf(OutFileTop, "   //- assign to 0 if Erasure\n");
154
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
155
   fprintf(OutFileTop, "   wire [%d:0]   dataInCheck;\n\n", bitSymbol-1);
156
 
157
   if (ErasureOption == 1) {
158
      fprintf(OutFileTop, "   assign dataInCheck = (erasureIn == 1'b0) ? dataIn : %d'd0;\n", bitSymbol);
159
   } else {
160
      fprintf(OutFileTop, "   assign dataInCheck = dataIn;\n");
161
   }
162
   fprintf(OutFileTop, "\n\n\n");
163
 
164
 
165
 
166
   //------------------------------------------------------------------
167
   // + syndrome_0,...,syndrome_xxx
168
   // + doneSyndrome
169
   //- RS Syndrome calculation
170
   //------------------------------------------------------------------
171
   fprintf(OutFileTop, "    //------------------------------------------------------------------\n");
172
   fprintf(OutFileTop, "    // + syndrome_0,...,syndrome_%d\n", syndromeLength-1);
173
   fprintf(OutFileTop, "    // + doneSyndrome\n");
174
   fprintf(OutFileTop, "    //- RS Syndrome calculation\n");
175
   fprintf(OutFileTop, "    //------------------------------------------------------------------\n");
176
   for(ii=0; ii<syndromeLength; ii++){
177
      fprintf(OutFileTop, "    wire [%d:0]   syndrome_%d;\n", bitSymbol-1, ii);
178
   }
179
   fprintf(OutFileTop, "    wire         doneSyndrome;\n");
180
   fprintf(OutFileTop, "\n\n");
181
 
182
 
183
   fprintf(OutFileTop, "   RsDecodeSyndrome RsDecodeSyndrome(\n");
184
   fprintf(OutFileTop, "      // Inputs\n");
185
   fprintf(OutFileTop, "      .CLK           (CLK),\n");
186
   fprintf(OutFileTop, "      .RESET         (RESET),\n");
187
   fprintf(OutFileTop, "      .enable        (enable),\n");
188
   fprintf(OutFileTop, "      .sync          (startPls),\n");
189
   fprintf(OutFileTop, "      .dataIn        (dataInCheck),\n");
190
   fprintf(OutFileTop, "      // Outputs\n");
191
   for(ii=0; ii<syndromeLength; ii++){
192
      if (ii<10){
193
         fprintf(OutFileTop, "      .syndrome_%d    (syndrome_%d),\n", ii, ii);
194
      }else{
195
         fprintf(OutFileTop, "      .syndrome_%d   (syndrome_%d),\n", ii, ii);
196
      }
197
   }
198
   fprintf(OutFileTop, "      .done          (doneSyndrome)\n");
199
   fprintf(OutFileTop, "   );\n");
200
   fprintf(OutFileTop, "\n\n\n");
201
 
202
 
203
   //------------------------------------------------------------------
204
   // indexSyndrome calculation
205
   //------------------------------------------------------------------
206
   if (syndromeLength > 2047) {
207
      indexSyndrome = 11;
208
   }
209
   else if (syndromeLength > 1023) {
210
      indexSyndrome = 10;
211
   }
212
   else if (syndromeLength > 511) {
213
      indexSyndrome = 9;
214
   }
215
   else if (syndromeLength > 255) {
216
      indexSyndrome = 8;
217
   }
218
   else if (syndromeLength > 127) {
219
      indexSyndrome = 7;
220
   }
221
   else if  (syndromeLength > 63) {
222
      indexSyndrome = 6;
223
   }
224
   else if  (syndromeLength > 31) {
225
      indexSyndrome = 5;
226
   }
227
   else if  (syndromeLength > 15) {
228
      indexSyndrome = 4;
229
   }
230
   else if  (syndromeLength > 7) {
231
      indexSyndrome = 3;
232
   }
233
   else if  (syndromeLength > 3) {
234
      indexSyndrome = 2;
235
   }
236
   else {
237
      indexSyndrome = 1;
238
   }
239
 
240
 
241
   //------------------------------------------------------------------
242
   // + epsilon_0,..., epsilon_xxx
243
   // + degreeEpsilon, failErasure, doneErasure
244
   //- RS Erasure calculation
245
   //------------------------------------------------------------------
246
   if (ErasureOption == 1) {
247
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
248
      fprintf(OutFileTop, "   // + epsilon_0,..., epsilon_%d\n", syndromeLength);
249
      fprintf(OutFileTop, "   // + degreeEpsilon, failErasure, doneErasure\n");
250
      fprintf(OutFileTop, "   //- RS Erasure calculation\n");
251
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
252
      for(ii=0; ii<(syndromeLength+1); ii++){
253
         fprintf(OutFileTop, "   wire [%d:0]   epsilon_%d;\n", bitSymbol-1, ii);
254
      }
255
 
256
      fprintf(OutFileTop, "   wire [%d:0]   degreeEpsilon;\n", indexSyndrome);
257
 
258
      if (passFailFlag == 1){
259
         fprintf(OutFileTop, "   wire         failErasure;\n");
260
      }
261
      fprintf(OutFileTop, "   wire         doneErasure;\n");
262
   }
263
   fprintf(OutFileTop, "\n\n");
264
 
265
 
266
   if (ErasureOption == 1) {
267
      fprintf(OutFileTop, "   RsDecodeErasure RsDecodeErasure(\n");
268
      fprintf(OutFileTop, "      // Inputs\n");
269
      fprintf(OutFileTop, "      .CLK          (CLK),\n");
270
      fprintf(OutFileTop, "      .RESET        (RESET),\n");
271
      fprintf(OutFileTop, "      .enable       (enable),\n");
272
      fprintf(OutFileTop, "      .sync         (startPls),\n");
273
      fprintf(OutFileTop, "      .erasureIn    (erasureIn),\n");
274
      fprintf(OutFileTop, "      // Outputs\n");
275
      for(ii=0; ii<(syndromeLength+1); ii++){
276
         if (ii<10){
277
            fprintf(OutFileTop, "      .epsilon_%d    (epsilon_%d),\n", ii ,ii);
278
         }else{
279
            fprintf(OutFileTop, "      .epsilon_%d   (epsilon_%d),\n", ii ,ii);
280
         }
281
      }
282
      fprintf(OutFileTop, "      .numErasure   (degreeEpsilon),\n");
283
      if (passFailFlag == 1){
284
         fprintf(OutFileTop, "      .fail         (failErasure),\n");
285
      }
286
      fprintf(OutFileTop, "      .done         (doneErasure)\n");
287
      fprintf(OutFileTop, "   );\n");
288
   }
289
   fprintf(OutFileTop, "\n\n\n");
290
 
291
 
292
   //------------------------------------------------------------------
293
   // + polymulSyndrome_0,..., polymulSyndrome_xxx
294
   // + donePolymul
295
   //- RS Polymul calculation
296
   //------------------------------------------------------------------
297
   if (ErasureOption == 1) {
298
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
299
      fprintf(OutFileTop, "   // + polymulSyndrome_0,..., polymulSyndrome_%d\n",syndromeLength-1);
300
      fprintf(OutFileTop, "   // + donePolymul\n");
301
      fprintf(OutFileTop, "   //- RS Polymul calculation\n");
302
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
303
      for(ii=0; ii<syndromeLength; ii++){
304
         fprintf(OutFileTop, "    wire [%d:0]   polymulSyndrome_%d;\n",bitSymbol -1, ii);
305
      }
306
      fprintf(OutFileTop, "    wire         donePolymul;\n");
307
      fprintf(OutFileTop, "\n\n");
308
   }
309
 
310
 
311
   if (ErasureOption == 1) {
312
      fprintf(OutFileTop, "   RsDecodePolymul RsDecodePolymul(\n");
313
      fprintf(OutFileTop, "      // Inputs\n");
314
      fprintf(OutFileTop, "      .CLK              (CLK),\n");
315
      fprintf(OutFileTop, "      .RESET            (RESET),\n");
316
      fprintf(OutFileTop, "      .enable           (enable),\n");
317
      fprintf(OutFileTop, "      .sync             (doneSyndrome),\n");
318
      for(ii=0; ii<syndromeLength; ii++){
319
         if (ii<10){
320
            fprintf(OutFileTop, "      .syndromeIn_%d     (syndrome_%d),\n", ii ,ii);
321
         }else{
322
            fprintf(OutFileTop, "      .syndromeIn_%d    (syndrome_%d),\n", ii ,ii);
323
         }
324
      }
325
      for(ii=0; ii<(syndromeLength+1); ii++){
326
         if (ii<10){
327
            fprintf(OutFileTop, "      .epsilon_%d        (epsilon_%d),\n", ii ,ii);
328
         }else{
329
            fprintf(OutFileTop, "      .epsilon_%d       (epsilon_%d),\n", ii ,ii);
330
         }
331
      }
332
      fprintf(OutFileTop, "      // Outputs\n");
333
      for(ii=0; ii<syndromeLength; ii++){
334
         if (ii<10){
335
            fprintf(OutFileTop, "      .syndromeOut_%d    (polymulSyndrome_%d),\n", ii ,ii);
336
         }else{
337
            fprintf(OutFileTop, "      .syndromeOut_%d   (polymulSyndrome_%d),\n", ii ,ii);
338
         }
339
      }
340
      fprintf(OutFileTop, "      .done             (donePolymul)\n");
341
      fprintf(OutFileTop, "   );\n");
342
   }
343
 
344
   fprintf(OutFileTop, "\n\n\n");
345
 
346
 
347
   //------------------------------------------------------------------
348
   // + lambda_0,..., lambda_xxx
349
   // + omega_0,..., omega_xxx
350
   // + numShifted, doneEuclide
351
   //- RS EUCLIDE
352
   //------------------------------------------------------------------
353
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
354
   fprintf(OutFileTop, "   // + lambda_0,..., lambda_%d\n", syndromeLength-1);
355
   fprintf(OutFileTop, "   // + omega_0,..., omega_%d\n", syndromeLength-1);
356
   fprintf(OutFileTop, "   // + numShifted, doneEuclide\n");
357
   fprintf(OutFileTop, "   //- RS EUCLIDE\n");
358
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
359
 
360
 
361
   if (ErasureOption == 0){
362
      startPointer = (syndromeLength/2);
363
   }else{
364
      startPointer = 0;
365
   }
366
   if (ErasureOption == 0){
367
      endPointer = (syndromeLength/2)+1;
368
   }else{
369
      endPointer = syndromeLength;
370
   }
371
 
372
 
373
/*   for(ii=0; ii<syndromeLength; ii++){
374
      fprintf(OutFileTop, "   wire [%d:0]   lambda_%d;\n", bitSymbol-1, ii);
375
   }
376
   for(ii=0; ii<syndromeLength; ii++){
377
      fprintf(OutFileTop, "   wire [%d:0]   omega_%d;\n", bitSymbol-1, ii);
378
   }*/
379
   for(ii=0; ii<endPointer; ii++){
380
      fprintf(OutFileTop, "   wire [%d:0]   lambda_%d;\n", bitSymbol-1, ii);
381
   }
382
   for(ii=startPointer; ii<syndromeLength; ii++){
383
      fprintf(OutFileTop, "   wire [%d:0]   omega_%d;\n", bitSymbol-1, ii);
384
   }
385
 
386
 
387
   fprintf(OutFileTop, "   wire         doneEuclide;\n");
388
 
389
 
390
   fprintf(OutFileTop, "   wire [%d:0]   numShifted;\n", indexSyndrome);
391
   if (ErasureOption == 1) {
392
      fprintf(OutFileTop, "   reg  [%d:0]   degreeEpsilonReg;\n", indexSyndrome);
393
   }
394
 
395
   fprintf(OutFileTop, "\n\n");
396
   fprintf(OutFileTop, "   RsDecodeEuclide  RsDecodeEuclide(\n");
397
   fprintf(OutFileTop, "      // Inputs\n");
398
   fprintf(OutFileTop, "      .CLK           (CLK),\n");
399
   fprintf(OutFileTop, "      .RESET         (RESET),\n");
400
   fprintf(OutFileTop, "      .enable        (enable),\n");
401
   if (ErasureOption == 1) {
402
      fprintf(OutFileTop, "      .sync          (donePolymul),\n");
403
   } else {
404
      fprintf(OutFileTop, "      .sync          (doneSyndrome),\n");
405
   }
406
 
407
   if (ErasureOption == 1) {
408
      for(ii=0; ii<syndromeLength; ii++){
409
         if (ii<10){
410
            fprintf(OutFileTop, "      .syndrome_%d    (polymulSyndrome_%d),\n", ii, ii);
411
         }else{
412
            fprintf(OutFileTop, "      .syndrome_%d   (polymulSyndrome_%d),\n", ii, ii);
413
         }
414
      }
415
   }else{
416
      for(ii=0; ii<syndromeLength; ii++){
417
         if (ii<10){
418
            fprintf(OutFileTop, "      .syndrome_%d    (syndrome_%d),\n", ii, ii);
419
         }else{
420
            fprintf(OutFileTop, "      .syndrome_%d   (syndrome_%d),\n", ii, ii);
421
         }
422
      }
423
   }
424
 
425
 
426
   if (ErasureOption == 1) {
427
      fprintf(OutFileTop, "      .numErasure    (degreeEpsilonReg),\n");
428
   }
429
 
430
   fprintf(OutFileTop, "      // Outputs\n");
431
/*   for(ii=0; ii<syndromeLength; ii++){
432
      if (ii<10){
433
         fprintf(OutFileTop, "      .lambda_%d      (lambda_%d),\n", ii, ii);
434
      }else{
435
         fprintf(OutFileTop, "      .lambda_%d     (lambda_%d),\n", ii, ii);
436
      }
437
   }
438
   for(ii=0; ii<syndromeLength; ii++){
439
      if (ii<10){
440
         fprintf(OutFileTop, "      .omega_%d       (omega_%d),\n", ii, ii);
441
      }else{
442
         fprintf(OutFileTop, "      .omega_%d      (omega_%d),\n", ii, ii);
443
      }
444
   }*/
445
   for(ii=0; ii<endPointer; ii++){
446
      if (ii<10){
447
         fprintf(OutFileTop, "      .lambda_%d      (lambda_%d),\n", ii, ii);
448
      }else{
449
         fprintf(OutFileTop, "      .lambda_%d     (lambda_%d),\n", ii, ii);
450
      }
451
   }
452
   for(ii=startPointer; ii<syndromeLength; ii++){
453
      if (ii<10){
454
         fprintf(OutFileTop, "      .omega_%d       (omega_%d),\n", ii, ii);
455
      }else{
456
         fprintf(OutFileTop, "      .omega_%d      (omega_%d),\n", ii, ii);
457
      }
458
   }
459
   fprintf(OutFileTop, "      .numShifted    (numShifted),\n");
460
   fprintf(OutFileTop, "      .done          (doneEuclide)\n");
461
   fprintf(OutFileTop, "   );\n");
462
   fprintf(OutFileTop, "\n\n\n");
463
 
464
 
465
   //------------------------------------------------------------------
466
   // + epsilonReg_0, ..., epsilonReg_xxx
467
   //-
468
   //------------------------------------------------------------------
469
   if (ErasureOption == 1) {
470
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
471
      fprintf(OutFileTop, "   // + epsilonReg_0, ..., epsilonReg_%d\n", syndromeLength);
472
      fprintf(OutFileTop, "   //-\n");
473
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
474
      for(ii=0; ii<(syndromeLength+1); ii++){
475
         fprintf(OutFileTop, "   reg [%d:0]   epsilonReg_%d;\n", bitSymbol-1, ii);
476
      }
477
      fprintf(OutFileTop, "\n\n");
478
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
479
      fprintf(OutFileTop, "      if (~RESET) begin\n");
480
      for(ii=0; ii<(syndromeLength+1); ii++){
481
         if (ii < 10){
482
            fprintf(OutFileTop, "         epsilonReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
483
         }else{
484
            fprintf(OutFileTop, "         epsilonReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
485
         }
486
      }
487
 
488
      fprintf(OutFileTop, "      end\n");
489
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneErasure == 1'b1)) begin\n");
490
 
491
      for(ii=0; ii<(syndromeLength+1); ii++){
492
         if (ii < 10){
493
            fprintf(OutFileTop, "         epsilonReg_%d [%d:0]  <= epsilon_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
494
         }else{
495
            fprintf(OutFileTop, "         epsilonReg_%d [%d:0] <= epsilon_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
496
         }
497
      }
498
      fprintf(OutFileTop, "      end\n");
499
      fprintf(OutFileTop, "   end\n");
500
      fprintf(OutFileTop, "\n\n\n");
501
   }
502
 
503
 
504
   //------------------------------------------------------------------
505
   // + epsilonReg2_0,..., epsilonReg2_xxx
506
   //-
507
   //------------------------------------------------------------------
508
   if (ErasureOption == 1) {
509
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
510
      fprintf(OutFileTop, "   // + epsilonReg2_0,..., epsilonReg2_%d\n", syndromeLength);
511
      fprintf(OutFileTop, "   //-\n");
512
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
513
      for(ii=0; ii<(syndromeLength+1); ii++){
514
         fprintf(OutFileTop, "   reg [%d:0]   epsilonReg2_%d;\n", bitSymbol-1, ii);
515
      }
516
      fprintf(OutFileTop, "\n\n");
517
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
518
      fprintf(OutFileTop, "      if (~RESET) begin\n");
519
      for(ii=0; ii<(syndromeLength+1); ii++){
520
         if (ii < 10){
521
            fprintf(OutFileTop, "         epsilonReg2_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
522
         }else{
523
            fprintf(OutFileTop, "         epsilonReg2_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
524
         }
525
      }
526
      fprintf(OutFileTop, "      end\n");
527
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (donePolymul == 1'b1)) begin\n");
528
      for(ii=0; ii<(syndromeLength+1); ii++){
529
         if (ii < 10){
530
            fprintf(OutFileTop, "         epsilonReg2_%d [%d:0]  <= epsilonReg_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
531
         }else{
532
            fprintf(OutFileTop, "         epsilonReg2_%d [%d:0] <= epsilonReg_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
533
         }
534
      }
535
      fprintf(OutFileTop, "      end\n");
536
      fprintf(OutFileTop, "   end\n");
537
      fprintf(OutFileTop, "\n\n\n");
538
   }
539
 
540
 
541
   //------------------------------------------------------------------
542
   // + epsilonReg3_0, ..., epsilonReg3_20
543
   //-
544
   //------------------------------------------------------------------
545
   if (ErasureOption == 1) {
546
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
547
      fprintf(OutFileTop, "   // + epsilonReg3_0, ..., epsilonReg3_%d\n", syndromeLength);
548
      fprintf(OutFileTop, "   //-\n");
549
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
550
      for(ii=0; ii<(syndromeLength+1); ii++){
551
         fprintf(OutFileTop, "   reg [%d:0]   epsilonReg3_%d;\n", bitSymbol-1, ii);
552
      }
553
      fprintf(OutFileTop, "\n\n");
554
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
555
      fprintf(OutFileTop, "      if (~RESET) begin\n");
556
      for(ii=0; ii<(syndromeLength+1); ii++){
557
         if (ii < 10) {
558
            fprintf(OutFileTop, "         epsilonReg3_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
559
         }else{
560
            fprintf(OutFileTop, "         epsilonReg3_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
561
         }
562
      }
563
 
564
      fprintf(OutFileTop, "      end\n");
565
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
566
 
567
      for(ii=0; ii<(syndromeLength+1); ii++){
568
         if (ii < 10) {
569
            fprintf(OutFileTop, "         epsilonReg3_%d [%d:0]  <= epsilonReg2_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
570
         }else{
571
            fprintf(OutFileTop, "         epsilonReg3_%d [%d:0] <= epsilonReg2_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
572
         }
573
      }
574
      fprintf(OutFileTop, "      end\n");
575
      fprintf(OutFileTop, "   end\n");
576
      fprintf(OutFileTop, "\n\n\n");
577
   }
578
 
579
 
580
   //------------------------------------------------------------------
581
   // + degreeEpsilonReg
582
   //-
583
   //------------------------------------------------------------------
584
   if (ErasureOption == 1) {
585
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
586
      fprintf(OutFileTop, "   // + degreeEpsilonReg\n");
587
      fprintf(OutFileTop, "   //-\n");
588
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
589
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
590
      fprintf(OutFileTop, "      if (~RESET) begin\n");
591
      fprintf(OutFileTop, "         degreeEpsilonReg   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
592
      fprintf(OutFileTop, "      end\n");
593
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneErasure == 1'b1)) begin\n");
594
      fprintf(OutFileTop, "         degreeEpsilonReg   <= degreeEpsilon;\n");
595
      fprintf(OutFileTop, "      end\n");
596
      fprintf(OutFileTop, "   end\n");
597
      fprintf(OutFileTop, "\n\n\n");
598
   }
599
 
600
 
601
   //------------------------------------------------------------------
602
   // + degreeEpsilonReg2
603
   //-
604
   //------------------------------------------------------------------
605
   if ((ErasureOption == 1) && ((passFailFlag==1) || (errorStats == 1))) {
606
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
607
      fprintf(OutFileTop, "   // + degreeEpsilonReg2\n");
608
      fprintf(OutFileTop, "   //-\n");
609
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
610
      fprintf(OutFileTop, "   reg    [%d:0]   degreeEpsilonReg2;\n", indexSyndrome);
611
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
612
      fprintf(OutFileTop, "      if (~RESET) begin\n");
613
      fprintf(OutFileTop, "         degreeEpsilonReg2   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
614
      fprintf(OutFileTop, "      end\n");
615
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (donePolymul == 1'b1)) begin\n");
616
      fprintf(OutFileTop, "         degreeEpsilonReg2   <= degreeEpsilonReg;\n");
617
      fprintf(OutFileTop, "      end\n");
618
      fprintf(OutFileTop, "   end\n");
619
      fprintf(OutFileTop, "\n\n\n");
620
   }
621
 
622
 
623
   //------------------------------------------------------------------
624
   // + degreeEpsilonReg3
625
   //-
626
   //------------------------------------------------------------------
627
   if ((ErasureOption == 1) && ((passFailFlag==1) || (errorStats == 1))) {
628
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
629
      fprintf(OutFileTop, "   // + degreeEpsilonReg3\n");
630
      fprintf(OutFileTop, "   //-\n");
631
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
632
      fprintf(OutFileTop, "   reg    [%d:0]   degreeEpsilonReg3;\n", indexSyndrome);
633
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
634
      fprintf(OutFileTop, "      if (~RESET) begin\n");
635
      fprintf(OutFileTop, "         degreeEpsilonReg3   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
636
      fprintf(OutFileTop, "      end\n");
637
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
638
      fprintf(OutFileTop, "         degreeEpsilonReg3   <= degreeEpsilonReg2;\n");
639
      fprintf(OutFileTop, "      end\n");
640
      fprintf(OutFileTop, "   end\n");
641
      fprintf(OutFileTop, "\n\n\n");
642
   }
643
 
644
 
645
   //------------------------------------------------------------------
646
   // + degreeEpsilonReg4
647
   //-
648
   //------------------------------------------------------------------
649
   fprintf(OutFileTop, "   reg          doneShiftReg;\n");
650
 
651
   if ((ErasureOption == 1) && ((passFailFlag==1) || (errorStats == 1))) {
652
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
653
      fprintf(OutFileTop, "   // + degreeEpsilonReg4\n");
654
      fprintf(OutFileTop, "   //-\n");
655
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
656
      fprintf(OutFileTop, "   reg    [%d:0]   degreeEpsilonReg4;\n", indexSyndrome);
657
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
658
      fprintf(OutFileTop, "      if (~RESET) begin\n");
659
      fprintf(OutFileTop, "         degreeEpsilonReg4   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
660
      fprintf(OutFileTop, "      end\n");
661
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneShiftReg == 1'b1)) begin\n");
662
      fprintf(OutFileTop, "         degreeEpsilonReg4   <= degreeEpsilonReg3;\n");
663
      fprintf(OutFileTop, "      end\n");
664
      fprintf(OutFileTop, "   end\n");
665
      fprintf(OutFileTop, "\n\n\n");
666
   }
667
 
668
 
669
   //------------------------------------------------------------------
670
   // + degreeEpsilonReg5
671
   //-
672
   //------------------------------------------------------------------
673
   fprintf(OutFileTop, "   wire         doneChien;\n");
674
 
675
   if (errorStats == 1){
676
      if (ErasureOption == 1) {
677
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
678
         fprintf(OutFileTop, "   // + degreeEpsilonReg5\n");
679
         fprintf(OutFileTop, "   //-\n");
680
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
681
         fprintf(OutFileTop, "   reg    [%d:0]   degreeEpsilonReg5;\n", indexSyndrome);
682
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
683
         fprintf(OutFileTop, "      if (~RESET) begin\n");
684
         fprintf(OutFileTop, "         degreeEpsilonReg5 [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
685
         fprintf(OutFileTop, "      end\n");
686
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneChien == 1'b1)) begin\n");
687
         fprintf(OutFileTop, "         degreeEpsilonReg5   <= degreeEpsilonReg4;\n");
688
         fprintf(OutFileTop, "      end\n");
689
         fprintf(OutFileTop, "   end\n");
690
         fprintf(OutFileTop, "\n\n\n");
691
      }
692
   }
693
 
694
   //------------------------------------------------------------------
695
   // + numErasureReg
696
   //-
697
   //------------------------------------------------------------------
698
   fprintf(OutFileTop, "   reg [2:0]   doneReg;\n");
699
   if (errorStats == 1){
700
      if (ErasureOption == 1) {
701
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
702
         fprintf(OutFileTop, "   // + numErasureReg\n");
703
         fprintf(OutFileTop, "   //-\n");
704
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
705
         fprintf(OutFileTop, "   reg [%d:0]   numErasureReg;\n", indexSyndrome);
706
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
707
         fprintf(OutFileTop, "      if (~RESET) begin\n");
708
         fprintf(OutFileTop, "         numErasureReg   <= %d'd0;\n", indexSyndrome+1);
709
         fprintf(OutFileTop, "      end\n");
710
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneReg[0] == 1'b1)) begin\n");
711
         fprintf(OutFileTop, "         numErasureReg   <= degreeEpsilonReg5;\n");
712
         fprintf(OutFileTop, "      end\n");
713
         fprintf(OutFileTop, "   end\n");
714
         fprintf(OutFileTop, "\n\n\n");
715
      }
716
   }
717
 
718
 
719
   //------------------------------------------------------------------------
720
   // + doneShift
721
   //------------------------------------------------------------------------
722
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
723
   fprintf(OutFileTop, "   // + doneShift\n");
724
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
725
   fprintf(OutFileTop, "   reg          doneShift;\n");
726
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
727
   fprintf(OutFileTop, "      if (~RESET) begin\n");
728
   fprintf(OutFileTop, "         doneShift <= 1'b0;\n");
729
   fprintf(OutFileTop, "      end\n");
730
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
731
   fprintf(OutFileTop, "         doneShift <= doneEuclide;\n");
732
   fprintf(OutFileTop, "      end\n");
733
   fprintf(OutFileTop, "   end\n");
734
   fprintf(OutFileTop, "\n\n\n");
735
 
736
 
737
   //------------------------------------------------------------------
738
   // + numShiftedReg
739
   //------------------------------------------------------------------
740
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
741
   fprintf(OutFileTop, "   // + numShiftedReg\n");
742
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
743
   fprintf(OutFileTop, "   reg [%d:0]   numShiftedReg;\n", indexSyndrome);
744
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
745
   fprintf(OutFileTop, "      if (~RESET) begin\n");
746
   fprintf(OutFileTop, "         numShiftedReg <= %d'd0;\n", indexSyndrome+1);
747
   fprintf(OutFileTop, "      end\n");
748
   fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
749
   fprintf(OutFileTop, "         numShiftedReg <= numShifted;\n");
750
   fprintf(OutFileTop, "      end\n");
751
   fprintf(OutFileTop, "   end\n");
752
   fprintf(OutFileTop, "\n\n\n");
753
 
754
 
755
   //------------------------------------------------------------------
756
   // + lambdaReg_0,..., lambdaReg_xxx
757
   //------------------------------------------------------------------
758
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
759
   fprintf(OutFileTop, "   // + lambdaReg_0,..., lambdaReg_%d\n", syndromeLength-1);
760
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
761
/*   for(ii=0; ii<syndromeLength; ii++){
762
      fprintf(OutFileTop, "   reg [%d:0]   lambdaReg_%d;\n", bitSymbol-1, ii);
763
   }*/
764
   for(ii=0; ii<endPointer; ii++){
765
      fprintf(OutFileTop, "   reg [%d:0]   lambdaReg_%d;\n", bitSymbol-1, ii);
766
   }
767
   fprintf(OutFileTop, "\n\n");
768
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
769
   fprintf(OutFileTop, "      if (~RESET) begin\n");
770
 
771
/*   for(ii=0; ii<syndromeLength; ii++){
772
      if (ii < 10){
773
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
774
      }else{
775
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
776
      }
777
   }*/
778
   for(ii=0; ii<endPointer; ii++){
779
      if (ii < 10){
780
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
781
      }else{
782
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
783
      }
784
   }
785
 
786
 
787
   fprintf(OutFileTop, "      end\n");
788
   fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
789
 
790
/*   for(ii=0; ii<syndromeLength; ii++){
791
      if (ii < 10){
792
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0]  <= lambda_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
793
      }else{
794
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0] <= lambda_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
795
      }
796
   }*/
797
   for(ii=0; ii<endPointer; ii++){
798
      if (ii < 10){
799
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0]  <= lambda_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
800
      }else{
801
         fprintf(OutFileTop, "         lambdaReg_%d [%d:0] <= lambda_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
802
      }
803
   }
804
 
805
 
806
   fprintf(OutFileTop, "      end\n");
807
   fprintf(OutFileTop, "   end\n");
808
   fprintf(OutFileTop, "\n\n\n");
809
 
810
 
811
   //------------------------------------------------------------------
812
   // + omegaReg_0,..., omegaReg_19
813
   //------------------------------------------------------------------
814
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
815
   fprintf(OutFileTop, "   // + omegaReg_0,..., omegaReg_%d\n", syndromeLength-1);
816
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
817
/*   for(ii=0; ii<syndromeLength; ii++){
818
      fprintf(OutFileTop, "   reg [%d:0]   omegaReg_%d;\n", bitSymbol-1, ii);
819
   }*/
820
   for(ii=startPointer; ii<syndromeLength; ii++){
821
      fprintf(OutFileTop, "   reg [%d:0]   omegaReg_%d;\n", bitSymbol-1, ii);
822
   }
823
 
824
 
825
 
826
   fprintf(OutFileTop, "\n\n");
827
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
828
   fprintf(OutFileTop, "      if (~RESET) begin\n");
829
 
830
/*   for(ii=0; ii<syndromeLength; ii++){
831
      if (ii < 10){
832
         fprintf(OutFileTop, "         omegaReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
833
      }else{
834
         fprintf(OutFileTop, "         omegaReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
835
      }
836
   }*/
837
   for(ii=startPointer; ii<syndromeLength; ii++){
838
      if (ii < 10){
839
         fprintf(OutFileTop, "         omegaReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
840
      }else{
841
         fprintf(OutFileTop, "         omegaReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
842
      }
843
   }
844
 
845
 
846
   fprintf(OutFileTop, "      end\n");
847
   fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
848
 
849
/*   for(ii=0; ii<syndromeLength; ii++){
850
      if (ii < 10){
851
         fprintf(OutFileTop, "         omegaReg_%d [%d:0]  <= omega_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
852
      }else{
853
         fprintf(OutFileTop, "         omegaReg_%d [%d:0] <= omega_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
854
      }
855
   }*/
856
   for(ii=startPointer; ii<syndromeLength; ii++){
857
      if (ii < 10){
858
         fprintf(OutFileTop, "         omegaReg_%d [%d:0]  <= omega_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
859
      }else{
860
         fprintf(OutFileTop, "         omegaReg_%d [%d:0] <= omega_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
861
      }
862
   }
863
 
864
 
865
   fprintf(OutFileTop, "      end\n");
866
   fprintf(OutFileTop, "   end\n");
867
   fprintf(OutFileTop, "\n\n\n");
868
 
869
   //------------------------------------------------------------------
870
   // + omegaShifted_0, ..., omegaShifted_19
871
   //- Rs Shift Omega
872
   //------------------------------------------------------------------
873
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
874
   fprintf(OutFileTop, "   // + omegaShifted_0, ..., omegaShifted_%d\n", syndromeLength-1);
875
   fprintf(OutFileTop, "   //- Rs Shift Omega\n");
876
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
877
/*   for(ii=0; ii<syndromeLength; ii++){
878
      fprintf(OutFileTop, "    wire [%d:0]   omegaShifted_%d;\n", bitSymbol-1, ii);
879
   }*/
880
   if (ErasureOption == 1) {
881
      shiftPointer = syndromeLength;
882
   }else{
883
      shiftPointer = (syndromeLength/2);
884
   }
885
 
886
   for(ii=0; ii<shiftPointer; ii++){
887
      fprintf(OutFileTop, "    wire [%d:0]   omegaShifted_%d;\n", bitSymbol-1, ii);
888
   }
889
 
890
 
891
   fprintf(OutFileTop, "\n\n");
892
   fprintf(OutFileTop, "   RsDecodeShiftOmega RsDecodeShiftOmega(\n");
893
   fprintf(OutFileTop, "      // Inputs\n");
894
 
895
/*   for(ii=0; ii<syndromeLength; ii++){
896
      if (ii<10) {
897
         fprintf(OutFileTop, "      .omega_%d           (omegaReg_%d),\n", ii, ii);
898
      }else{
899
         fprintf(OutFileTop, "      .omega_%d          (omegaReg_%d),\n", ii, ii);
900
      }
901
   }*/
902
   for(ii=startPointer; ii<syndromeLength; ii++){
903
      if (ii<10) {
904
         fprintf(OutFileTop, "      .omega_%d           (omegaReg_%d),\n", ii, ii);
905
      }else{
906
         fprintf(OutFileTop, "      .omega_%d          (omegaReg_%d),\n", ii, ii);
907
      }
908
   }
909
 
910
//   fprintf(OutFileTop, "      .numShifted        (numShiftedReg),\n");
911
   fprintf(OutFileTop, "      // Outputs\n");
912
 
913
/*   for(ii=0; ii<(syndromeLength-1); ii++){
914
      if (ii<10) {
915
         fprintf(OutFileTop, "      .omegaShifted_%d    (omegaShifted_%d),\n", ii, ii);
916
      }else{
917
         fprintf(OutFileTop, "      .omegaShifted_%d   (omegaShifted_%d),\n", ii, ii);
918
      }
919
   }
920
   fprintf(OutFileTop, "      .omegaShifted_%d   (omegaShifted_%d)\n", (syndromeLength-1), (syndromeLength-1));
921
   */
922
   for(ii=0; ii<shiftPointer; ii++){
923
      if (ii<10) {
924
         fprintf(OutFileTop, "      .omegaShifted_%d    (omegaShifted_%d),\n", ii, ii);
925
      }else{
926
         fprintf(OutFileTop, "      .omegaShifted_%d   (omegaShifted_%d),\n", ii, ii);
927
      }
928
   }
929
 
930
 
931
   fprintf(OutFileTop, "      // Inputs\n");
932
   fprintf(OutFileTop, "      .numShifted        (numShiftedReg)\n");
933
 
934
   fprintf(OutFileTop, "   );\n");
935
   fprintf(OutFileTop, "\n\n\n");
936
 
937
 
938
   //------------------------------------------------------------------
939
   // + omegaShiftedReg_0,.., omegaShiftedReg_19
940
   //------------------------------------------------------------------
941
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
942
   fprintf(OutFileTop, "   // + omegaShiftedReg_0,.., omegaShiftedReg_%d\n", syndromeLength-1);
943
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
944
 
945
/*   for(ii=0; ii<(syndromeLength); ii++){
946
      fprintf(OutFileTop, "    reg [%d:0]   omegaShiftedReg_%d;\n", bitSymbol-1, ii);
947
   }*/
948
   for(ii=0; ii<shiftPointer; ii++){
949
      fprintf(OutFileTop, "    reg [%d:0]   omegaShiftedReg_%d;\n", bitSymbol-1, ii);
950
   }
951
 
952
   fprintf(OutFileTop, "\n\n");
953
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
954
   fprintf(OutFileTop, "      if (~RESET) begin\n");
955
 
956
/*   for(ii=0; ii<(syndromeLength); ii++){
957
      if (ii<10) {
958
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
959
      }else{
960
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
961
      }
962
   }*/
963
   for(ii=0; ii<shiftPointer; ii++){
964
      if (ii<10) {
965
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
966
      }else{
967
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0] <= %d'd0;\n", ii, bitSymbol-1, bitSymbol);
968
      }
969
   }
970
   fprintf(OutFileTop, "      end\n");
971
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
972
 
973
/*   for(ii=0; ii<(syndromeLength); ii++){
974
      if (ii<10) {
975
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0]  <= omegaShifted_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
976
      }else{
977
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0] <= omegaShifted_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
978
      }
979
   }*/
980
   for(ii=0; ii<(shiftPointer); ii++){
981
      if (ii<10) {
982
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0]  <= omegaShifted_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
983
      }else{
984
         fprintf(OutFileTop, "         omegaShiftedReg_%d [%d:0] <= omegaShifted_%d [%d:0];\n", ii, bitSymbol-1, ii, bitSymbol-1);
985
      }
986
   }
987
   fprintf(OutFileTop, "      end\n");
988
   fprintf(OutFileTop, "   end\n");
989
   fprintf(OutFileTop, "\n\n\n");
990
 
991
 
992
   //------------------------------------------------------------------
993
   // + degreeOmega
994
   //------------------------------------------------------------------
995
   if (passFailFlag == 1){
996
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
997
      fprintf(OutFileTop, "   // + degreeOmega\n");
998
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
999
 
1000
 
1001
   if ((syndromeLength/2) > 2047) {
1002
      degreeTemp = 12;
1003
   }
1004
   else if ((syndromeLength/2) > 1023) {
1005
      degreeTemp = 11;
1006
   }
1007
   else if ((syndromeLength/2) > 511) {
1008
      degreeTemp = 10;
1009
   }
1010
   else if ((syndromeLength/2) > 255) {
1011
      degreeTemp = 9;
1012
   }
1013
   else if ((syndromeLength/2) > 127) {
1014
      degreeTemp = 8;
1015
   }
1016
   else if ((syndromeLength/2) > 63) {
1017
      degreeTemp = 7;
1018
   }
1019
   else if ((syndromeLength/2) > 31) {
1020
      degreeTemp = 6;
1021
   }
1022
   else if ((syndromeLength/2) > 15) {
1023
      degreeTemp = 5;
1024
   }
1025
   else if ((syndromeLength/2) > 7) {
1026
      degreeTemp = 4;
1027
   }
1028
   else if ((syndromeLength/2) > 3) {
1029
      degreeTemp = 3;
1030
   }
1031
   else {
1032
      degreeTemp = 2;
1033
   }
1034
 
1035
 
1036
   if (ErasureOption == 1) {
1037
      fprintf(OutFileTop, "   wire   [%d:0]   degreeOmega;\n", indexSyndrome);
1038
   }else{
1039
      fprintf(OutFileTop, "   wire   [%d:0]   degreeOmega;\n", degreeTemp-1);
1040
   }
1041
//      fprintf(OutFileTop, "   wire   [%d:0]   degreeOmega;\n", indexSyndrome);
1042
 
1043
 
1044
      fprintf(OutFileTop, "\n\n");
1045
      fprintf(OutFileTop, "   RsDecodeDegree  RsDecodeDegree_1(\n");
1046
      fprintf(OutFileTop, "      // Inputs\n");
1047
 
1048
      for(ii=0; ii<(syndromeLength); ii++){
1049
/*         if (ii<10){
1050
            fprintf(OutFileTop, "      .polynom_%d   (omegaShiftedReg_%d),\n", ii, ii);
1051
         }else{
1052
            fprintf(OutFileTop, "      .polynom_%d  (omegaShiftedReg_%d),\n", ii, ii);
1053
         }*/
1054
         //// temp ////
1055
         if (ii < (shiftPointer)) {
1056
            if (ii<10){
1057
               fprintf(OutFileTop, "      .polynom_%d   (omegaShiftedReg_%d),\n", ii, ii);
1058
            }else{
1059
               fprintf(OutFileTop, "      .polynom_%d  (omegaShiftedReg_%d),\n", ii, ii);
1060
            }
1061
         }else{
1062
            if (ii ==  (shiftPointer)){
1063
               fprintf(OutFileTop, "      .polynom_%d   (%d'd0),\n", ii, bitSymbol);
1064
            }
1065
         }
1066
         //// temp ////
1067
      }
1068
      fprintf(OutFileTop, "      // Outputs\n");
1069
      fprintf(OutFileTop, "      .degree      (degreeOmega)\n");
1070
      fprintf(OutFileTop, "   );\n");
1071
      fprintf(OutFileTop, "\n\n\n");
1072
   }
1073
 
1074
   //------------------------------------------------------------------
1075
   // + lambdaReg2_0,.., lambdaReg2_19
1076
   //------------------------------------------------------------------
1077
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1078
   fprintf(OutFileTop, "   // + lambdaReg2_0,.., lambdaReg2_%d\n", syndromeLength-1);
1079
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1080
/*   for(ii=0; ii<(syndromeLength); ii++){
1081
      fprintf(OutFileTop, "   reg [%d:0]   lambdaReg2_%d;\n", bitSymbol-1, ii);
1082
   }*/
1083
   for(ii=0; ii<(endPointer); ii++){
1084
      fprintf(OutFileTop, "   reg [%d:0]   lambdaReg2_%d;\n", bitSymbol-1, ii);
1085
   }
1086
 
1087
   fprintf(OutFileTop, "\n\n");
1088
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1089
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1090
 
1091
/*   for(ii=0; ii<(syndromeLength); ii++){
1092
      if (ii < 10) {
1093
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1,bitSymbol);
1094
      }else{
1095
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
1096
      }
1097
   }*/
1098
   for(ii=0; ii<(endPointer); ii++){
1099
      if (ii < 10) {
1100
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0]  <= %d'd0;\n", ii, bitSymbol-1,bitSymbol);
1101
      }else{
1102
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0] <= %d'd0;\n", ii,bitSymbol-1,bitSymbol);
1103
      }
1104
   }
1105
 
1106
   fprintf(OutFileTop, "      end\n");
1107
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
1108
 
1109
/*   for(ii=0; ii<(syndromeLength); ii++){
1110
      if (ii < 10) {
1111
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0]  <= lambdaReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
1112
      }else{
1113
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0] <= lambdaReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
1114
      }
1115
   }*/
1116
   for(ii=0; ii<(endPointer); ii++){
1117
      if (ii < 10) {
1118
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0]  <= lambdaReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
1119
      }else{
1120
         fprintf(OutFileTop, "         lambdaReg2_%d [%d:0] <= lambdaReg_%d [%d:0];\n", ii,bitSymbol-1, ii,bitSymbol-1);
1121
      }
1122
   }
1123
 
1124
   fprintf(OutFileTop, "      end\n");
1125
   fprintf(OutFileTop, "   end\n");
1126
   fprintf(OutFileTop, "\n\n\n");
1127
 
1128
 
1129
   //------------------------------------------------------------------
1130
   // + degreeLambda
1131
   //------------------------------------------------------------------
1132
   if (passFailFlag == 1){
1133
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1134
      fprintf(OutFileTop, "   // + degreeLambda\n");
1135
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1136
//      fprintf(OutFileTop, "   wire [%d:0]   degreeLambda;\n", indexSyndrome);
1137
 
1138
      if (ErasureOption == 1) {
1139
         fprintf(OutFileTop, "   wire [%d:0]   degreeLambda;\n", indexSyndrome);
1140
      }else{
1141
         fprintf(OutFileTop, "   wire [%d:0]   degreeLambda;\n", degreeTemp-1);
1142
      }
1143
 
1144
 
1145
 
1146
      fprintf(OutFileTop, "   RsDecodeDegree  RsDecodeDegree_2(\n");
1147
      fprintf(OutFileTop, "      // Inputs\n");
1148
 
1149
      for(ii=0; ii<(syndromeLength); ii++){
1150
/*         if (ii<10) {
1151
            fprintf(OutFileTop, "      .polynom_%d   (lambdaReg2_%d),\n", ii, ii);
1152
         }else{
1153
            fprintf(OutFileTop, "      .polynom_%d  (lambdaReg2_%d),\n", ii, ii);
1154
         }*/
1155
         //// temp ////
1156
         if (ii < endPointer) {
1157
            if (ii<10) {
1158
               fprintf(OutFileTop, "      .polynom_%d   (lambdaReg2_%d),\n", ii, ii);
1159
            }else{
1160
               fprintf(OutFileTop, "      .polynom_%d  (lambdaReg2_%d),\n", ii, ii);
1161
            }
1162
         }/*else{
1163
            if (ii<10) {
1164
               fprintf(OutFileTop, "      .polynom_%d   (%d'd0),\n", ii, bitSymbol);
1165
            }else{
1166
               fprintf(OutFileTop, "      .polynom_%d  (%d'd0),\n", ii, bitSymbol);
1167
            }
1168
         }*/
1169
         //// temp ////
1170
      }
1171
      fprintf(OutFileTop, "      // Outputs\n");
1172
      fprintf(OutFileTop, "      .degree      (degreeLambda)\n");
1173
      fprintf(OutFileTop, "   );\n");
1174
      fprintf(OutFileTop, "\n\n\n");
1175
   }
1176
 
1177
   //------------------------------------------------------------------
1178
   // + degreeOmegaReg
1179
   // + degreeLambdaReg
1180
   //------------------------------------------------------------------
1181
   if (passFailFlag == 1){
1182
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1183
      fprintf(OutFileTop, "   // + degreeOmegaReg\n");
1184
      fprintf(OutFileTop, "   // + degreeLambdaReg\n");
1185
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1186
 
1187
      if (ErasureOption == 1) {
1188
         fprintf(OutFileTop, "   reg [%d:0]   degreeOmegaReg;\n", indexSyndrome);
1189
         fprintf(OutFileTop, "   reg [%d:0]   degreeLambdaReg;\n", indexSyndrome);
1190
      }else{
1191
         fprintf(OutFileTop, "   reg [%d:0]   degreeOmegaReg;\n", degreeTemp-1);
1192
         fprintf(OutFileTop, "   reg [%d:0]   degreeLambdaReg;\n", degreeTemp-1);
1193
      }
1194
 
1195
//      fprintf(OutFileTop, "   reg [%d:0]   degreeOmegaReg;\n", indexSyndrome);
1196
//      fprintf(OutFileTop, "   reg [%d:0]   degreeLambdaReg;\n", indexSyndrome);
1197
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1198
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1199
 
1200
 
1201
//      fprintf(OutFileTop, "         degreeOmegaReg  <= %d'd0;\n", indexSyndrome+1);
1202
//      fprintf(OutFileTop, "         degreeLambdaReg <= %d'd0;\n", indexSyndrome+1);
1203
      if (ErasureOption == 1) {
1204
         fprintf(OutFileTop, "         degreeOmegaReg  <= %d'd0;\n", indexSyndrome+1);
1205
         fprintf(OutFileTop, "         degreeLambdaReg <= %d'd0;\n", indexSyndrome+1);
1206
      }else{
1207
         fprintf(OutFileTop, "         degreeOmegaReg  <= %d'd0;\n", degreeTemp);
1208
         fprintf(OutFileTop, "         degreeLambdaReg <= %d'd0;\n", degreeTemp);
1209
      }
1210
 
1211
      fprintf(OutFileTop, "      end\n");
1212
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneShiftReg == 1'b1)) begin\n");
1213
      fprintf(OutFileTop, "         degreeOmegaReg  <= degreeOmega;\n");
1214
      fprintf(OutFileTop, "         degreeLambdaReg <= degreeLambda;\n");
1215
      fprintf(OutFileTop, "      end\n");
1216
      fprintf(OutFileTop, "   end\n");
1217
      fprintf(OutFileTop, "\n\n\n");
1218
   }
1219
 
1220
 
1221
   //------------------------------------------------------------------
1222
   // + doneShiftReg
1223
   //------------------------------------------------------------------
1224
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1225
   fprintf(OutFileTop, "   // + doneShiftReg\n");
1226
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1227
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1228
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1229
   fprintf(OutFileTop, "         doneShiftReg <= 1'b0;\n");
1230
   fprintf(OutFileTop, "      end \n");
1231
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
1232
   fprintf(OutFileTop, "         doneShiftReg <= doneShift;\n");
1233
   fprintf(OutFileTop, "      end\n");
1234
   fprintf(OutFileTop, "   end\n");
1235
   fprintf(OutFileTop, "\n\n\n");
1236
 
1237
 
1238
   //------------------------------------------------------------------
1239
   // + 
1240
   //- RS Chien Search Algorithm
1241
   //------------------------------------------------------------------
1242
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1243
   fprintf(OutFileTop, "   // + \n");
1244
   fprintf(OutFileTop, "   //- RS Chien Search Algorithm\n");
1245
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1246
   if ((errorStats!=0) || (passFailFlag!=0)) {
1247
      fprintf(OutFileTop, "   wire [%d:0]   numErrorChien;\n", indexSyndrome);
1248
   }
1249
   fprintf(OutFileTop, "   wire [%d:0]   error;\n", bitSymbol-1);
1250
 
1251
   if (ErasureOption == 1) {
1252
      fprintf(OutFileTop, "   wire         delayedErasureIn;\n");
1253
   }
1254
 
1255
   fprintf(OutFileTop, "\n\n");
1256
   fprintf(OutFileTop, "   RsDecodeChien RsDecodeChien(\n");
1257
   fprintf(OutFileTop, "      // Inputs\n");
1258
   fprintf(OutFileTop, "      .CLK            (CLK),\n");
1259
   fprintf(OutFileTop, "      .RESET          (RESET),\n");
1260
   fprintf(OutFileTop, "      .enable         (enable),\n");
1261
   fprintf(OutFileTop, "      .sync           (doneShiftReg),\n");
1262
   if (ErasureOption == 1) {
1263
      fprintf(OutFileTop, "      .erasureIn      (delayedErasureIn),\n");
1264
   }
1265
 
1266
 
1267
/*   for(ii=0; ii<(syndromeLength); ii++){
1268
      if (ii < 10) {
1269
         fprintf(OutFileTop, "      .lambdaIn_%d     (lambdaReg2_%d),\n", ii, ii);
1270
      }else{
1271
         fprintf(OutFileTop, "      .lambdaIn_%d    (lambdaReg2_%d),\n", ii, ii);
1272
      }
1273
   }*/
1274
   for(ii=0; ii<(endPointer); ii++){
1275
      if (ii < 10) {
1276
         fprintf(OutFileTop, "      .lambdaIn_%d     (lambdaReg2_%d),\n", ii, ii);
1277
      }else{
1278
         fprintf(OutFileTop, "      .lambdaIn_%d    (lambdaReg2_%d),\n", ii, ii);
1279
      }
1280
   }
1281
 
1282
 
1283
 
1284
/*   for(ii=0; ii<(syndromeLength); ii++){
1285
      if (ii < 10) {
1286
         fprintf(OutFileTop, "      .omegaIn_%d      (omegaShiftedReg_%d),\n", ii, ii);
1287
      }else{
1288
         fprintf(OutFileTop, "      .omegaIn_%d     (omegaShiftedReg_%d),\n", ii, ii);
1289
      }
1290
   }*/
1291
   for(ii=0; ii<(shiftPointer); ii++){
1292
      if (ii < 10) {
1293
         fprintf(OutFileTop, "      .omegaIn_%d      (omegaShiftedReg_%d),\n", ii, ii);
1294
      }else{
1295
         fprintf(OutFileTop, "      .omegaIn_%d     (omegaShiftedReg_%d),\n", ii, ii);
1296
      }
1297
   }
1298
 
1299
 
1300
   if (ErasureOption == 1) {
1301
      for(ii=0; ii<(syndromeLength+1); ii++){
1302
         if (ii < 10) {
1303
            fprintf(OutFileTop, "      .epsilonIn_%d    (epsilonReg3_%d),\n", ii, ii);
1304
         }else{
1305
            fprintf(OutFileTop, "      .epsilonIn_%d   (epsilonReg3_%d),\n", ii, ii);
1306
         }
1307
      }
1308
   }
1309
 
1310
   fprintf(OutFileTop, "      // Outputs\n");
1311
   fprintf(OutFileTop, "      .errorOut       (error),\n");
1312
   if ((errorStats!=0) || (passFailFlag!=0)) {
1313
      fprintf(OutFileTop, "      .numError       (numErrorChien),\n");
1314
   }
1315
   fprintf(OutFileTop, "      .done           (doneChien)\n");
1316
   fprintf(OutFileTop, "   );\n");
1317
   fprintf(OutFileTop, "\n\n\n");
1318
 
1319
 
1320
   //------------------------------------------------------------------
1321
   // + delayOut
1322
   //- Rs Decode Delay
1323
   //------------------------------------------------------------------
1324
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1325
   fprintf(OutFileTop, "   // + delayOut\n");
1326
   fprintf(OutFileTop, "   //- Rs Decode Delay\n");
1327
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1328
 
1329
   if (ErasureOption == 1) {
1330
      fprintf(OutFileTop, "   wire [%d:0]   delayOut;\n",bitSymbol);
1331
      fprintf(OutFileTop, "   wire [%d:0]   delayIn;\n",bitSymbol);
1332
   }else{
1333
      fprintf(OutFileTop, "   wire [%d:0]   delayOut;\n", bitSymbol-1);
1334
      fprintf(OutFileTop, "   wire [%d:0]   delayIn;\n", bitSymbol-1);
1335
   }
1336
 
1337
   fprintf(OutFileTop, "\n\n");
1338
   fprintf(OutFileTop, "   RsDecodeDelay  RsDecodeDelay(\n");
1339
   fprintf(OutFileTop, "      // Inputs\n");
1340
   fprintf(OutFileTop, "      .CLK      (CLK),\n");
1341
   fprintf(OutFileTop, "      .RESET    (RESET),\n");
1342
   fprintf(OutFileTop, "      .enable   (enable),\n");
1343
   fprintf(OutFileTop, "      .dataIn   (delayIn),\n");
1344
   fprintf(OutFileTop, "      // Outputs\n");
1345
   fprintf(OutFileTop, "      .dataOut  (delayOut)\n");
1346
   fprintf(OutFileTop, "   );\n");
1347
   fprintf(OutFileTop, "\n\n\n");
1348
 
1349
 
1350
   //------------------------------------------------------------------
1351
   // + delayIn, delayedErasureIn, delayedDataIn
1352
   //------------------------------------------------------------------
1353
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1354
   fprintf(OutFileTop, "   // + delayIn, delayedErasureIn, delayedDataIn\n");
1355
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1356
   fprintf(OutFileTop, "   wire [%d:0]   delayedDataIn;\n", bitSymbol-1);
1357
 
1358
   if (ErasureOption == 1) {
1359
      fprintf(OutFileTop, "   assign   delayIn          = {erasureIn, dataInCheck};\n");
1360
      fprintf(OutFileTop, "   assign   delayedErasureIn = delayOut[%d];\n", bitSymbol);
1361
   }else {
1362
      fprintf(OutFileTop, "   assign   delayIn          = dataInCheck;\n");
1363
   }
1364
 
1365
 
1366
   fprintf(OutFileTop, "   assign   delayedDataIn    = delayOut[%d:0];\n", bitSymbol-1);
1367
   fprintf(OutFileTop, "\n\n\n");
1368
 
1369
 
1370
   //------------------------------------------------------------------------
1371
   // + OutputValidReg
1372
   //------------------------------------------------------------------------
1373
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
1374
   fprintf(OutFileTop, "   // + OutputValidReg\n");
1375
   fprintf(OutFileTop, "   //------------------------------------------------------------------------\n");
1376
   fprintf(OutFileTop, "   reg         OutputValidReg;\n");
1377
   fprintf(OutFileTop, "   reg [3:0]   startReg;\n\n");
1378
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1379
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1380
   fprintf(OutFileTop, "         OutputValidReg   <= 1'b0;\n");
1381
   fprintf(OutFileTop, "      end\n");
1382
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
1383
   fprintf(OutFileTop, "         if (startReg[1] == 1'b1) begin\n");
1384
   fprintf(OutFileTop, "            OutputValidReg   <= 1'b1;\n");
1385
   fprintf(OutFileTop, "         end\n");
1386
   fprintf(OutFileTop, "         else if (doneReg[0] == 1'b1) begin\n");
1387
   fprintf(OutFileTop, "            OutputValidReg   <= 1'b0;\n");
1388
   fprintf(OutFileTop, "         end\n");
1389
   fprintf(OutFileTop, "      end\n");
1390
   fprintf(OutFileTop, "   end\n");
1391
   fprintf(OutFileTop, "\n\n\n");
1392
 
1393
 
1394
   //------------------------------------------------------------------
1395
   // + startReg, doneReg
1396
   //------------------------------------------------------------------
1397
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1398
   fprintf(OutFileTop, "   // + startReg, doneReg\n");
1399
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1400
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1401
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1402
   fprintf(OutFileTop, "         startReg   [3:0] <= 4'd0;\n");
1403
   fprintf(OutFileTop, "         doneReg   [2:0]  <= 3'd0;\n");
1404
   fprintf(OutFileTop, "      end\n");
1405
   fprintf(OutFileTop, "      else if (enable == 1'b1) begin\n");
1406
   fprintf(OutFileTop, "         startReg [3:0] <= {doneShiftReg, startReg[3:1]};\n");
1407
   fprintf(OutFileTop, "         doneReg  [2:0] <= {doneChien, doneReg[2:1]};\n");
1408
   fprintf(OutFileTop, "      end\n");
1409
   fprintf(OutFileTop, "   end\n");
1410
   fprintf(OutFileTop, "\n\n\n");
1411
 
1412
 
1413
 
1414
   //------------------------------------------------------------------
1415
   // + numErrorLambdaReg
1416
   //------------------------------------------------------------------
1417
   if (passFailFlag == 1){
1418
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1419
      fprintf(OutFileTop, "   // + numErrorLambdaReg\n");
1420
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1421
//      fprintf(OutFileTop, "   reg [%d:0]   numErrorLambdaReg;\n", indexSyndrome);
1422
 
1423
      if (ErasureOption == 1) {
1424
         fprintf(OutFileTop, "   reg [%d:0]   numErrorLambdaReg;\n", indexSyndrome);
1425
      }else{
1426
         fprintf(OutFileTop, "   reg [%d:0]   numErrorLambdaReg;\n", degreeTemp-1);
1427
      }
1428
 
1429
 
1430
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1431
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1432
//      fprintf(OutFileTop, "         numErrorLambdaReg   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
1433
      if (ErasureOption == 1) {
1434
         fprintf(OutFileTop, "         numErrorLambdaReg   [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
1435
      }else{
1436
         fprintf(OutFileTop, "         numErrorLambdaReg   [%d:0] <= %d'd0;\n", degreeTemp-1, degreeTemp);
1437
      }
1438
 
1439
 
1440
 
1441
      fprintf(OutFileTop, "      end\n");
1442
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (startReg[1] == 1'b1)) begin\n");
1443
      fprintf(OutFileTop, "         numErrorLambdaReg   <= degreeLambdaReg;\n");
1444
      fprintf(OutFileTop, "      end\n");
1445
      fprintf(OutFileTop, "   end\n");
1446
      fprintf(OutFileTop, "\n\n\n");
1447
   }
1448
 
1449
 
1450
   //------------------------------------------------------------------
1451
   // + degreeErrorReg
1452
   //------------------------------------------------------------------
1453
   if (passFailFlag == 1){
1454
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1455
      fprintf(OutFileTop, "   // + degreeErrorReg\n");
1456
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1457
      fprintf(OutFileTop, "   reg         degreeErrorReg;\n");
1458
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1459
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1460
      fprintf(OutFileTop, "         degreeErrorReg   <= 1'b0;\n");
1461
      fprintf(OutFileTop, "      end\n");
1462
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (startReg[1] == 1'b1)) begin\n");
1463
/*      if (ErasureOption == 1) {
1464
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) <= ({1'b0, degreeLambdaReg}) + ({1'b0, degreeEpsilonReg4})) begin\n");
1465
      }else {
1466
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) <= {1'b0, degreeLambdaReg}) begin\n");
1467
      }*/
1468
/*      if (ErasureOption == 1) {
1469
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) < ({1'b0, degreeLambdaReg}) + ({1'b0, degreeEpsilonReg4})) begin\n");
1470
      }else {
1471
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) < {1'b0, degreeLambdaReg}) begin\n");
1472
      }*/
1473
      if (ErasureOption == 1) {
1474
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) <= ({1'b0, degreeLambdaReg}) + ({1'b0, degreeEpsilonReg4})) begin\n");
1475
      }else {
1476
         fprintf(OutFileTop, "         if (({1'b0, degreeOmegaReg}) <= {1'b0, degreeLambdaReg}) begin\n");
1477
      }
1478
      fprintf(OutFileTop, "            degreeErrorReg   <= 1'b0;\n");
1479
      fprintf(OutFileTop, "         end\n");
1480
/*      if (ErasureOption == 1) {
1481
         fprintf(OutFileTop, "         else if ((degreeOmegaReg == %d'd0) && (degreeLambdaReg == %d'd0) && (degreeEpsilonReg4 == %d'd0)) begin\n", indexSyndrome+1, indexSyndrome+1, indexSyndrome+1);
1482
      }else {
1483
         fprintf(OutFileTop, "         else if ((degreeOmegaReg == %d'd0) && (degreeLambdaReg == %d'd0)) begin\n", indexSyndrome+1, indexSyndrome+1);
1484
      }
1485
 
1486
 
1487
      fprintf(OutFileTop, "            degreeErrorReg   <= 1'b0;\n");
1488
      fprintf(OutFileTop, "         end\n");
1489
      */
1490
      fprintf(OutFileTop, "         else begin\n");
1491
      fprintf(OutFileTop, "            degreeErrorReg   <= 1'b1;\n");
1492
      fprintf(OutFileTop, "         end\n");
1493
      fprintf(OutFileTop, "      end\n");
1494
      fprintf(OutFileTop, "   end\n");
1495
      fprintf(OutFileTop, "\n\n\n");
1496
   }
1497
 
1498
   //------------------------------------------------------------------
1499
   // + numErrorReg
1500
   //------------------------------------------------------------------
1501
   if (errorStats == 1) {
1502
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1503
      fprintf(OutFileTop, "   // + numErrorReg\n");
1504
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1505
//      fprintf(OutFileTop, "   reg    [%d:0]   numErrorReg;\n",indexSyndrome-1);
1506
      fprintf(OutFileTop, "   reg    [%d:0]   numErrorReg;\n",indexSyndrome);
1507
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1508
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1509
      fprintf(OutFileTop, "         numErrorReg [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
1510
      fprintf(OutFileTop, "      end\n");
1511
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneReg[0] == 1'b1)) begin\n");
1512
      fprintf(OutFileTop, "         numErrorReg [%d:0] <= numErrorChien[%d:0];\n",indexSyndrome,indexSyndrome);
1513
      fprintf(OutFileTop, "      end\n");
1514
      fprintf(OutFileTop, "   end\n");
1515
      fprintf(OutFileTop, "\n\n\n");
1516
   }
1517
 
1518
 
1519
   //------------------------------------------------------------------
1520
   // + failErasureReg
1521
   //------------------------------------------------------------------
1522
/*   if (passFailFlag == 1){
1523
      if (ErasureOption == 1) {
1524
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1525
         fprintf(OutFileTop, "   // + failErasureReg\n");
1526
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1527
         fprintf(OutFileTop, "   reg    [%d:0]   failErasureReg;\n", indexSyndrome);
1528
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1529
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1530
         fprintf(OutFileTop, "         failErasureReg [%d:0] <= %d'd0;\n", indexSyndrome, indexSyndrome+1);
1531
         fprintf(OutFileTop, "      end\n");
1532
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && ((doneErasure == 1'b1) || (doneChien == 1'b1))) begin\n");
1533
         fprintf(OutFileTop, "         failErasureReg [%d:0] <= {failErasure, failErasureReg[%d:1]};\n", indexSyndrome, indexSyndrome);
1534
         fprintf(OutFileTop, "      end\n");
1535
         fprintf(OutFileTop, "   end\n");
1536
         fprintf(OutFileTop, "\n\n\n");
1537
      }
1538
   }*/
1539
 
1540
   if (passFailFlag == 1){
1541
      if (ErasureOption == 1) {
1542
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1543
         fprintf(OutFileTop, "   // + failErasureReg\n");
1544
         fprintf(OutFileTop, "   //-\n");
1545
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1546
         fprintf(OutFileTop, "   reg failErasureReg;\n");
1547
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1548
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1549
         fprintf(OutFileTop, "         failErasureReg   <= 1'b0;\n");
1550
         fprintf(OutFileTop, "      end\n");
1551
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneErasure == 1'b1)) begin\n");
1552
         fprintf(OutFileTop, "         failErasureReg   <= failErasure;\n");
1553
         fprintf(OutFileTop, "      end\n");
1554
         fprintf(OutFileTop, "   end\n");
1555
         fprintf(OutFileTop, "\n\n\n");
1556
 
1557
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1558
         fprintf(OutFileTop, "   // + failErasureReg2\n");
1559
         fprintf(OutFileTop, "   //-\n");
1560
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1561
         fprintf(OutFileTop, "   reg failErasureReg2;\n");
1562
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1563
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1564
         fprintf(OutFileTop, "         failErasureReg2   <= 1'b0;\n");
1565
         fprintf(OutFileTop, "      end\n");
1566
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (donePolymul == 1'b1)) begin\n");
1567
         fprintf(OutFileTop, "         failErasureReg2   <= failErasureReg;\n");
1568
         fprintf(OutFileTop, "      end\n");
1569
         fprintf(OutFileTop, "   end\n");
1570
         fprintf(OutFileTop, "\n\n\n");
1571
 
1572
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1573
         fprintf(OutFileTop, "   // + failErasureReg3\n");
1574
         fprintf(OutFileTop, "   //-\n");
1575
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1576
         fprintf(OutFileTop, "   reg failErasureReg3;\n");
1577
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1578
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1579
         fprintf(OutFileTop, "         failErasureReg3   <= 1'b0;\n");
1580
         fprintf(OutFileTop, "      end\n");
1581
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneEuclide == 1'b1)) begin\n");
1582
         fprintf(OutFileTop, "         failErasureReg3   <= failErasureReg2;\n");
1583
         fprintf(OutFileTop, "      end\n");
1584
         fprintf(OutFileTop, "   end\n");
1585
         fprintf(OutFileTop, "\n\n\n");
1586
 
1587
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1588
         fprintf(OutFileTop, "   // + failErasureReg4\n");
1589
         fprintf(OutFileTop, "   //-\n");
1590
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1591
         fprintf(OutFileTop, "   reg failErasureReg4;\n");
1592
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1593
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1594
         fprintf(OutFileTop, "         failErasureReg4   <= 1'b0;\n");
1595
         fprintf(OutFileTop, "      end\n");
1596
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneShiftReg == 1'b1)) begin\n");
1597
         fprintf(OutFileTop, "         failErasureReg4   <= failErasureReg3;\n");
1598
         fprintf(OutFileTop, "      end\n");
1599
         fprintf(OutFileTop, "   end\n");
1600
         fprintf(OutFileTop, "\n\n\n");
1601
 
1602
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1603
         fprintf(OutFileTop, "   // + failErasureReg5\n");
1604
         fprintf(OutFileTop, "   //-\n");
1605
         fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1606
         fprintf(OutFileTop, "   reg failErasureReg5;\n");
1607
         fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1608
         fprintf(OutFileTop, "      if (~RESET) begin\n");
1609
         fprintf(OutFileTop, "         failErasureReg5   <= 1'b0;\n");
1610
         fprintf(OutFileTop, "      end\n");
1611
         fprintf(OutFileTop, "      else if ((enable == 1'b1) && (startReg[1]  == 1'b1)) begin\n");
1612
         fprintf(OutFileTop, "         failErasureReg5   <= failErasureReg4;\n");
1613
         fprintf(OutFileTop, "      end\n");
1614
         fprintf(OutFileTop, "   end\n");
1615
         fprintf(OutFileTop, "\n\n\n");
1616
 
1617
 
1618
      }
1619
   }
1620
 
1621
 
1622
   //------------------------------------------------------------------
1623
   // + failReg
1624
   //------------------------------------------------------------------
1625
   if (passFailFlag == 1){
1626
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1627
      fprintf(OutFileTop, "   // + failReg\n");
1628
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1629
      fprintf(OutFileTop, "   reg          failReg;\n\n");
1630
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1631
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1632
      fprintf(OutFileTop, "         failReg <= 1'b0;\n");
1633
      fprintf(OutFileTop, "      end\n");
1634
      fprintf(OutFileTop, "      else if ((enable == 1'b1) && (doneReg[0] == 1'b1)) begin\n");
1635
      if (ErasureOption == 1) {
1636
//         fprintf(OutFileTop, "         if ((numErrorLambdaReg == numErrorChien) && (degreeErrorReg == 1'b0) && (failErasureReg[0] == 1'b0)) begin\n");
1637
         fprintf(OutFileTop, "         if ((numErrorLambdaReg == numErrorChien) && (degreeErrorReg == 1'b0) && (failErasureReg5 == 1'b0)) begin\n");
1638
      } else {
1639
         if (indexSyndrome == (degreeTemp-1)) {
1640
            fprintf(OutFileTop, "         if ((numErrorLambdaReg == numErrorChien) && (degreeErrorReg == 1'b0)) begin\n");
1641
         }else{
1642
            fprintf(OutFileTop, "         if (({%d'd0, numErrorLambdaReg} == numErrorChien) && (degreeErrorReg == 1'b0)) begin\n", indexSyndrome - (degreeTemp-1));
1643
         }
1644
      }
1645
      fprintf(OutFileTop, "            failReg <= 1'b0;\n");
1646
      fprintf(OutFileTop, "         end\n");
1647
      fprintf(OutFileTop, "         else begin\n");
1648
      fprintf(OutFileTop, "            failReg <= 1'b1;\n");
1649
      fprintf(OutFileTop, "         end\n");
1650
      fprintf(OutFileTop, "      end\n");
1651
      fprintf(OutFileTop, "   end\n");
1652
      fprintf(OutFileTop, "\n\n\n");
1653
   }
1654
 
1655
 
1656
 
1657
   //------------------------------------------------------------------
1658
   // + DataOutInner
1659
   //------------------------------------------------------------------
1660
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1661
   fprintf(OutFileTop, "   // + DataOutInner\n");
1662
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1663
   fprintf(OutFileTop, "   reg [%d:0]   DataOutInner;\n", bitSymbol-1);
1664
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1665
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1666
   fprintf(OutFileTop, "         DataOutInner <= %d'd0;\n", bitSymbol);
1667
   fprintf(OutFileTop, "      end\n");
1668
   fprintf(OutFileTop, "      else begin\n");
1669
   fprintf(OutFileTop, "         DataOutInner <= delayedDataIn ^ error;\n");
1670
   fprintf(OutFileTop, "      end\n");
1671
   fprintf(OutFileTop, "   end\n");
1672
   fprintf(OutFileTop, "\n\n\n");
1673
 
1674
 
1675
 
1676
   //------------------------------------------------------------------
1677
   // + DelayedDataOutInner
1678
   //------------------------------------------------------------------
1679
   if (delayDataIn == 1){
1680
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1681
      fprintf(OutFileTop, "   // + DelayedDataOutInner\n");
1682
      fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1683
      fprintf(OutFileTop, "   reg [%d:0]   DelayedDataOutInner;\n", bitSymbol-1);
1684
      fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1685
      fprintf(OutFileTop, "      if (~RESET) begin\n");
1686
      fprintf(OutFileTop, "         DelayedDataOutInner <= %d'd0;\n", bitSymbol);
1687
      fprintf(OutFileTop, "      end\n");
1688
      fprintf(OutFileTop, "      else begin\n");
1689
      fprintf(OutFileTop, "         DelayedDataOutInner <= delayedDataIn;\n");
1690
      fprintf(OutFileTop, "      end\n");
1691
      fprintf(OutFileTop, "   end\n");
1692
      fprintf(OutFileTop, "\n\n\n");
1693
   }
1694
 
1695
 
1696
   //------------------------------------------------------------------
1697
   //- enableFF
1698
   //------------------------------------------------------------------
1699
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1700
   fprintf(OutFileTop, "   // - enableFF \n");
1701
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1702
   fprintf(OutFileTop, "   reg       enableFF;\n");
1703
   fprintf(OutFileTop, "\n\n");
1704
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1705
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1706
   fprintf(OutFileTop, "         enableFF <= 1'b0;\n");
1707
   fprintf(OutFileTop, "      end\n");
1708
   fprintf(OutFileTop, "      else begin\n");
1709
   fprintf(OutFileTop, "         enableFF <= enable;\n");
1710
   fprintf(OutFileTop, "      end\n");
1711
   fprintf(OutFileTop, "   end\n");
1712
   fprintf(OutFileTop, "\n\n\n");
1713
 
1714
 
1715
   //------------------------------------------------------------------
1716
   //- FF for outputs
1717
   //------------------------------------------------------------------
1718
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1719
   fprintf(OutFileTop, "   // - FF for Outputs \n");
1720
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1721
   fprintf(OutFileTop, "   reg         startRegInner;\n");
1722
   fprintf(OutFileTop, "   reg         doneRegInner;\n");
1723
 
1724
   if (errorStats == 1) {
1725
      fprintf(OutFileTop, "   reg [%d:0]   numErrorRegInner;\n", bitSymbol-1);
1726
      if (ErasureOption == 1) {
1727
         fprintf(OutFileTop, "   reg [%d:0]   numErasureRegInner;\n", bitSymbol-1);
1728
      }
1729
   }
1730
 
1731
 
1732
   if (passFailFlag == 1){
1733
      fprintf(OutFileTop, "   reg         failRegInner;\n");
1734
   }
1735
 
1736
   fprintf(OutFileTop, "\n\n");
1737
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1738
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1739
   fprintf(OutFileTop, "         startRegInner       <= 1'b0;\n");
1740
   fprintf(OutFileTop, "         doneRegInner        <= 1'b0;\n");
1741
 
1742
   if (errorStats == 1) {
1743
      fprintf(OutFileTop, "         numErrorRegInner    <= %d'd0;\n", bitSymbol);
1744
      if (ErasureOption == 1) {
1745
         fprintf(OutFileTop, "         numErasureRegInner  <= %d'd0;\n", bitSymbol);
1746
      }
1747
   }
1748
 
1749
   if (passFailFlag == 1){
1750
      fprintf(OutFileTop, "         failRegInner        <= 1'b0;\n");
1751
   }
1752
   fprintf(OutFileTop, "      end\n");
1753
   fprintf(OutFileTop, "      else begin\n");
1754
   fprintf(OutFileTop, "         startRegInner       <= startReg[0];\n");
1755
   fprintf(OutFileTop, "         doneRegInner        <= doneReg[0];\n");
1756
 
1757
 
1758
   if (errorStats == 1) {
1759
//      fprintf(OutFileTop, "         numErrorRegInner    <= { 1'd0, numErrorReg[%d:0]};\n", indexSyndrome-1);
1760
/*      if (indexSyndrome < bitSymbol) {
1761
         fprintf(OutFileTop, "         numErrorRegInner    <= { %d'd0, numErrorReg[%d:0]};\n", bitSymbol-indexSyndrome, indexSyndrome-1);
1762
      }else{
1763
         fprintf(OutFileTop, "         numErrorRegInner    <= numErrorReg[%d:0];\n", indexSyndrome-1);
1764
      }*/
1765
      if ((indexSyndrome+1) < bitSymbol) {
1766
         fprintf(OutFileTop, "         numErrorRegInner    <= { %d'd0, numErrorReg[%d:0]};\n", bitSymbol-1-indexSyndrome, indexSyndrome);
1767
      }else{
1768
         fprintf(OutFileTop, "         numErrorRegInner    <= numErrorReg[%d:0];\n", indexSyndrome);
1769
      }
1770
 
1771
 
1772
 
1773
      if (ErasureOption == 1) {
1774
//         fprintf(OutFileTop, "         numErasureRegInner  <= numErasureReg[%d:0];\n", indexSyndrome);
1775
         if ((indexSyndrome+1) < bitSymbol) {
1776
            fprintf(OutFileTop, "         numErasureRegInner  <= { %d'd0, numErasureReg[%d:0]};\n", bitSymbol-1-indexSyndrome, indexSyndrome);
1777
         }else{
1778
            fprintf(OutFileTop, "         numErasureRegInner  <= numErasureReg[%d:0];\n", indexSyndrome);
1779
         }
1780
      }
1781
   }
1782
 
1783
   if (passFailFlag == 1){
1784
      fprintf(OutFileTop, "         failRegInner        <= failReg;\n");
1785
   }
1786
   fprintf(OutFileTop, "      end\n");
1787
   fprintf(OutFileTop, "   end\n");
1788
   fprintf(OutFileTop, "\n\n\n");
1789
 
1790
 
1791
 
1792
   //------------------------------------------------------------------
1793
   //- OutputValidRegInner
1794
   //------------------------------------------------------------------
1795
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1796
   fprintf(OutFileTop, "   // - OutputValidRegInner \n");
1797
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1798
   fprintf(OutFileTop, "   reg         OutputValidRegInner;\n\n");
1799
 
1800
   fprintf(OutFileTop, "   always @(posedge CLK or negedge RESET) begin\n");
1801
   fprintf(OutFileTop, "      if (~RESET) begin\n");
1802
   fprintf(OutFileTop, "         OutputValidRegInner <= 1'b0;\n");
1803
   fprintf(OutFileTop, "      end\n");
1804
   fprintf(OutFileTop, "      else if (enableFF == 1'b1) begin\n");
1805
   fprintf(OutFileTop, "         OutputValidRegInner <= OutputValidReg;\n");
1806
   fprintf(OutFileTop, "      end\n");
1807
   fprintf(OutFileTop, "      else begin\n");
1808
   fprintf(OutFileTop, "         OutputValidRegInner <= 1'b0;\n");
1809
   fprintf(OutFileTop, "      end\n");
1810
   fprintf(OutFileTop, "   end\n");
1811
   fprintf(OutFileTop, "\n\n\n");
1812
 
1813
 
1814
   //------------------------------------------------------------------
1815
   // - Output Ports
1816
   //------------------------------------------------------------------
1817
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1818
   fprintf(OutFileTop, "   // - Output Ports\n");
1819
   fprintf(OutFileTop, "   //------------------------------------------------------------------\n");
1820
   fprintf(OutFileTop, "   assign   outEnable   = OutputValidRegInner;\n");
1821
   fprintf(OutFileTop, "   assign   outStartPls = startRegInner;\n");
1822
   fprintf(OutFileTop, "   assign   outDone     = doneRegInner;\n");
1823
   fprintf(OutFileTop, "   assign   outData     = DataOutInner;\n");
1824
 
1825
 
1826
   if (errorStats == 1) {
1827
      fprintf(OutFileTop, "   assign   errorNum    = numErrorRegInner;\n");
1828
      if (ErasureOption == 1) {
1829
         fprintf(OutFileTop, "   assign   erasureNum  = numErasureRegInner;\n");
1830
      }
1831
   }
1832
 
1833
   if (delayDataIn == 1){
1834
      fprintf(OutFileTop, "   assign   delayedData = DelayedDataOutInner;\n");
1835
   }
1836
 
1837
   if (passFailFlag == 1){
1838
      fprintf(OutFileTop, "   assign   fail        = failRegInner;\n");
1839
   }
1840
   fprintf(OutFileTop, "\n\n");
1841
   fprintf(OutFileTop, "endmodule\n");
1842
 
1843
 
1844
 
1845
   //---------------------------------------------------------------
1846
  // close file
1847
  //---------------------------------------------------------------
1848
   fclose(OutFileTop);
1849
 
1850
 
1851
   //---------------------------------------------------------------
1852
   // automatically convert Dos mode To Unix mode
1853
   //---------------------------------------------------------------
1854
        char ch;
1855
        char temp[MAX_PATH]="\0";
1856
 
1857
        //Open the file for reading in binarymode.
1858
        ifstream fp_read(strRsDecodeTop, ios_base::in | ios_base::binary);
1859
        sprintf(temp, "%s.temp", strRsDecodeTop);
1860
        //Create a temporary file for writing in the binary mode. This
1861
        //file will be created in the same directory as the input file.
1862
        ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
1863
 
1864
        while(fp_read.eof() != true)
1865
        {
1866
                fp_read.get(ch);
1867
                //Check for CR (carriage return)
1868
                if((int)ch == 0x0D)
1869
                        continue;
1870
                if (!fp_read.eof())fp_write.put(ch);
1871
        }
1872
 
1873
        fp_read.close();
1874
        fp_write.close();
1875
        //Delete the existing input file.
1876
        remove(strRsDecodeTop);
1877
        //Rename the temporary file to the input file.
1878
        rename(temp, strRsDecodeTop);
1879
        //Delete the temporary file.
1880
        remove(temp);
1881
 
1882
 
1883
   //---------------------------------------------------------------
1884
   // clean string
1885
   //---------------------------------------------------------------
1886
   free(strRsDecodeTop);
1887
 
1888
 
1889
}

powered by: WebSVN 2.1.0

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