1 |
2 |
issei |
//===================================================================
|
2 |
|
|
// Module Name : main
|
3 |
|
|
// File Name : RsIpEngine.cpp
|
4 |
|
|
// Function : main
|
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 <cstdio>
|
15 |
|
|
#include <cstdlib>
|
16 |
|
|
#include <ctime>
|
17 |
|
|
#include <iostream>
|
18 |
|
|
#include<windows.h>
|
19 |
|
|
#include<fstream>
|
20 |
|
|
#include <stdio.h>
|
21 |
|
|
#include <stdlib.h>
|
22 |
|
|
using namespace std;
|
23 |
|
|
#include <io.h>
|
24 |
|
|
#include <sys/types.h>
|
25 |
|
|
#include <sys/stat.h>
|
26 |
|
|
#include <string.h>
|
27 |
|
|
|
28 |
|
|
FILE *OutFileIPSpecs;
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
void RsEncode(int, int, int, int, int, int, int, int*, int*, int*, int, int, int, int, int, int, int, int, int, int, char*);
|
32 |
|
|
void RsGfMultiplier(int*, int*,int*, int, int);
|
33 |
|
|
void RsDecode(int, int, int, int, int, int, int, int,int,int,int,int,int, int*, int*, int*,int,int, int, int, char*);
|
34 |
|
|
void RsSimBench(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, char*);
|
35 |
|
|
void RsMrefTab(int*, int);
|
36 |
|
|
void RsPrefTab(int*, int, int);
|
37 |
|
|
|
38 |
|
|
int main(int argc, char *argv[])
|
39 |
|
|
{
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
//---------------------------------------------------------------
|
44 |
|
|
//---------------------------------------------------------------
|
45 |
|
|
//- Get Parameters from C# program
|
46 |
|
|
//---------------------------------------------------------------
|
47 |
|
|
int DataSize, TotalSize, PrimPoly, ErasureOption;
|
48 |
|
|
int BlockAmount, ErrorRate;
|
49 |
|
|
int bitSymbol;
|
50 |
|
|
int syndromeLength;
|
51 |
|
|
int syndromeMod2;
|
52 |
|
|
int ii,jj,zz;
|
53 |
|
|
int tempix;
|
54 |
|
|
int symbolMax;
|
55 |
|
|
int DecNumber;
|
56 |
|
|
int index;
|
57 |
|
|
int errorStats;
|
58 |
|
|
int passFailFlag;
|
59 |
|
|
int delayDataIn;
|
60 |
|
|
int encDecMode;
|
61 |
|
|
int encBlockAmount;
|
62 |
|
|
int ipCustomerKey;
|
63 |
|
|
int PowerErrorRate;
|
64 |
|
|
int ErasureRate;
|
65 |
|
|
int PowerErasureRate;
|
66 |
|
|
int cppCoreInternalKey;
|
67 |
|
|
int pathFlag;
|
68 |
|
|
int lengthPath;
|
69 |
|
|
|
70 |
|
|
char *rootFolderPath;
|
71 |
|
|
char *strsimReedSolomon;
|
72 |
|
|
char *strrtl;
|
73 |
|
|
char *strsim;
|
74 |
|
|
char *strRsEncIn;
|
75 |
|
|
char *strRsEncOut;
|
76 |
|
|
char *strRsDecIn;
|
77 |
|
|
char *strRsDecOut;
|
78 |
|
|
char *strRsEncodeTop;
|
79 |
|
|
char *strRsDecodeTop;
|
80 |
|
|
char *strRsDecodeSyndrome;
|
81 |
|
|
char *strRsDecodeShiftOmega;
|
82 |
|
|
char *strRsDecodePolymul;
|
83 |
|
|
char *strRsDecodeMult;
|
84 |
|
|
char *strRsDecodeInv;
|
85 |
|
|
char *strRsDecodeEuclide;
|
86 |
|
|
char *strRsDecodeErasure;
|
87 |
|
|
char *strRsDecodeDpRam;
|
88 |
|
|
char *strRsDecodeDelay;
|
89 |
|
|
char *strRsDecodeDegree;
|
90 |
|
|
char *strRsDecodeChien;
|
91 |
|
|
char *strIPSpecs;
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
//---------------------------------------------------------------
|
96 |
|
|
// cpp core internal ip key
|
97 |
|
|
//- It is the only line to change before release
|
98 |
|
|
//---------------------------------------------------------------
|
99 |
|
|
cppCoreInternalKey = 27;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
//---------------------------------------------------------------
|
104 |
|
|
// convert parameters to Int
|
105 |
|
|
//---------------------------------------------------------------
|
106 |
|
|
DataSize = atoi(argv[1]); // Data Size
|
107 |
|
|
TotalSize = atoi(argv[2]); // Total Size
|
108 |
|
|
PrimPoly = atoi(argv[3]); // Primitve Polynom
|
109 |
|
|
ErasureOption = atoi(argv[4]); // Erasure Decoding ( 0: No, 1:Yes)
|
110 |
|
|
BlockAmount = atoi(argv[5]); // RS Decoder Block Amount for Sim
|
111 |
|
|
ErrorRate = atoi(argv[6]); // Error rate
|
112 |
|
|
PowerErrorRate = atoi(argv[7]); // 0: 1, 1: 10^-1, 4: 10^-4
|
113 |
|
|
ErasureRate = atoi(argv[8]); // Erasure rate
|
114 |
|
|
PowerErasureRate = atoi(argv[9]); // 0: 1, 1: 10^-1, 4: 10^-4
|
115 |
|
|
bitSymbol = atoi(argv[10]); // range = [3..12]
|
116 |
|
|
errorStats = atoi(argv[11]); //( 0: No, 1:Yes)
|
117 |
|
|
passFailFlag = atoi(argv[12]); //( 0: No, 1:Yes)
|
118 |
|
|
delayDataIn = atoi(argv[13]); //( 0: No, 1:Yes)
|
119 |
|
|
encDecMode = atoi(argv[14]); //(1: enc only, 2:dec only, 3: enc & dec)
|
120 |
|
|
encBlockAmount = atoi(argv[15]); // encoder block amount
|
121 |
|
|
ipCustomerKey = atoi(argv[16]); // IP Key
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
//---------------------------------------------------------------
|
125 |
|
|
// check parameter amount if not 17 or 18 -> escape code
|
126 |
|
|
//---------------------------------------------------------------
|
127 |
|
|
if ((argc < 17) || (argc > 18)){
|
128 |
|
|
exit(1);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
//---------------------------------------------------------------
|
132 |
|
|
// get Root folder path if specified
|
133 |
|
|
// apthFlag= 1 if Path specified, 0 if not specified
|
134 |
|
|
//---------------------------------------------------------------
|
135 |
|
|
if (argc == 18) {
|
136 |
|
|
pathFlag = 1;
|
137 |
|
|
lengthPath = strlen(argv[17]);
|
138 |
|
|
}else{
|
139 |
|
|
pathFlag = 0;
|
140 |
|
|
lengthPath = 1;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
rootFolderPath = (char *)calloc(lengthPath, sizeof(char));
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
if (pathFlag == 1) {
|
148 |
|
|
rootFolderPath = argv[17]; // Root Folder Path
|
149 |
|
|
|
150 |
|
|
for(ii=0; ii<lengthPath; ii++){ // unify markers
|
151 |
|
|
if (rootFolderPath[ii] == '\\' ) {
|
152 |
|
|
rootFolderPath[ii] = '/';
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
}else{
|
156 |
|
|
rootFolderPath = "Z";
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
//---------------------------------------------------------------
|
161 |
|
|
// make path file strings
|
162 |
|
|
//---------------------------------------------------------------
|
163 |
|
|
strsimReedSolomon = (char *)calloc(lengthPath + 22, sizeof(char));
|
164 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
165 |
|
|
strsimReedSolomon[ii] = rootFolderPath[ii];
|
166 |
|
|
}
|
167 |
|
|
strcat(strsimReedSolomon, "/sim/simReedSolomon.v");
|
168 |
|
|
|
169 |
|
|
strRsEncIn = (char *)calloc(lengthPath + 17, sizeof(char));
|
170 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
171 |
|
|
strRsEncIn[ii] = rootFolderPath[ii];
|
172 |
|
|
}
|
173 |
|
|
strcat(strRsEncIn, "/sim/RsEncIn.hex");
|
174 |
|
|
|
175 |
|
|
strRsEncOut = (char *)calloc(lengthPath + 18, sizeof(char));
|
176 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
177 |
|
|
strRsEncOut[ii] = rootFolderPath[ii];
|
178 |
|
|
}
|
179 |
|
|
strcat(strRsEncOut, "/sim/RsEncOut.hex");
|
180 |
|
|
|
181 |
|
|
strRsDecIn = (char *)calloc(lengthPath + 17, sizeof(char));
|
182 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
183 |
|
|
strRsDecIn[ii] = rootFolderPath[ii];
|
184 |
|
|
}
|
185 |
|
|
strcat(strRsDecIn, "/sim/RsDecIn.hex");
|
186 |
|
|
|
187 |
|
|
strRsDecOut = (char *)calloc(lengthPath + 18, sizeof(char));
|
188 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
189 |
|
|
strRsDecOut[ii] = rootFolderPath[ii];
|
190 |
|
|
}
|
191 |
|
|
strcat(strRsDecOut, "/sim/RsDecOut.hex");
|
192 |
|
|
|
193 |
|
|
strRsEncodeTop = (char *)calloc(lengthPath + 19, sizeof(char));
|
194 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
195 |
|
|
strRsEncodeTop[ii] = rootFolderPath[ii];
|
196 |
|
|
}
|
197 |
|
|
strcat(strRsEncodeTop, "/rtl/RsEncodeTop.v");
|
198 |
|
|
|
199 |
|
|
strRsDecodeTop = (char *)calloc(lengthPath + 19, sizeof(char));
|
200 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
201 |
|
|
strRsDecodeTop[ii] = rootFolderPath[ii];
|
202 |
|
|
}
|
203 |
|
|
strcat(strRsDecodeTop, "/rtl/RsDecodeTop.v");
|
204 |
|
|
|
205 |
|
|
strRsDecodeSyndrome = (char *)calloc(lengthPath + 24, sizeof(char));
|
206 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
207 |
|
|
strRsDecodeSyndrome[ii] = rootFolderPath[ii];
|
208 |
|
|
}
|
209 |
|
|
strcat(strRsDecodeSyndrome, "/rtl/RsDecodeSyndrome.v");
|
210 |
|
|
|
211 |
|
|
strRsDecodeShiftOmega = (char *)calloc(lengthPath + 26, sizeof(char));
|
212 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
213 |
|
|
strRsDecodeShiftOmega[ii] = rootFolderPath[ii];
|
214 |
|
|
}
|
215 |
|
|
strcat(strRsDecodeShiftOmega, "/rtl/RsDecodeShiftOmega.v");
|
216 |
|
|
|
217 |
|
|
strRsDecodePolymul = (char *)calloc(lengthPath + 23, sizeof(char));
|
218 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
219 |
|
|
strRsDecodePolymul[ii] = rootFolderPath[ii];
|
220 |
|
|
}
|
221 |
|
|
strcat(strRsDecodePolymul, "/rtl/RsDecodePolymul.v");
|
222 |
|
|
|
223 |
|
|
strRsDecodeMult = (char *)calloc(lengthPath + 20, sizeof(char));
|
224 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
225 |
|
|
strRsDecodeMult[ii] = rootFolderPath[ii];
|
226 |
|
|
}
|
227 |
|
|
strcat(strRsDecodeMult, "/rtl/RsDecodeMult.v");
|
228 |
|
|
|
229 |
|
|
strRsDecodeInv = (char *)calloc(lengthPath + 19, sizeof(char));
|
230 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
231 |
|
|
strRsDecodeInv[ii] = rootFolderPath[ii];
|
232 |
|
|
}
|
233 |
|
|
strcat(strRsDecodeInv, "/rtl/RsDecodeInv.v");
|
234 |
|
|
|
235 |
|
|
strRsDecodeEuclide = (char *)calloc(lengthPath + 23, sizeof(char));
|
236 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
237 |
|
|
strRsDecodeEuclide[ii] = rootFolderPath[ii];
|
238 |
|
|
}
|
239 |
|
|
strcat(strRsDecodeEuclide, "/rtl/RsDecodeEuclide.v");
|
240 |
|
|
|
241 |
|
|
strRsDecodeErasure = (char *)calloc(lengthPath + 23, sizeof(char));
|
242 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
243 |
|
|
strRsDecodeErasure[ii] = rootFolderPath[ii];
|
244 |
|
|
}
|
245 |
|
|
strcat(strRsDecodeErasure, "/rtl/RsDecodeErasure.v");
|
246 |
|
|
|
247 |
|
|
strRsDecodeDpRam = (char *)calloc(lengthPath + 21, sizeof(char));
|
248 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
249 |
|
|
strRsDecodeDpRam[ii] = rootFolderPath[ii];
|
250 |
|
|
}
|
251 |
|
|
strcat(strRsDecodeDpRam, "/rtl/RsDecodeDpRam.v");
|
252 |
|
|
|
253 |
|
|
strRsDecodeDelay = (char *)calloc(lengthPath + 21, sizeof(char));
|
254 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
255 |
|
|
strRsDecodeDelay[ii] = rootFolderPath[ii];
|
256 |
|
|
}
|
257 |
|
|
strcat(strRsDecodeDelay, "/rtl/RsDecodeDelay.v");
|
258 |
|
|
|
259 |
|
|
strRsDecodeDegree = (char *)calloc(lengthPath + 22, sizeof(char));
|
260 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
261 |
|
|
strRsDecodeDegree[ii] = rootFolderPath[ii];
|
262 |
|
|
}
|
263 |
|
|
strcat(strRsDecodeDegree, "/rtl/RsDecodeDegree.v");
|
264 |
|
|
|
265 |
|
|
strRsDecodeChien = (char *)calloc(lengthPath + 21, sizeof(char));
|
266 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
267 |
|
|
strRsDecodeChien[ii] = rootFolderPath[ii];
|
268 |
|
|
}
|
269 |
|
|
strcat(strRsDecodeChien, "/rtl/RsDecodeChien.v");
|
270 |
|
|
|
271 |
|
|
strrtl = (char *)calloc(lengthPath + 5, sizeof(char));
|
272 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
273 |
|
|
strrtl[ii] = rootFolderPath[ii];
|
274 |
|
|
}
|
275 |
|
|
strcat(strrtl, "/rtl");
|
276 |
|
|
|
277 |
|
|
strsim = (char *)calloc(lengthPath + 5, sizeof(char));
|
278 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
279 |
|
|
strsim[ii] = rootFolderPath[ii];
|
280 |
|
|
}
|
281 |
|
|
strcat(strsim, "/sim");
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
//---------------------------------------------------------------
|
285 |
|
|
// syndrome Polynom calculation
|
286 |
|
|
//---------------------------------------------------------------
|
287 |
|
|
syndromeLength = TotalSize - DataSize;
|
288 |
|
|
syndromeMod2 = syndromeLength %2;
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
//---------------------------------------------------------------
|
292 |
|
|
// symbolMax calculation
|
293 |
|
|
//---------------------------------------------------------------
|
294 |
|
|
symbolMax = 1;
|
295 |
|
|
for (ii=0;ii<bitSymbol;ii++){
|
296 |
|
|
symbolMax= 2* symbolMax;
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
//---------------------------------------------------------------
|
301 |
|
|
//- c++ variables
|
302 |
|
|
//---------------------------------------------------------------
|
303 |
|
|
int mmTabSize = (bitSymbol*2) -1;
|
304 |
|
|
int *PrefTab;
|
305 |
|
|
int *MrefTab;
|
306 |
|
|
int *x1Tab;
|
307 |
|
|
int *x2Tab;
|
308 |
|
|
int *ppTab;
|
309 |
|
|
int *aTab;
|
310 |
|
|
int *checkTab;
|
311 |
|
|
int *powerTab;
|
312 |
|
|
int *GenPoly;
|
313 |
|
|
int *convPoly;
|
314 |
|
|
int *xPoly;
|
315 |
|
|
int *coeffPoly;
|
316 |
|
|
int *aPoly;
|
317 |
|
|
int *coeffTab;
|
318 |
|
|
|
319 |
|
|
PrefTab = new int[mmTabSize*bitSymbol];
|
320 |
|
|
MrefTab = new int[mmTabSize*bitSymbol];
|
321 |
|
|
x1Tab = new int[bitSymbol];
|
322 |
|
|
x2Tab = new int[bitSymbol];
|
323 |
|
|
ppTab = new int[bitSymbol];
|
324 |
|
|
checkTab = new int[symbolMax-1];
|
325 |
|
|
aTab = new int[syndromeLength+1];
|
326 |
|
|
powerTab = new int[bitSymbol];
|
327 |
|
|
GenPoly = new int[syndromeLength+1];
|
328 |
|
|
convPoly = new int[syndromeLength+1];
|
329 |
|
|
xPoly = new int[syndromeLength+1];
|
330 |
|
|
coeffPoly = new int[syndromeLength+1];
|
331 |
|
|
aPoly = new int[syndromeLength+1];
|
332 |
|
|
coeffTab = new int[symbolMax];
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
//------------------------------------------------------------------------
|
336 |
|
|
// MrefTab Construction
|
337 |
|
|
//------------------------------------------------------------------------
|
338 |
|
|
RsMrefTab(MrefTab, bitSymbol);
|
339 |
|
|
|
340 |
|
|
|
341 |
|
|
//------------------------------------------------------------------------
|
342 |
|
|
// PrefTab Construction
|
343 |
|
|
//------------------------------------------------------------------------
|
344 |
|
|
RsPrefTab(PrefTab, PrimPoly, bitSymbol);
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
//-----------------------------------------------------------------------
|
348 |
|
|
// initialize x1Tab
|
349 |
|
|
//------------------------------------------------------------------------
|
350 |
|
|
x1Tab[0] = 1;
|
351 |
|
|
for (ii=1;ii<bitSymbol;ii++){
|
352 |
|
|
x1Tab[ii] = 0;
|
353 |
|
|
}
|
354 |
|
|
|
355 |
|
|
|
356 |
|
|
//-----------------------------------------------------------------------
|
357 |
|
|
// initialize x2Tab
|
358 |
|
|
//------------------------------------------------------------------------
|
359 |
|
|
x2Tab[0] = 0;
|
360 |
|
|
x2Tab[1] = 1;
|
361 |
|
|
for (ii=2;ii<bitSymbol;ii++){
|
362 |
|
|
x2Tab[ii] = 0;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
//-----------------------------------------------------------------------
|
367 |
|
|
// initialize powerTab
|
368 |
|
|
//------------------------------------------------------------------------
|
369 |
|
|
powerTab[0] = 1;
|
370 |
|
|
for (ii=1; ii<bitSymbol;ii++){
|
371 |
|
|
powerTab[ii] = 2*powerTab[ii-1];
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
//-----------------------------------------------------------------------
|
376 |
|
|
//------------------------------------------------------------------------
|
377 |
|
|
for(ii=0; ii<symbolMax-1; ii++){
|
378 |
|
|
|
379 |
|
|
//-----------------------------------------------------------------------
|
380 |
|
|
// ppTab = x1Tab * x2Tab
|
381 |
|
|
//------------------------------------------------------------------------
|
382 |
|
|
RsGfMultiplier(ppTab, x1Tab, x2Tab, PrimPoly, bitSymbol);
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
//-----------------------------------------------------------------------
|
386 |
|
|
// Binary To Decimal DecNumber [dec] = ppTab [bin]
|
387 |
|
|
//------------------------------------------------------------------------
|
388 |
|
|
DecNumber = 0;
|
389 |
|
|
for (jj=0; jj<bitSymbol;jj++){
|
390 |
|
|
DecNumber = DecNumber + ppTab[jj] * powerTab[jj];
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
checkTab[ii] = DecNumber;
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
//-----------------------------------------------------------------------
|
397 |
|
|
// Reassign x1Tab
|
398 |
|
|
//------------------------------------------------------------------------
|
399 |
|
|
for (jj=0; jj<bitSymbol;jj++){
|
400 |
|
|
x1Tab[jj] = ppTab [jj];
|
401 |
|
|
}
|
402 |
|
|
}
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
aTab[0] = 1;
|
406 |
|
|
|
407 |
|
|
//-----------------------------------------------------------------------
|
408 |
|
|
// initialize x1Tab
|
409 |
|
|
//------------------------------------------------------------------------
|
410 |
|
|
x1Tab[0] = 1;
|
411 |
|
|
for (ii=1;ii<bitSymbol;ii++){
|
412 |
|
|
x1Tab[ii] = 0;
|
413 |
|
|
}
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
//-----------------------------------------------------------------------
|
417 |
|
|
// initialize x2Tab
|
418 |
|
|
//------------------------------------------------------------------------
|
419 |
|
|
x2Tab[0] = 0;
|
420 |
|
|
x2Tab[1] = 1;
|
421 |
|
|
for (ii=2;ii<bitSymbol;ii++){
|
422 |
|
|
x2Tab[ii] = 0;
|
423 |
|
|
}
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
for(ii=1; ii<(syndromeLength+1); ii++){
|
427 |
|
|
|
428 |
|
|
//-----------------------------------------------------------------------
|
429 |
|
|
// ppTab = x1Tab * x2Tab
|
430 |
|
|
//------------------------------------------------------------------------
|
431 |
|
|
RsGfMultiplier(ppTab, x1Tab, x2Tab, PrimPoly, bitSymbol);
|
432 |
|
|
|
433 |
|
|
//-----------------------------------------------------------------------
|
434 |
|
|
// Binary To Decimal DecNumber [dec] = ppTab [bin]
|
435 |
|
|
//------------------------------------------------------------------------
|
436 |
|
|
DecNumber = 0;
|
437 |
|
|
for (jj=0; jj<bitSymbol;jj++){
|
438 |
|
|
DecNumber = DecNumber + ppTab[jj] * powerTab[jj];
|
439 |
|
|
}
|
440 |
|
|
aTab[ii] = DecNumber;
|
441 |
|
|
|
442 |
|
|
//-----------------------------------------------------------------------
|
443 |
|
|
// Reassign x1Tab
|
444 |
|
|
//------------------------------------------------------------------------
|
445 |
|
|
for (jj=0; jj<bitSymbol;jj++){
|
446 |
|
|
x1Tab[jj] = ppTab [jj];
|
447 |
|
|
}
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
//-----------------------------------------------------------------------
|
452 |
|
|
// initialize GenPoly, aPoly, convPoly, xPoly, coeffPoly
|
453 |
|
|
//------------------------------------------------------------------------
|
454 |
|
|
for(ii=0; ii<syndromeLength+1; ii++){
|
455 |
|
|
GenPoly [ii] = 0;
|
456 |
|
|
aPoly [ii] = 0;
|
457 |
|
|
convPoly [ii] = 0;
|
458 |
|
|
xPoly [ii] = 0;
|
459 |
|
|
coeffPoly [ii] = 0;
|
460 |
|
|
}
|
461 |
|
|
GenPoly [0] = 1;
|
462 |
|
|
GenPoly [1] = 1;
|
463 |
|
|
aPoly [1] = 1;
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
for(ii=0; ii<(syndromeLength-1); ii++){
|
468 |
|
|
aPoly [0] = aTab[ii+1];
|
469 |
|
|
|
470 |
|
|
//-----------------------------------------------------------------------
|
471 |
|
|
// assign xPoly
|
472 |
|
|
//-----------------------------------------------------------------------
|
473 |
|
|
for (jj=1; jj< (syndromeLength+1); jj++){
|
474 |
|
|
xPoly [jj] = GenPoly[jj-1];
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
for (jj=0; jj< (syndromeLength+1); jj++){
|
478 |
|
|
|
479 |
|
|
//-----------------------------------------------------------------------
|
480 |
|
|
// Decimal To Binary x1Tab [bin] = GenPoly[jj][dec]
|
481 |
|
|
//-----------------------------------------------------------------------
|
482 |
|
|
tempix = GenPoly[jj];
|
483 |
|
|
|
484 |
|
|
for (zz =(bitSymbol-1); zz>=0;zz--) {
|
485 |
|
|
if (tempix >= powerTab[zz]) {
|
486 |
|
|
tempix = tempix - powerTab[zz];
|
487 |
|
|
x1Tab [zz] = 1;
|
488 |
|
|
}else{
|
489 |
|
|
x1Tab [zz] = 0;
|
490 |
|
|
}
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
//-----------------------------------------------------------------------
|
495 |
|
|
// Decimal To Binary x2Tab [bin] = aPoly[0][dec]
|
496 |
|
|
//-----------------------------------------------------------------------
|
497 |
|
|
tempix = aPoly [0];
|
498 |
|
|
for (zz =(bitSymbol-1); zz>=0;zz--) {
|
499 |
|
|
if (tempix >= powerTab[zz]) {
|
500 |
|
|
tempix = tempix -powerTab[zz];
|
501 |
|
|
x2Tab [zz] = 1;
|
502 |
|
|
}else{
|
503 |
|
|
x2Tab [zz] = 0;
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
//-----------------------------------------------------------------------
|
508 |
|
|
// ppTab = x1Tab * x2Tab
|
509 |
|
|
//-----------------------------------------------------------------------
|
510 |
|
|
RsGfMultiplier(ppTab, x1Tab, x2Tab, PrimPoly, bitSymbol);
|
511 |
|
|
|
512 |
|
|
|
513 |
|
|
//-----------------------------------------------------------------------
|
514 |
|
|
// Binary To Decimal coeffPoly[jj] [dec] = ppTab[zz] [bin]
|
515 |
|
|
//-----------------------------------------------------------------------
|
516 |
|
|
coeffPoly[jj] = 0;
|
517 |
|
|
for (zz=0;zz<bitSymbol;zz++){
|
518 |
|
|
coeffPoly[jj] = coeffPoly[jj] + ppTab[zz] *powerTab[zz];
|
519 |
|
|
}
|
520 |
|
|
|
521 |
|
|
|
522 |
|
|
//-----------------------------------------------------------------------
|
523 |
|
|
// compute GenPoly (convolution function)
|
524 |
|
|
//-----------------------------------------------------------------------
|
525 |
|
|
GenPoly [jj] = coeffPoly[jj] ^ xPoly[jj];
|
526 |
|
|
}
|
527 |
|
|
}
|
528 |
|
|
|
529 |
|
|
|
530 |
|
|
//---------------------------------------------------------------
|
531 |
|
|
// coeffTab calculation
|
532 |
|
|
//---------------------------------------------------------------
|
533 |
|
|
for(ii=0; ii<syndromeLength; ii++){
|
534 |
|
|
index = 0;
|
535 |
|
|
for (jj= 0; jj<symbolMax-2; jj++){
|
536 |
|
|
if (checkTab[jj] == GenPoly [ii]) {
|
537 |
|
|
index = jj+1;
|
538 |
|
|
}
|
539 |
|
|
}
|
540 |
|
|
coeffTab[ii] = index;
|
541 |
|
|
}
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
|
545 |
|
|
|
546 |
|
|
if (ipCustomerKey == cppCoreInternalKey) {
|
547 |
|
|
|
548 |
|
|
|
549 |
|
|
//---------------------------------------------------------------
|
550 |
|
|
// remove Files if they already exists
|
551 |
|
|
//---------------------------------------------------------------
|
552 |
|
|
if (pathFlag == 0) { // no path folder specified
|
553 |
|
|
DeleteFile ("./sim/simReedSolomon.v");
|
554 |
|
|
DeleteFile ("./sim/RsEncIn.hex");
|
555 |
|
|
DeleteFile ("./sim/RsEncOut.hex");
|
556 |
|
|
DeleteFile ("./sim/RsDecIn.hex");
|
557 |
|
|
DeleteFile ("./sim/RsDecOut.hex");
|
558 |
|
|
DeleteFile ("./rtl/RsEncodeTop.v");
|
559 |
|
|
DeleteFile ("./rtl/RsDecodeTop.v");
|
560 |
|
|
DeleteFile ("./rtl/RsDecodeSyndrome.v");
|
561 |
|
|
DeleteFile ("./rtl/RsDecodeShiftOmega.v");
|
562 |
|
|
DeleteFile ("./rtl/RsDecodePolymul.v");
|
563 |
|
|
DeleteFile ("./rtl/RsDecodeMult.v");
|
564 |
|
|
DeleteFile ("./rtl/RsDecodeInv.v");
|
565 |
|
|
DeleteFile ("./rtl/RsDecodeEuclide.v");
|
566 |
|
|
DeleteFile ("./rtl/RsDecodeErasure.v");
|
567 |
|
|
DeleteFile ("./rtl/RsDecodeDpRam.v");
|
568 |
|
|
DeleteFile ("./rtl/RsDecodeDelay.v");
|
569 |
|
|
DeleteFile ("./rtl/RsDecodeDegree.v");
|
570 |
|
|
DeleteFile ("./rtl/RsDecodeChien.v");
|
571 |
|
|
}else{ // a path folder has been specified
|
572 |
|
|
DeleteFile (strsimReedSolomon);
|
573 |
|
|
DeleteFile (strRsEncIn);
|
574 |
|
|
DeleteFile (strRsEncOut);
|
575 |
|
|
DeleteFile (strRsDecIn);
|
576 |
|
|
DeleteFile (strRsDecOut);
|
577 |
|
|
DeleteFile (strRsEncodeTop);
|
578 |
|
|
DeleteFile (strRsDecodeTop);
|
579 |
|
|
DeleteFile (strRsDecodeSyndrome);
|
580 |
|
|
DeleteFile (strRsDecodeShiftOmega);
|
581 |
|
|
DeleteFile (strRsDecodePolymul);
|
582 |
|
|
DeleteFile (strRsDecodeMult);
|
583 |
|
|
DeleteFile (strRsDecodeInv);
|
584 |
|
|
DeleteFile (strRsDecodeEuclide);
|
585 |
|
|
DeleteFile (strRsDecodeErasure);
|
586 |
|
|
DeleteFile (strRsDecodeDpRam);
|
587 |
|
|
DeleteFile (strRsDecodeDelay);
|
588 |
|
|
DeleteFile (strRsDecodeDegree);
|
589 |
|
|
DeleteFile (strRsDecodeChien);
|
590 |
|
|
}
|
591 |
|
|
|
592 |
|
|
|
593 |
|
|
//---------------------------------------------------------------
|
594 |
|
|
// create source and sim folders if they do not already exists
|
595 |
|
|
//---------------------------------------------------------------
|
596 |
|
|
if (pathFlag == 0) { // no path folder specified
|
597 |
|
|
CreateDirectory ("rtl", NULL);
|
598 |
|
|
CreateDirectory ("sim", NULL);
|
599 |
|
|
}else{ // a path folder has been specified
|
600 |
|
|
CreateDirectory (strrtl, NULL);
|
601 |
|
|
CreateDirectory (strsim, NULL);
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
//---------------------------------------------------------------
|
606 |
|
|
// RS DECODE
|
607 |
|
|
//---------------------------------------------------------------
|
608 |
|
|
if ((encDecMode == 2) || (encDecMode == 3)){
|
609 |
|
|
RsDecode(DataSize, TotalSize, PrimPoly, bitSymbol, errorStats, passFailFlag, delayDataIn, ErasureOption, BlockAmount, ErrorRate, PowerErrorRate, ErasureRate, PowerErasureRate, MrefTab, PrefTab, coeffTab, encDecMode, encBlockAmount, pathFlag, lengthPath, rootFolderPath);
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
//---------------------------------------------------------------
|
613 |
|
|
// RS ENCODE
|
614 |
|
|
//---------------------------------------------------------------
|
615 |
|
|
if ((encDecMode == 1) || (encDecMode == 3)){
|
616 |
|
|
RsEncode(DataSize, TotalSize, PrimPoly, bitSymbol, ErasureOption, encBlockAmount, ErrorRate, MrefTab, PrefTab, coeffTab, errorStats, passFailFlag, delayDataIn, encDecMode, PowerErrorRate, ErasureRate, PowerErasureRate, BlockAmount, pathFlag, lengthPath, rootFolderPath);
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
//---------------------------------------------------------------
|
620 |
|
|
// RS SimBench
|
621 |
|
|
//---------------------------------------------------------------
|
622 |
|
|
if ((encDecMode == 1) ||(encDecMode == 2) || (encDecMode == 3)){
|
623 |
|
|
RsSimBench(DataSize, TotalSize, PrimPoly, bitSymbol, errorStats, passFailFlag, delayDataIn, encDecMode, ErasureOption, BlockAmount, encBlockAmount, ErrorRate,PowerErrorRate, ErasureRate, PowerErasureRate, pathFlag, lengthPath, rootFolderPath);
|
624 |
|
|
}
|
625 |
|
|
|
626 |
|
|
|
627 |
|
|
|
628 |
|
|
|
629 |
|
|
//---------------------------------------------------------------
|
630 |
|
|
// create IP summary File
|
631 |
|
|
//---------------------------------------------------------------
|
632 |
|
|
// OutFileIPSpecs = fopen("./sim/IPSpecs.txt","w");
|
633 |
|
|
|
634 |
|
|
strIPSpecs = (char *)calloc(lengthPath + 17, sizeof(char));
|
635 |
|
|
if (pathFlag == 0) {
|
636 |
|
|
strIPSpecs[0] = '.';
|
637 |
|
|
}else{
|
638 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
639 |
|
|
strIPSpecs[ii] = rootFolderPath[ii];
|
640 |
|
|
}
|
641 |
|
|
}
|
642 |
|
|
strcat(strIPSpecs, "/sim/IPSpecs.txt");
|
643 |
|
|
|
644 |
|
|
OutFileIPSpecs = fopen(strIPSpecs,"w");
|
645 |
|
|
|
646 |
|
|
|
647 |
|
|
fprintf(OutFileIPSpecs, "//=================================================================\n");
|
648 |
|
|
fprintf(OutFileIPSpecs, "// RS-IP Global Settings \n");
|
649 |
|
|
fprintf(OutFileIPSpecs, "//=================================================================\n");
|
650 |
|
|
|
651 |
|
|
if (pathFlag == 1) {
|
652 |
|
|
fprintf(OutFileIPSpecs, "- Path Folder : ");
|
653 |
|
|
for(ii=0; ii<lengthPath; ii++){
|
654 |
|
|
fprintf(OutFileIPSpecs, "%c", rootFolderPath[ii]);
|
655 |
|
|
}
|
656 |
|
|
fprintf(OutFileIPSpecs, "\n");
|
657 |
|
|
}else{
|
658 |
|
|
fprintf(OutFileIPSpecs, "- Path Folder : No Path Specified\n");
|
659 |
|
|
}
|
660 |
|
|
|
661 |
|
|
fprintf(OutFileIPSpecs, "- Symbol Bit Width: %d bits\n", bitSymbol);
|
662 |
|
|
if (encDecMode == 1) { fprintf(OutFileIPSpecs, "- IP Mode: Encoder Only\n");}
|
663 |
|
|
if (encDecMode == 2) { fprintf(OutFileIPSpecs, "- IP Mode: Decoder Only\n");}
|
664 |
|
|
if (encDecMode == 3) { fprintf(OutFileIPSpecs, "- IP Mode: Encoder + Decoder\n");}
|
665 |
|
|
fprintf(OutFileIPSpecs, "- Data Symbol Amount: %d symbols\n", DataSize);
|
666 |
|
|
fprintf(OutFileIPSpecs, "- Data+Redundancy Symbol Amount: %d symbols\n", TotalSize);
|
667 |
|
|
fprintf(OutFileIPSpecs, "- Primitive Polynomial: %d\n", PrimPoly);
|
668 |
|
|
|
669 |
|
|
if ((encDecMode == 1) || (encDecMode == 3)) {
|
670 |
|
|
fprintf(OutFileIPSpecs, "\n\n//=================================================================\n");
|
671 |
|
|
fprintf(OutFileIPSpecs, "// RS-IP Encoder Settings \n");
|
672 |
|
|
fprintf(OutFileIPSpecs, "//=================================================================\n");
|
673 |
|
|
fprintf(OutFileIPSpecs, "- RTL sim block amount: %d Blocks\n", encBlockAmount);
|
674 |
|
|
}
|
675 |
|
|
if ((encDecMode == 2) || (encDecMode == 3)) {
|
676 |
|
|
fprintf(OutFileIPSpecs, "\n\n//=================================================================\n");
|
677 |
|
|
fprintf(OutFileIPSpecs, "// RS-IP Decoder Settings \n");
|
678 |
|
|
fprintf(OutFileIPSpecs, "//=================================================================\n");
|
679 |
|
|
if (ErasureOption == 0) { fprintf(OutFileIPSpecs, "- Erasure Decoding: No\n" );}
|
680 |
|
|
if (ErasureOption == 1) { fprintf(OutFileIPSpecs, "- Erasure Decoding: Yes\n" );}
|
681 |
|
|
if (errorStats == 0) { fprintf(OutFileIPSpecs, "- Decoder Statisctics Pin: No\n" );}
|
682 |
|
|
if (errorStats == 1) { fprintf(OutFileIPSpecs, "- Decoder Statisctics Pin: Yes\n" );}
|
683 |
|
|
if (passFailFlag == 0) { fprintf(OutFileIPSpecs, "- Decoder Result Pin: No\n" );}
|
684 |
|
|
if (passFailFlag == 1) { fprintf(OutFileIPSpecs, "- Decoder Result Pin: Yes\n" );}
|
685 |
|
|
if (delayDataIn == 0) { fprintf(OutFileIPSpecs, "- Delayed Data Pin: No\n" );}
|
686 |
|
|
if (delayDataIn == 1) { fprintf(OutFileIPSpecs, "- Delayed Data Pin: Yes\n" );}
|
687 |
|
|
fprintf(OutFileIPSpecs, "- RTL sim block amount: %d Blocks\n", BlockAmount);
|
688 |
|
|
fprintf(OutFileIPSpecs, "- RTL sim Input Error Rate: %d * 10^-%d Percent\n", ErrorRate, PowerErrorRate);
|
689 |
|
|
if (ErasureOption == 1)
|
690 |
|
|
{
|
691 |
|
|
fprintf(OutFileIPSpecs, "- RTL sim Input Erasure Rate: %d * 10^-%d Percent\n", ErasureRate, PowerErasureRate);
|
692 |
|
|
}
|
693 |
|
|
}
|
694 |
|
|
|
695 |
|
|
fclose(OutFileIPSpecs);
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
}
|
700 |
|
|
//---------------------------------------------------------------
|
701 |
|
|
// clean data
|
702 |
|
|
//---------------------------------------------------------------
|
703 |
|
|
delete[] PrefTab;
|
704 |
|
|
delete[] MrefTab;
|
705 |
|
|
delete[] x1Tab;
|
706 |
|
|
delete[] x2Tab;
|
707 |
|
|
delete[] ppTab;
|
708 |
|
|
delete[] checkTab;
|
709 |
|
|
delete[] aTab;
|
710 |
|
|
delete[] powerTab;
|
711 |
|
|
delete[] GenPoly;
|
712 |
|
|
delete[] convPoly;
|
713 |
|
|
delete[] xPoly;
|
714 |
|
|
delete[] coeffPoly;
|
715 |
|
|
delete[] aPoly;
|
716 |
|
|
delete[] coeffTab;
|
717 |
|
|
|
718 |
|
|
|
719 |
|
|
//---------------------------------------------------------------
|
720 |
|
|
// clean strings
|
721 |
|
|
//---------------------------------------------------------------
|
722 |
|
|
free(strrtl);
|
723 |
|
|
free(strsim);
|
724 |
|
|
free(strsimReedSolomon);
|
725 |
|
|
free(strRsEncIn);
|
726 |
|
|
free(strRsEncOut);
|
727 |
|
|
free(strRsDecIn);
|
728 |
|
|
free(strRsDecOut);
|
729 |
|
|
free(strRsEncodeTop);
|
730 |
|
|
free(strRsDecodeTop);
|
731 |
|
|
free(strRsDecodeSyndrome);
|
732 |
|
|
free(strRsDecodeShiftOmega);
|
733 |
|
|
free(strRsDecodePolymul);
|
734 |
|
|
free(strRsDecodeMult);
|
735 |
|
|
free(strRsDecodeInv);
|
736 |
|
|
free(strRsDecodeEuclide);
|
737 |
|
|
free(strRsDecodeErasure);
|
738 |
|
|
free(strRsDecodeDpRam);
|
739 |
|
|
free(strRsDecodeDelay);
|
740 |
|
|
free(strRsDecodeDegree);
|
741 |
|
|
free(strRsDecodeChien);
|
742 |
|
|
free(strIPSpecs);
|
743 |
|
|
|
744 |
|
|
|
745 |
|
|
}
|