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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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