39crc20(uint64_t* data, uint64_t length,
bool crc_new)
53 crc = (crc >> 1) ^ ((1 << (
CRC_WIDTH - 1)) | (polynomial >> 1));
60 for (i = 0; i < length; i++) {
61 for (k = 1; k <= 32; k++) {
63 crc = ((crc << 1) | ((data[i] >> (32 - k)) & 1)) ^ polynomial;
65 crc = ((crc << 1) | ((data[i] >> (32 - k)) & 1));
74 crc = (crc << 1) ^ polynomial;
87 uint32_t req_chunksize,
100 for (i = 0; i < emusize; ++i) {
106 uint32_t max_chunkcnt = (emusize - 2) / (1 + req_chunksize / 4 + 1 + idle_chars);
116 uint32_t next_index, chunkcntr = 0, chunksz, chunk_datasz;
117 while (index < emusize && chunkcntr < max_chunkcnt) {
118 if (random_sz && req_chunksize > 8) {
122 uint32_t sz = (req_chunksize + 1) / 2;
123 double r =
static_cast<double>(rand()) / RAND_MAX;
124 double d = 0.5 *
static_cast<double>(1 - (req_chunksize & 1));
125 chunksz = ((sz +
static_cast<uint32_t
>(
static_cast<double>(sz) * r + d) + 3) / 4) * 4;
128 chunksz = req_chunksize;
133 next_index = index + (1 + chunksz / 4 + 1);
134 if (next_index >= emusize) {
136 for (; index < emusize; ++index) {
147 if (omit_one_soc && chunkcntr == 2) {
154 emudata[index++] = ((chunkcntr & 0xFF) |
155 (chunk_datasz & 0xF00) | ((chunk_datasz & 0x0FF) << 16) | ((chunkcntr & 0xFF) << 24));
158 (0xAA | (chunk_datasz & 0xF00) | ((chunk_datasz & 0x0FF) << 16) | ((chunkcntr & 0xFF) << 24));
161 emudata[index++] = 0x10AABB00;
164 if (pattern_id == 1) {
165 for (i = 0; i < chunk_datasz / 4; ++i) {
166 emudata[index++] = 0xAA55AA55;
168 }
else if (pattern_id == 2) {
169 for (i = 0; i < chunk_datasz / 4; ++i) {
170 emudata[index++] = 0xFFFFFFFF;
172 }
else if (pattern_id == 3) {
173 for (i = 0; i < chunk_datasz / 4; ++i) {
174 emudata[index++] = 0x00000000;
177 unsigned int cntr = 0;
178 for (i = 0; i < chunk_datasz / 4; ++i, cntr += 4) {
180 ((((cntr + 3) & 0xFF) << 24) | (((cntr + 2) & 0xFF) << 16) | (((cntr + 1) & 0xFF) << 8) |
181 (((cntr + 0) & 0xFF) << 0));
186 uint64_t crc =
crc20(&emudata[index - chunksz / 4], chunksz / 4, crc_new);
188 if (add_crc_err && chunkcntr == 3) {
194 if (omit_one_eoc && chunkcntr == 2) {
198 if (add_busy && chunkcntr == 0) {
203 for (i = 0; i < idle_chars; ++i) {
207 if (add_busy && chunkcntr == 0) {
215 for (; index < emusize; ++index) {
220 if (chunkcntr < max_chunkcnt) {
233 const std::vector<std::string> cmdArgs = { argv,
237 uint32_t emusize = 8192;
238 uint32_t req_chunksize = 464;
239 uint32_t pattern_id = 0;
240 uint32_t idle_chars = 1;
241 bool random_sz =
false;
243 bool use_streamid =
false;
244 bool add_busy =
false;
245 bool omit_one_soc =
false;
246 bool omit_one_eoc =
false;
247 bool add_crc_err =
false;
248 std::string
filename =
"emuconfigreg";
251 for (
unsigned j = 0; j < cmdArgs.size(); j++) {
252 std::string arg = cmdArgs[j];
253 if (arg ==
"-h" || arg ==
"--help") {
254 std::ostringstream oss;
256 <<
"\nThis app is used to create basic emulator configurations for the FELIX to use with flx-config. Usage: \n"
257 <<
" -h/--help : display help messege \n"
258 <<
" --filename : output configuration filename \n"
260 <<
" --chunkSize : chunk sie of each block of data \n"
261 <<
" --idles : number of idle charachters between chunks \n"
262 <<
" --pattern : type of data to write \n"
263 <<
" 0 is incrimental \n"
264 <<
" 1 sets all to 0xAA55AA55 \n"
265 <<
" 2 sets all to 0xFFFFFFFF \n"
266 <<
" 3 sets all to 0x00000000";
269 }
else if (arg ==
"--filename") {
271 if (j >= cmdArgs.size() - 1)
273 TLOG() <<
"No file name was specified";
285 }
else if (arg ==
"--chunkSize") {
286 if (j >= cmdArgs.size() - 1) {
287 TLOG() <<
"No value was specified";
290 req_chunksize = std::stoi(cmdArgs[j + 1]);
292 }
else if (arg ==
"--idles") {
293 if (j >= cmdArgs.size() - 1) {
294 TLOG() <<
"No value was specified";
297 idle_chars = std::stoi(cmdArgs[j + 1]);
299 }
else if (arg ==
"--pattern") {
300 if (j >= cmdArgs.size() - 1) {
301 TLOG() <<
"No value was specified";
304 pattern_id = std::stoi(cmdArgs[j + 1]);
308 TLOG() <<
"chunk size : " << req_chunksize;
309 TLOG() <<
"idle characters : " << idle_chars;
310 TLOG() <<
"pattern type : " << pattern_id;
312 filename +=
"_" + std::to_string(req_chunksize) +
"_" + std::to_string(idle_chars) +
"_" + std::to_string(pattern_id);
316 std::ofstream output;
332 for (
unsigned i = 0; i < emusize; i++) {
333 output <<
"FE_EMU_CONFIG_WRADDR=0x" << std::hex << i << std::endl;
334 output <<
"FE_EMU_CONFIG_WRDATA=0x" << std::hex << emudata[i] << std::endl;
335 output <<
"FE_EMU_CONFIG_WE=1" << std::endl;
336 output <<
"FE_EMU_CONFIG_WE=0" << std::endl;
341 TLOG() <<
"Config file written.";
bool generateFm(uint64_t *emudata, uint64_t emusize, uint32_t req_chunksize, uint32_t pattern_id, uint32_t idle_chars, bool random_sz, bool crc_new, bool use_streamid, bool add_busy, bool omit_one_soc, bool omit_one_eoc, bool add_crc_err)