1 |
2 |
issei |
//===================================================================
|
2 |
|
|
// Module Name : RsEncodeTop
|
3 |
|
|
// File Name : RsEncodeTop.cpp
|
4 |
|
|
// Function : RTL Encoder Top Module generation
|
5 |
|
|
//
|
6 |
|
|
// Revision History:
|
7 |
|
|
// Date By Version Change Description
|
8 |
|
|
//===================================================================
|
9 |
|
|
// 2009/02/03 Gael Sapience 1.0 Original
|
10 |
|
|
//
|
11 |
|
|
//===================================================================
|
12 |
|
|
// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.
|
13 |
|
|
//
|
14 |
|
|
#include <stdio.h>
|
15 |
|
|
#include <stdlib.h>
|
16 |
|
|
#include <ctime>
|
17 |
|
|
#include<windows.h>
|
18 |
|
|
#include<fstream>
|
19 |
|
|
#include <string.h>
|
20 |
|
|
using namespace std;
|
21 |
|
|
FILE *OutFileEncodeTop;
|
22 |
|
|
|
23 |
|
|
void RsGfMultiplier( int*, int*,int*, int, int);
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
void RsEncodeTop(int DataSize, int TotalSize, int PrimPoly, int bitSymbol, int *coeffTab, int *MrefTab, int *PrefTab, int pathFlag, int lengthPath, char *rootFolderPath) {
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
//---------------------------------------------------------------
|
30 |
|
|
// C parameters
|
31 |
|
|
//---------------------------------------------------------------
|
32 |
|
|
int syndromeLength;
|
33 |
|
|
syndromeLength = TotalSize - DataSize;
|
34 |
|
|
|
35 |
|
|
int ii,jj,zz;
|
36 |
|
|
int countSize;
|
37 |
|
|
int flag;
|
38 |
|
|
int flagIndex;
|
39 |
|
|
int Pidx;
|
40 |
|
|
int init;
|
41 |
|
|
int idx1;
|
42 |
|
|
int idx2;
|
43 |
|
|
int idx;
|
44 |
|
|
int tempNum;
|
45 |
|
|
int LoopSize;
|
46 |
|
|
int Temp;
|
47 |
|
|
int mmTabSize = (bitSymbol*2) -1;
|
48 |
|
|
|
49 |
|
|
int *ttTab;
|
50 |
|
|
int *bbTab;
|
51 |
|
|
int *ppTab;
|
52 |
|
|
int *bidon;
|
53 |
|
|
char *strRsEncodeTop;
|
54 |
|
|
|
55 |
|
|
ttTab = new int[bitSymbol];
|
56 |
|
|
bbTab = new int[bitSymbol];
|
57 |
|
|
ppTab = new int[bitSymbol];
|
58 |
|
|
bidon = new int[bitSymbol];
|
59 |
|
|
//---------------------------------------------------------------
|
60 |
|
|
// open file
|
61 |
|
|
//---------------------------------------------------------------
|
62 |
|
|
strRsEncodeTop = (char *)calloc(lengthPath + 20, sizeof(char));
|
63 |
|
|
if (pathFlag == 0) {
|
64 |
|
|
strRsEncodeTop[0] = '.';
|
65 |
|
|
}else{
|
66 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
67 |
|
|
strRsEncodeTop[ii] = rootFolderPath[ii];
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
strcat(strRsEncodeTop, "/rtl/RsEncodeTop.v");
|
71 |
|
|
|
72 |
|
|
OutFileEncodeTop = fopen(strRsEncodeTop,"w");
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
//---------------------------------------------------------------
|
76 |
|
|
// Ports Declaration
|
77 |
|
|
//---------------------------------------------------------------
|
78 |
|
|
|
79 |
|
|
fprintf(OutFileEncodeTop, "//===================================================================\n");
|
80 |
|
|
fprintf(OutFileEncodeTop, "// Module Name : RsEncodeTop\n");
|
81 |
|
|
fprintf(OutFileEncodeTop, "// File Name : RsEncodeTop.v\n");
|
82 |
|
|
fprintf(OutFileEncodeTop, "// Function : Rs Encoder Top Module\n");
|
83 |
|
|
fprintf(OutFileEncodeTop, "// \n");
|
84 |
|
|
fprintf(OutFileEncodeTop, "// Revision History:\n");
|
85 |
|
|
fprintf(OutFileEncodeTop, "// Date By Version Change Description\n");
|
86 |
|
|
fprintf(OutFileEncodeTop, "//===================================================================\n");
|
87 |
|
|
fprintf(OutFileEncodeTop, "// 2009/02/03 Gael Sapience 1.0 Original\n");
|
88 |
|
|
fprintf(OutFileEncodeTop, "//\n");
|
89 |
|
|
fprintf(OutFileEncodeTop, "//===================================================================\n");
|
90 |
|
|
fprintf(OutFileEncodeTop, "// (C) COPYRIGHT 2009 SYSTEM LSI CO., Ltd.\n");
|
91 |
|
|
fprintf(OutFileEncodeTop, "//\n\n\n");
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
fprintf(OutFileEncodeTop, "module RsEncodeTop(\n");
|
96 |
|
|
fprintf(OutFileEncodeTop, " CLK, // system clock\n");
|
97 |
|
|
fprintf(OutFileEncodeTop, " RESET, // system reset\n");
|
98 |
|
|
fprintf(OutFileEncodeTop, " enable, // rs encoder enable signal\n");
|
99 |
|
|
fprintf(OutFileEncodeTop, " startPls, // rs encoder sync signal\n");
|
100 |
|
|
fprintf(OutFileEncodeTop, " dataIn, // rs encoder data in\n");
|
101 |
|
|
fprintf(OutFileEncodeTop, " dataOut // rs encoder data out\n");
|
102 |
|
|
fprintf(OutFileEncodeTop, ");\n\n\n");
|
103 |
|
|
fprintf(OutFileEncodeTop, " input CLK; // system clock\n");
|
104 |
|
|
fprintf(OutFileEncodeTop, " input RESET; // system reset\n");
|
105 |
|
|
fprintf(OutFileEncodeTop, " input enable; // rs encoder enable signal\n");
|
106 |
|
|
fprintf(OutFileEncodeTop, " input startPls; // rs encoder sync signal\n");
|
107 |
|
|
fprintf(OutFileEncodeTop, " input [%d:0] dataIn; // rs encoder data in\n", (bitSymbol-1));
|
108 |
|
|
fprintf(OutFileEncodeTop, " output [%d:0] dataOut; // rs encoder data out\n", (bitSymbol-1));
|
109 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
//---------------------------------------------------------------
|
113 |
|
|
//- registers
|
114 |
|
|
//---------------------------------------------------------------
|
115 |
|
|
countSize = 0;
|
116 |
|
|
|
117 |
|
|
if (TotalSize > 2047) {
|
118 |
|
|
countSize = 12;
|
119 |
|
|
} else{
|
120 |
|
|
if (TotalSize > 1023) {
|
121 |
|
|
countSize = 11;
|
122 |
|
|
} else{
|
123 |
|
|
if (TotalSize > 511) {
|
124 |
|
|
countSize = 10;
|
125 |
|
|
}else{
|
126 |
|
|
if (TotalSize > 255) {
|
127 |
|
|
countSize = 9;
|
128 |
|
|
}else{
|
129 |
|
|
if (TotalSize > 127) {
|
130 |
|
|
countSize = 8;
|
131 |
|
|
}else{
|
132 |
|
|
if (TotalSize > 63) {
|
133 |
|
|
countSize = 7;
|
134 |
|
|
}else{
|
135 |
|
|
if (TotalSize > 31) {
|
136 |
|
|
countSize = 6;
|
137 |
|
|
}else{
|
138 |
|
|
if (TotalSize > 15) {
|
139 |
|
|
countSize = 5;
|
140 |
|
|
}else{
|
141 |
|
|
if (TotalSize > 7) {
|
142 |
|
|
countSize = 4;
|
143 |
|
|
}else{
|
144 |
|
|
if (TotalSize > 3) {
|
145 |
|
|
countSize = 3;
|
146 |
|
|
}else{
|
147 |
|
|
countSize = 2;
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
160 |
|
|
fprintf(OutFileEncodeTop, " //- registers\n");
|
161 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
162 |
|
|
// fprintf(OutFileEncodeTop, " reg [%d:0] count;\n", bitSymbol);
|
163 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] count;\n", countSize-1);
|
164 |
|
|
fprintf(OutFileEncodeTop, " reg dataValid;\n");
|
165 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] feedbackReg;\n", (bitSymbol-1));
|
166 |
|
|
for(ii=0; ii<syndromeLength; ii++){
|
167 |
|
|
fprintf(OutFileEncodeTop, " wire [%d:0] mult_%d;\n", (bitSymbol-1), ii);
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
for(ii=0; ii<syndromeLength; ii++){
|
171 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] syndromeReg_%d;\n", (bitSymbol-1), ii);
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] dataReg;\n", (bitSymbol-1));
|
175 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] syndromeRegFF;\n", (bitSymbol-1));
|
176 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] wireOut;\n", (bitSymbol-1));
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
//-----------------------------------------------------------------------
|
180 |
|
|
// + genPolynomCoeff_
|
181 |
|
|
//------------------------------------------------------------------------
|
182 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
//-----------------------------------------------------------------------
|
186 |
|
|
// count
|
187 |
|
|
//------------------------------------------------------------------------
|
188 |
|
|
|
189 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
190 |
|
|
fprintf(OutFileEncodeTop, " //- count\n");
|
191 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
192 |
|
|
fprintf(OutFileEncodeTop, " always @(posedge CLK or negedge RESET) begin\n");
|
193 |
|
|
fprintf(OutFileEncodeTop, " if (~RESET) begin\n");
|
194 |
|
|
// fprintf(OutFileEncodeTop, " count [%d:0] <= %d'd0;\n", bitSymbol, (bitSymbol+1));
|
195 |
|
|
fprintf(OutFileEncodeTop, " count [%d:0] <= %d'd0;\n", (countSize-1), countSize);
|
196 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
197 |
|
|
fprintf(OutFileEncodeTop, " else if (enable == 1'b1) begin\n");
|
198 |
|
|
fprintf(OutFileEncodeTop, " if (startPls == 1'b1) begin\n");
|
199 |
|
|
// fprintf(OutFileEncodeTop, " count[%d:0] <= %d'd1;\n", bitSymbol, (bitSymbol+1));
|
200 |
|
|
fprintf(OutFileEncodeTop, " count[%d:0] <= %d'd1;\n", (countSize-1), countSize);
|
201 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
202 |
|
|
// fprintf(OutFileEncodeTop, " else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n", bitSymbol, (bitSymbol+1), bitSymbol, (bitSymbol+1), TotalSize);
|
203 |
|
|
fprintf(OutFileEncodeTop, " else if ((count[%d:0] ==%d'd0) || (count[%d:0] ==%d'd%d)) begin\n", (countSize-1), countSize, (countSize-1), countSize, TotalSize);
|
204 |
|
|
// fprintf(OutFileEncodeTop, " count[%d:0] <= %d'd0;\n", bitSymbol, (bitSymbol+1));
|
205 |
|
|
fprintf(OutFileEncodeTop, " count[%d:0] <= %d'd0;\n", (countSize-1), countSize);
|
206 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
207 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
208 |
|
|
// fprintf(OutFileEncodeTop, " count[%d:0] <= count[%d:0] + %d'd1;\n", bitSymbol, bitSymbol, (bitSymbol+1));
|
209 |
|
|
fprintf(OutFileEncodeTop, " count[%d:0] <= count[%d:0] + %d'd1;\n", (countSize-1), (countSize-1), countSize);
|
210 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
211 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
212 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
213 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
//-----------------------------------------------------------------------
|
217 |
|
|
// dataValid
|
218 |
|
|
//------------------------------------------------------------------------
|
219 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
220 |
|
|
fprintf(OutFileEncodeTop, " //- dataValid\n");
|
221 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
222 |
|
|
fprintf(OutFileEncodeTop, " always @(count or startPls) begin\n");
|
223 |
|
|
// fprintf(OutFileEncodeTop, " if (startPls == 1'b1 || (count[%d:0] < %d'd%d)) begin\n", bitSymbol, (bitSymbol+1), DataSize);
|
224 |
|
|
fprintf(OutFileEncodeTop, " if (startPls == 1'b1 || (count[%d:0] < %d'd%d)) begin\n", (countSize-1), countSize, DataSize);
|
225 |
|
|
// fprintf(OutFileEncodeTop, " dataValid <= 1'b1;\n");
|
226 |
|
|
fprintf(OutFileEncodeTop, " dataValid = 1'b1;\n");
|
227 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
228 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
229 |
|
|
// fprintf(OutFileEncodeTop, " dataValid <= 1'b0;\n");
|
230 |
|
|
fprintf(OutFileEncodeTop, " dataValid = 1'b0;\n");
|
231 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
232 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
233 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n\n");
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
//-----------------------------------------------------------------------
|
237 |
|
|
// Multipliers
|
238 |
|
|
//------------------------------------------------------------------------
|
239 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
240 |
|
|
fprintf(OutFileEncodeTop, " //- Multipliers\n");
|
241 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
//-----------------------------------------------------------------------
|
245 |
|
|
//-----------------------------------------------------------------------
|
246 |
|
|
// Multplication Process
|
247 |
|
|
//-----------------------------------------------------------------------
|
248 |
|
|
//-----------------------------------------------------------------------
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
//------------------------------------------------------------------------
|
254 |
|
|
// initialize ttTab
|
255 |
|
|
//------------------------------------------------------------------------
|
256 |
|
|
ttTab[0] = 1;
|
257 |
|
|
for (ii=1;ii<bitSymbol;ii++){
|
258 |
|
|
ttTab[ii] = 0;
|
259 |
|
|
}
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
//------------------------------------------------------------------------
|
263 |
|
|
// initialize bbTab
|
264 |
|
|
//------------------------------------------------------------------------
|
265 |
|
|
bbTab[0] = 0;
|
266 |
|
|
bbTab[1] = 1;
|
267 |
|
|
for (ii=2;ii<bitSymbol;ii++){
|
268 |
|
|
bbTab[ii] = 0;
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
//------------------------------------------------------------------------
|
273 |
|
|
// initialize LoopSize
|
274 |
|
|
//------------------------------------------------------------------------
|
275 |
|
|
LoopSize = 2;
|
276 |
|
|
for(ii=0; ii<(bitSymbol-1); ii++){
|
277 |
|
|
LoopSize = LoopSize*2;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
//------------------------------------------------------------------------
|
282 |
|
|
// if coeefTab is null
|
283 |
|
|
//------------------------------------------------------------------------
|
284 |
|
|
for(jj=0; jj<syndromeLength; jj++){
|
285 |
|
|
if (coeffTab[jj] == 0) {
|
286 |
|
|
for (idx2=0; idx2<bitSymbol;idx2++){
|
287 |
|
|
fprintf(OutFileEncodeTop, " assign mult_%d[%d] = feedbackReg[%d];\n", jj, idx2, idx2);
|
288 |
|
|
}
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
for(ii=1; ii<LoopSize; ii++){
|
294 |
|
|
//------------------------------------------------------------------------
|
295 |
|
|
// ppTab = ttTab * bbTab
|
296 |
|
|
//------------------------------------------------------------------------
|
297 |
|
|
RsGfMultiplier(ppTab, ttTab, bbTab, PrimPoly, bitSymbol);
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
//------------------------------------------------------------------------
|
301 |
|
|
// reassign ttTab
|
302 |
|
|
//------------------------------------------------------------------------
|
303 |
|
|
for (jj=0;jj<bitSymbol;jj++){
|
304 |
|
|
ttTab[jj] = ppTab[jj];
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
flag = 0;
|
309 |
|
|
flagIndex = 0;
|
310 |
|
|
for(jj=0; jj<syndromeLength; jj++){
|
311 |
|
|
flag = 0;
|
312 |
|
|
flagIndex = 0;
|
313 |
|
|
if (coeffTab[jj] == ii) {
|
314 |
|
|
flag = 1;
|
315 |
|
|
flagIndex = jj;
|
316 |
|
|
|
317 |
|
|
//------------------------------------------------------------------------
|
318 |
|
|
// printf P_OUT[]
|
319 |
|
|
//------------------------------------------------------------------------
|
320 |
|
|
for (Pidx=0; Pidx<bitSymbol; Pidx++){
|
321 |
|
|
if (flag == 1) {
|
322 |
|
|
fprintf(OutFileEncodeTop, " assign mult_%d[%d] = ", flagIndex, Pidx);
|
323 |
|
|
}
|
324 |
|
|
init = 0;
|
325 |
|
|
|
326 |
|
|
for (idx2=0; idx2<bitSymbol;idx2++){
|
327 |
|
|
bidon [idx2] = 0;
|
328 |
|
|
}
|
329 |
|
|
|
330 |
|
|
for (idx1=0; idx1<mmTabSize;idx1++){
|
331 |
|
|
tempNum = PrefTab [Pidx*mmTabSize+idx1];
|
332 |
|
|
if (tempNum == 1) {
|
333 |
|
|
//------------------------------------------------------------------------
|
334 |
|
|
// search
|
335 |
|
|
//------------------------------------------------------------------------
|
336 |
|
|
for (idx2=0; idx2<bitSymbol;idx2++){
|
337 |
|
|
tempNum = MrefTab[idx1*bitSymbol+idx2];
|
338 |
|
|
|
339 |
|
|
if ((tempNum > 0) && (ttTab[tempNum-1] == 1)) {
|
340 |
|
|
if (bidon [idx2] == 0) {
|
341 |
|
|
bidon [idx2] = 1;
|
342 |
|
|
}
|
343 |
|
|
else {
|
344 |
|
|
bidon [idx2] = 0;
|
345 |
|
|
}
|
346 |
|
|
}
|
347 |
|
|
}
|
348 |
|
|
}
|
349 |
|
|
}
|
350 |
|
|
//------------------------------------------------------------------------
|
351 |
|
|
// printf
|
352 |
|
|
//------------------------------------------------------------------------
|
353 |
|
|
for (idx2=0; idx2<bitSymbol; idx2++){
|
354 |
|
|
if (bidon[idx2] == 1) {
|
355 |
|
|
if (init == 0) {
|
356 |
|
|
if (flag == 1) {
|
357 |
|
|
fprintf(OutFileEncodeTop, " feedbackReg[%d]", idx2);
|
358 |
|
|
}
|
359 |
|
|
init = 1;
|
360 |
|
|
}
|
361 |
|
|
else {
|
362 |
|
|
if (flag == 1) {
|
363 |
|
|
fprintf(OutFileEncodeTop, " ^ feedbackReg[%d]", idx2);
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
}
|
368 |
|
|
if (flag == 1) {
|
369 |
|
|
fprintf(OutFileEncodeTop,";\n");
|
370 |
|
|
}
|
371 |
|
|
}
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
}
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
//-----------------------------------------------------------------------
|
379 |
|
|
//-----------------------------------------------------------------------
|
380 |
|
|
// Multplication Process
|
381 |
|
|
//-----------------------------------------------------------------------
|
382 |
|
|
//-----------------------------------------------------------------------
|
383 |
|
|
|
384 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
//-----------------------------------------------------------------------
|
388 |
|
|
// syndromeReg
|
389 |
|
|
//------------------------------------------------------------------------
|
390 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
391 |
|
|
fprintf(OutFileEncodeTop, " //- syndromeReg\n");
|
392 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
393 |
|
|
fprintf(OutFileEncodeTop, " always @(posedge CLK or negedge RESET) begin\n");
|
394 |
|
|
fprintf(OutFileEncodeTop, " if (~RESET) begin\n");
|
395 |
|
|
for (ii=0; ii < syndromeLength; ii++) {
|
396 |
|
|
if (ii < 10) {
|
397 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= %d'd0;\n", ii, (bitSymbol-1), bitSymbol);
|
398 |
|
|
}else{
|
399 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= %d'd0;\n", ii, (bitSymbol-1), bitSymbol);
|
400 |
|
|
}
|
401 |
|
|
}
|
402 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
403 |
|
|
fprintf(OutFileEncodeTop, " else if (enable == 1'b1) begin\n");
|
404 |
|
|
|
405 |
|
|
fprintf(OutFileEncodeTop, " if (startPls == 1'b1) begin\n");
|
406 |
|
|
for (ii=0; ii < syndromeLength; ii++) {
|
407 |
|
|
if (ii < 10) {
|
408 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= mult_%d [%d:0];\n", ii, (bitSymbol-1), ii, (bitSymbol-1));
|
409 |
|
|
}else{
|
410 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= mult_%d [%d:0];\n", ii, (bitSymbol-1), ii, (bitSymbol-1));
|
411 |
|
|
}
|
412 |
|
|
}
|
413 |
|
|
|
414 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
415 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
416 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_0 [%d:0] <= mult_0 [%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
417 |
|
|
for (ii=1; ii < syndromeLength; ii++){
|
418 |
|
|
if (ii < 10) {
|
419 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= (syndromeReg_%d [%d:0] ^ mult_%d [%d:0]);\n", ii,(bitSymbol-1), (ii-1),(bitSymbol-1), ii, (bitSymbol-1));
|
420 |
|
|
}else{
|
421 |
|
|
fprintf(OutFileEncodeTop, " syndromeReg_%d [%d:0] <= (syndromeReg_%d [%d:0] ^ mult_%d [%d:0]);\n", ii,(bitSymbol-1), (ii-1),(bitSymbol-1), ii, (bitSymbol-1));
|
422 |
|
|
}
|
423 |
|
|
}
|
424 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
425 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
426 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
427 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
//-----------------------------------------------------------------------
|
432 |
|
|
// feedbackReg
|
433 |
|
|
//------------------------------------------------------------------------
|
434 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
435 |
|
|
fprintf(OutFileEncodeTop, " //- feedbackReg\n");
|
436 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
437 |
|
|
fprintf(OutFileEncodeTop, " always @( startPls, dataValid, dataIn");
|
438 |
|
|
fprintf(OutFileEncodeTop, ", syndromeReg_%d",(syndromeLength-1));
|
439 |
|
|
fprintf(OutFileEncodeTop, " ) begin\n");
|
440 |
|
|
fprintf(OutFileEncodeTop, " if (startPls == 1'b1) begin\n");
|
441 |
|
|
// fprintf(OutFileEncodeTop, " feedbackReg[%d:0] <= dataIn[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
442 |
|
|
fprintf(OutFileEncodeTop, " feedbackReg[%d:0] = dataIn[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
443 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
444 |
|
|
fprintf(OutFileEncodeTop, " else if (dataValid == 1'b1) begin\n");
|
445 |
|
|
// fprintf(OutFileEncodeTop, " feedbackReg [%d:0] <= dataIn[%d:0] ^ syndromeReg_%d [%d:0];\n", (bitSymbol-1), (bitSymbol-1), (syndromeLength-1), (bitSymbol-1));
|
446 |
|
|
fprintf(OutFileEncodeTop, " feedbackReg [%d:0] = dataIn[%d:0] ^ syndromeReg_%d [%d:0];\n", (bitSymbol-1), (bitSymbol-1), (syndromeLength-1), (bitSymbol-1));
|
447 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
448 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
449 |
|
|
// fprintf(OutFileEncodeTop, " feedbackReg [%d:0] <= %d'd0;\n", (bitSymbol-1), bitSymbol);
|
450 |
|
|
fprintf(OutFileEncodeTop, " feedbackReg [%d:0] = %d'd0;\n", (bitSymbol-1), bitSymbol);
|
451 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
452 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
453 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
//-----------------------------------------------------------------------
|
458 |
|
|
// dataReg syndromeRegFF
|
459 |
|
|
//------------------------------------------------------------------------
|
460 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
461 |
|
|
fprintf(OutFileEncodeTop, " //- dataReg syndromeRegFF\n");
|
462 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
463 |
|
|
|
464 |
|
|
fprintf(OutFileEncodeTop, " always @(posedge CLK, negedge RESET) begin\n");
|
465 |
|
|
fprintf(OutFileEncodeTop, " if (~RESET) begin\n");
|
466 |
|
|
fprintf(OutFileEncodeTop, " dataReg [%d:0] <= %d'd0;\n", (bitSymbol-1), bitSymbol);
|
467 |
|
|
fprintf(OutFileEncodeTop, " syndromeRegFF [%d:0] <= %d'd0;\n", (bitSymbol-1), bitSymbol);
|
468 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
469 |
|
|
fprintf(OutFileEncodeTop, " else if (enable == 1'b1) begin\n");
|
470 |
|
|
fprintf(OutFileEncodeTop, " dataReg [%d:0] <= dataIn [%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
471 |
|
|
fprintf(OutFileEncodeTop, " syndromeRegFF [%d:0] <= syndromeReg_%d [%d:0];\n", (bitSymbol-1), (syndromeLength-1), (bitSymbol-1));
|
472 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
473 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
474 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
//-----------------------------------------------------------------------
|
478 |
|
|
// wireOut
|
479 |
|
|
//------------------------------------------------------------------------
|
480 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
481 |
|
|
fprintf(OutFileEncodeTop, " //- wireOut\n");
|
482 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
483 |
|
|
fprintf(OutFileEncodeTop, " always @( count, dataReg, syndromeRegFF) begin\n");
|
484 |
|
|
// fprintf(OutFileEncodeTop, " if (count [%d:0]<= %d'd%d) begin\n", (bitSymbol-1), bitSymbol, DataSize);
|
485 |
|
|
fprintf(OutFileEncodeTop, " if (count [%d:0]<= %d'd%d) begin\n", (countSize-1), countSize, DataSize);
|
486 |
|
|
// fprintf(OutFileEncodeTop, " wireOut[%d:0] <= dataReg[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
487 |
|
|
fprintf(OutFileEncodeTop, " wireOut[%d:0] = dataReg[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
488 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
489 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
490 |
|
|
// fprintf(OutFileEncodeTop, " wireOut[%d:0] <= syndromeRegFF[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
491 |
|
|
fprintf(OutFileEncodeTop, " wireOut[%d:0] = syndromeRegFF[%d:0];\n", (bitSymbol-1), (bitSymbol-1));
|
492 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
493 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
494 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
495 |
|
|
|
496 |
|
|
|
497 |
|
|
|
498 |
|
|
//-----------------------------------------------------------------------
|
499 |
|
|
// dataOutInner
|
500 |
|
|
//------------------------------------------------------------------------
|
501 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
502 |
|
|
fprintf(OutFileEncodeTop, " //- dataOutInner\n");
|
503 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
504 |
|
|
fprintf(OutFileEncodeTop, " reg [%d:0] dataOutInner;\n", (bitSymbol-1));
|
505 |
|
|
fprintf(OutFileEncodeTop, " always @(posedge CLK, negedge RESET) begin\n");
|
506 |
|
|
fprintf(OutFileEncodeTop, " if (~RESET) begin\n");
|
507 |
|
|
fprintf(OutFileEncodeTop, " dataOutInner <= %d'd0;\n", bitSymbol);
|
508 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
509 |
|
|
fprintf(OutFileEncodeTop, " else begin\n");
|
510 |
|
|
fprintf(OutFileEncodeTop, " dataOutInner <= wireOut;\n");
|
511 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
512 |
|
|
fprintf(OutFileEncodeTop, " end\n");
|
513 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
514 |
|
|
|
515 |
|
|
|
516 |
|
|
//-----------------------------------------------------------------------
|
517 |
|
|
// Output ports
|
518 |
|
|
//------------------------------------------------------------------------
|
519 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
520 |
|
|
fprintf(OutFileEncodeTop, " //- Output ports\n");
|
521 |
|
|
fprintf(OutFileEncodeTop, " //---------------------------------------------------------------\n");
|
522 |
|
|
fprintf(OutFileEncodeTop, " assign dataOut = dataOutInner;\n");
|
523 |
|
|
fprintf(OutFileEncodeTop, "\n\n\n");
|
524 |
|
|
|
525 |
|
|
fprintf(OutFileEncodeTop, "endmodule\n");
|
526 |
|
|
|
527 |
|
|
|
528 |
|
|
//---------------------------------------------------------------
|
529 |
|
|
// close file
|
530 |
|
|
//---------------------------------------------------------------
|
531 |
|
|
fclose(OutFileEncodeTop);
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
//---------------------------------------------------------------
|
535 |
|
|
// Free memory
|
536 |
|
|
//---------------------------------------------------------------
|
537 |
|
|
delete[] ttTab;
|
538 |
|
|
delete[] bbTab;
|
539 |
|
|
delete[] ppTab;
|
540 |
|
|
delete[] bidon;
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
//---------------------------------------------------------------
|
544 |
|
|
// automatically convert Dos mode To Unix mode
|
545 |
|
|
//---------------------------------------------------------------
|
546 |
|
|
char ch;
|
547 |
|
|
char temp[MAX_PATH]="\0";
|
548 |
|
|
|
549 |
|
|
//Open the file for reading in binarymode.
|
550 |
|
|
ifstream fp_read(strRsEncodeTop, ios_base::in | ios_base::binary);
|
551 |
|
|
sprintf(temp, "%s.temp", strRsEncodeTop);
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
|
555 |
|
|
|
556 |
|
|
//Create a temporary file for writing in the binary mode. This
|
557 |
|
|
//file will be created in the same directory as the input file.
|
558 |
|
|
ofstream fp_write(temp, ios_base::out | ios_base::trunc | ios_base::binary);
|
559 |
|
|
|
560 |
|
|
while(fp_read.eof() != true)
|
561 |
|
|
{
|
562 |
|
|
fp_read.get(ch);
|
563 |
|
|
//Check for CR (carriage return)
|
564 |
|
|
if((int)ch == 0x0D)
|
565 |
|
|
continue;
|
566 |
|
|
if (!fp_read.eof())fp_write.put(ch);
|
567 |
|
|
}
|
568 |
|
|
|
569 |
|
|
fp_read.close();
|
570 |
|
|
fp_write.close();
|
571 |
|
|
//Delete the existing input file.
|
572 |
|
|
remove(strRsEncodeTop);
|
573 |
|
|
//Rename the temporary file to the input file.
|
574 |
|
|
rename(temp, strRsEncodeTop);
|
575 |
|
|
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
//Delete the temporary file.
|
579 |
|
|
remove(temp);
|
580 |
|
|
|
581 |
|
|
|
582 |
|
|
//---------------------------------------------------------------
|
583 |
|
|
// clean string
|
584 |
|
|
//---------------------------------------------------------------
|
585 |
|
|
free(strRsEncodeTop);
|
586 |
|
|
|
587 |
|
|
|
588 |
|
|
}
|