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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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