cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cF IBMZRL essentials
cF » cFp » cFp_Zoo

This is a set of projects developed by IBM Research Zurich Lab. The group contains educational projects and platform-stressing ones. More...

Collaboration diagram for cF IBMZRL essentials:

Modules

 Uppercase
 This is the Uppercase educational example. The FPGA accepts a string and returns the upper-case converted one.
 
 Memtest
 This is the Memtest platform stressing project. The FPGA tests its DRAM memory.
 

Classes

struct  MemoryTestResult
 

Macros

#define THIS_NAME   "TB"
 
#define TRACE_OFF   0x0000
 
#define TRACE_URIF   1 << 1
 
#define TRACE_UAF   1 << 2
 
#define TRACE_MMIO   1 << 3
 
#define TRACE_ALL   0xFFFF
 
#define DEBUG_LEVEL   (TRACE_ALL)
 
#define OK   true
 
#define KO   false
 
#define VALID   true
 
#define UNVALID   false
 
#define DEBUG_TRACE   true
 
#define ENABLED   (ap_uint<1>)1
 
#define DISABLED   (ap_uint<1>)0
 

Functions

bool setInputDataStream (stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string inpFileName, int simCnt)
 Initialize an input data stream from a file. More...
 
ap_uint< 64 > pack_ap_uint_64_ (ap_uint< 8 > *buffer)
 Pack an array of 8 x ap_uint<8> into a ap_uint<64> word. More...
 
bool dumpDataToFile (UdpWord *udpWord, std::ofstream &outFileStream)
 Dump a data word to a file. More...
 
bool getOutputDataStream (stream< UdpWord > &sDataStream, const std::string dataStreamName, const std::string outFileName, int simCnt)
 Fill an output file with data from an output stream. More...
 
bool dumpStringToFile (std::string s, const std::string outFileName, int simCnt)
 Initialize an input data stream from a file. More...
 
bool dumpStringToFileOnlyRawData (const std::string s, const std::string outFileName, int simCnt, size_t out_size)
 Fill an output file with data from an image. More...
 
bool dumpStringToFileWithLastSetEveryGnoPackets (std::string s, const std::string outFileName, int simCnt, int gno)
 Fill an output file with data from a string and set the tlast every gno packets. More...
 
bool dumpFileToString (const std::string inpFileName, std::string strOutput, int simCnt)
 Initialize an input data stream from a file. More...
 
template<unsigned int bytes_per_line = 8>
std::string dumpFileToStringRawDataString (const std::string inpFileName, int *rawdatalines, size_t outputSize)
 Initialize an input data stream from a file with only data. More...
 
unsigned char hexval (unsigned char c)
 convert a char to its hexadecimal representation. More...
 
void hex2ascii (const std::string &in, std::string &out)
 Convert a hexadecimal string to a ascii string. More...
 
void ascii2hex (const std::string &in, std::string &out)
 Convert a ascii string to a hexadecimal string. More...
 
void ascii2hexWithSize (const std::string &in, std::string &out, size_t bytesize)
 Convert a ascii string to a hexadecimal string. More...
 
bool isCornerPresent (std::string str, std::string corner)
 Check the presence of a given corner value at the begin and the end of a string. More...
 
template<typename T >
void string2hexnumerics (const std::string &in, char *out, size_t byteSize)
 Convert a hex string to a T type into a char buffer with the SAME dimensions. More...
 
std::string createMemTestCommands (unsigned long long int mem_address, int testingNumber, unsigned int burst_size)
 Create the commands for a memory test with start/max address to test-nop to execute-stop. More...
 
std::string createMemTestGoldenOutput (unsigned long long int mem_address, int testingNumber)
 Create the expected output results for the memory test (with FAULT INJECTION) More...
 
std::string createUppercaseGoldenOutput (std::string input_string)
 Create the expected output results for the uppercase. More...
 
void reverseStr (std::string &str)
 reverse a given string More...
 
template<unsigned int bytes_per_line = 8>
std::vector< MemoryTestResultparseMemoryTestOutput (const std::string longbuf, size_t charOutputSize, int rawdatalines)
 Parse the memory test output contained in astring with a given size. More...
 
void printStringHex (const std::string inStr, size_t strSize)
 print byte-per-byte a given string in hexadecimal format More...
 
void printCharBuffHex (const char *inStr, size_t strSize)
 print byte-per-byte a given char buff in hexadecimal format More...
 
void printBits (size_t const size, void const *const ptr)
 print the binary representation of a target pointer buffer of a given size. Assumes little endian. More...
 
bool setInputDataStream (stream< UdpWord > &sDataStream, const string dataStreamName, const string inpFileName, int simCnt)
 Initialize an input data stream from a file. More...
 
void unpack_ap_uint_64_ (ap_uint< 64 > value, ap_uint< 8 > *buffer)
 Unpack an ap_uint<64> word to an array of 8 x ap_uint<8>. More...
 
bool getOutputDataStream (stream< UdpWord > &sDataStream, const string dataStreamName, const string outFileName, int simCnt)
 Fill an output file with data from an output stream. More...
 
bool dumpStringToFile (const string s, const string outFileName, int simCnt)
 Fill an output file with data from an image. More...
 
bool dumpStringToFileOnlyRawData (const string s, const string outFileName, int simCnt, size_t out_size)
 Fill an output file with data from an image. More...
 
bool dumpStringToFileWithLastSetEveryGnoPackets (string s, const string outFileName, int simCnt, int gno)
 Fill an output file with data from a string and set the tlast every gno packets. More...
 
bool dumpFileToString (const string inpFileName, char *charOutput, int simCnt)
 Initialize an input data stream from a file. More...
 
template<unsigned int bytes_per_line = 8>
string dumpFileToStringRawDataString (const string inpFileName, int *rawdatalines, size_t outputSize)
 Initialize an input data stream from a file with only data. More...
 
void hex2ascii (const string &in, string &out)
 Convert a hexadecimal string to a ascii string FIXME: More...
 
void ascii2hex (const string &in, string &out)
 Convert a ascii string to a hexadecimal string FIXME: More...
 
void ascii2hexWithSize (const string &in, string &out, size_t bytesize)
 Convert a ascii string to a hexadecimal string FIXME: More...
 
bool isCornerPresent (string str, string corner)
 Check the presence of a given corner value at the begin and the end of a string. More...
 
template<typename T >
void string2hexnumerics (const string &in, char *out, size_t byteSize)
 Convert a hex string to a integer into a char buffer with the SAME dimensions FIXME: More...
 
void stringHex2Unsigned (const string &in, unsigned int *out, size_t byteSize)
 
void string2hexnumericsString (const string &in, string &out, size_t byteSize)
 Convert a hex string to a integer into a char buffer with the SAME dimensions FIXME: More...
 
template<unsigned int bytes_per_line = 8>
string createMemTestCommands (unsigned long long int mem_address, unsigned int testingNumber, unsigned int burst_size)
 Create the commands for a memory test with start/max address to test-nop to execute-stop. More...
 
template<unsigned int bytes_per_line = 8>
string createMemTestGoldenOutput (unsigned long long int mem_address, unsigned int testingNumber, bool with_bw_analysis)
 Create the expected output results for the memory test (with FAULT INJECTION) More...
 
void reverseStr (string &str)
 reverse a given string More...
 
template<unsigned int bytes_per_line = 8>
std::vector< MemoryTestResultparseMemoryTestOutput (const string longbuf, size_t charOutputSize, int rawdatalines)
 Parse the memory test output contained in astring with a given size. More...
 
void printStringHex (const string inStr, size_t strSize)
 print byte-per-byte a given string in hexadecimal format More...
 

Detailed Description

This is a set of projects developed by IBM Research Zurich Lab. The group contains educational projects and platform-stressing ones.

Macro Definition Documentation

◆ DEBUG_LEVEL

#define DEBUG_LEVEL   (TRACE_ALL)

Definition at line 71 of file common.hpp.

◆ DEBUG_TRACE

#define DEBUG_TRACE   true

Definition at line 81 of file common.hpp.

◆ DISABLED

#define DISABLED   (ap_uint<1>)0

Definition at line 84 of file common.hpp.

◆ ENABLED

#define ENABLED   (ap_uint<1>)1

Definition at line 83 of file common.hpp.

◆ KO

#define KO   false

Definition at line 78 of file common.hpp.

◆ OK

#define OK   true

Definition at line 77 of file common.hpp.

◆ THIS_NAME

#define THIS_NAME   "TB"

Definition at line 63 of file common.hpp.

◆ TRACE_ALL

#define TRACE_ALL   0xFFFF

Definition at line 69 of file common.hpp.

◆ TRACE_MMIO

#define TRACE_MMIO   1 << 3

Definition at line 68 of file common.hpp.

◆ TRACE_OFF

#define TRACE_OFF   0x0000

Definition at line 65 of file common.hpp.

◆ TRACE_UAF

#define TRACE_UAF   1 << 2

Definition at line 67 of file common.hpp.

◆ TRACE_URIF

#define TRACE_URIF   1 << 1

Definition at line 66 of file common.hpp.

◆ UNVALID

#define UNVALID   false

Definition at line 80 of file common.hpp.

◆ VALID

#define VALID   true

Definition at line 79 of file common.hpp.

Function Documentation

◆ ascii2hex() [1/2]

void ascii2hex ( const std::string &  in,
std::string &  out 
)

Convert a ascii string to a hexadecimal string.

Parameters
[in]inthe input ascii string
[out]outthe output hexadecimal string

◆ ascii2hex() [2/2]

void ascii2hex ( const string &  in,
string &  out 
)

Convert a ascii string to a hexadecimal string FIXME:

Parameters
[in]inthe input ascii string
[out]outthe output hexadecimal string

Definition at line 574 of file common.cpp.

575 {
576  std::stringstream sstream;
577  for ( string::const_iterator item = in.begin(); item != in.end(); item++){
578  sstream << std::hex << int(*item);
579  }
580  out=sstream.str();
581 }
out
Definition: test.py:12

◆ ascii2hexWithSize() [1/2]

void ascii2hexWithSize ( const std::string &  in,
std::string &  out,
size_t  bytesize 
)

Convert a ascii string to a hexadecimal string.

Parameters
[in]inthe input ascii string
[out]outthe output hexadecimal string
[in]bytesizethe input ascii string size

◆ ascii2hexWithSize() [2/2]

void ascii2hexWithSize ( const string &  in,
string &  out,
size_t  bytesize 
)

Convert a ascii string to a hexadecimal string FIXME:

Parameters
[in]inthe input ascii string
[out]outthe output hexadecimal string
[in]bytesizethe input ascii string size

Definition at line 590 of file common.cpp.

591 {
592  std::stringstream sstream;
593  for ( int i=0; i<bytesize; i++){
594  sstream << std::hex << int(in[i]);
595  }
596  out=sstream.str();
597 }

◆ createMemTestCommands() [1/2]

std::string createMemTestCommands ( unsigned long long int  mem_address,
int  testingNumber,
unsigned int  burst_size 
)

Create the commands for a memory test with start/max address to test-nop to execute-stop.

Parameters
[in]mem_addressmax target address to test
[in]testingNumberthe number of tests to perform on the memory
Returns
out the output string with start/max address-nops4trgtCCsNeeded-stop

◆ createMemTestCommands() [2/2]

template<unsigned int bytes_per_line = 8>
string createMemTestCommands ( unsigned long long int  mem_address,
unsigned int  testingNumber,
unsigned int  burst_size 
)

Create the commands for a memory test with start/max address to test-nop to execute-stop.

Parameters
[in]mem_addressmax target address to test
[out]outthe output string with start/max address-nops4trgtCCsNeeded-stop
[in]testingNumberthe number of tests to perform on the memory

Definition at line 671 of file common.cpp.

672 {
673  string out;
674  char start_cmd [bytes_per_line];
675  char stop_cmd [bytes_per_line];
676  char value_cmd[bytes_per_line];
677  char burst_cmd[bytes_per_line];
678  //WARNING: currently hardcoded way of start and stop commands with a 1 and 2 for start and stop respectively
679  for (unsigned int k = 0; k < bytes_per_line; k++) {
680  value_cmd[k] = (char)0;
681  if (k != 0) {
682  stop_cmd[k] = (char)0;
683  start_cmd[k] = (char)0;
684  burst_cmd[k] = (char)0;
685  }
686  else {
687  start_cmd[k] = (char)1;
688  stop_cmd[k] = (char)2;
689  burst_cmd[k] = (char)4;
690  }
691  }
692  memcpy(start_cmd+1, (char*)&testingNumber, 2);
693  out = out.append(start_cmd,3);
694  memcpy(value_cmd, (char*)&mem_address, 5);
695  out = out.append(value_cmd,5);
696  memcpy(burst_cmd+1,(char*)&burst_size,2);
697  out = out.append(burst_cmd,8);
698  return string(out);
699  }

◆ createMemTestGoldenOutput() [1/2]

std::string createMemTestGoldenOutput ( unsigned long long int  mem_address,
int  testingNumber 
)

Create the expected output results for the memory test (with FAULT INJECTION)

Parameters
[in]mem_addressmax target address to test
[in]testingNumberthe number of tests to perform on the memory
Returns
out the results of the memory test (with FAULT INJECTION)
Here is the caller graph for this function:

◆ createMemTestGoldenOutput() [2/2]

template<unsigned int bytes_per_line = 8>
string createMemTestGoldenOutput ( unsigned long long int  mem_address,
unsigned int  testingNumber,
bool  with_bw_analysis 
)

Create the expected output results for the memory test (with FAULT INJECTION)

Parameters
[in]mem_addressmax target address to test
[out]outthe results of the memory test (with FAULT INJECTION)
[in]testingNumberthe number of tests to perform on the memory

Definition at line 710 of file common.cpp.

711 {
712  char addr_cmd [bytes_per_line]; // Half of the command filled with start other half with the address
713  char fault_cntr_cmd [bytes_per_line];
714  char fault_addr_cmd [bytes_per_line];
715  char filler_cmd [bytes_per_line];
716  char clock_cycles_cmd [bytes_per_line];
717  char end_of_tests_cmd [bytes_per_line];
718  char stop_cmd [bytes_per_line];
719  unsigned int fault_addr = 0;
720  unsigned int clock_cycles = 0;
721  const unsigned int first_faultTests = 3;
722  string out;
723 
724 //given parameters
725  unsigned int mem_word_size = 512;
726  unsigned int mem_size_of_word_size = 20;
727 // computations the first faulty address and the the fault counter
728  unsigned int mem_addr_per_word = mem_word_size / 8; // byte size of this word
729  unsigned int fault_cntr = 0;
730 //precomputing the cc
731  clock_cycles = mem_address % mem_addr_per_word == 0 ? mem_address / mem_addr_per_word : (unsigned int) mem_address / mem_addr_per_word + 1;
732 
733 
734 //simulating the fault injection
735  for (unsigned int j = 1; j < mem_address/64; j++)
736  {
737  ap_uint<512> currentNumber = j;
738  ap_uint<512> nextNumber = (currentNumber+1) xor 1;
739  ap_uint<512> tmpNumber = nextNumber;
740  tmpNumber = nextNumber & 0;
741  if( nextNumber != (tmpNumber)){
742  fault_cntr+=1;
743  }
744  }
745  // for (unsigned int j = 0; j < mem_address; j+=mem_addr_per_word)
746  // {
747  // ap_uint<32> currentNumber = j;
748  // ap_uint<32> nextNumber = (currentNumber+1) xor 1;
749  // ap_uint<32> prevNumber = currentNumber;
750  // ap_uint<32> tmpNumber = nextNumber;
751  // ap_uint<32> mask = 0;
752 
753  // for (unsigned int i = 0; i < mem_word_size/32 && j > 0; i++){
754  // tmpNumber = nextNumber & 0;
755 
756  // if( nextNumber != (tmpNumber)){
757  // fault_cntr+=1;
758  // }
759  // prevNumber = currentNumber;
760  // currentNumber = nextNumber;
761  // nextNumber = (nextNumber + 1 ) xor i;
762  // }
763  // }
764 
765 
766 //init the commands and fill em out of the fault simulation before
767  for(unsigned int i = 0; i < testingNumber; i++){
768  for (unsigned int k = 0; k < bytes_per_line; k++) {
769  addr_cmd[k] = (char)0;
770  filler_cmd[k] = (char)0;
771  fault_cntr_cmd[k] = (char)0;
772  fault_addr_cmd[k] = (char)0;
773  stop_cmd[k] = (char)0;
774  stop_cmd[k] = (char)0;
775  end_of_tests_cmd[k] = (char)0;
776  clock_cycles_cmd[k] = (char)0;
777  }
778  stop_cmd[0] = (char)2;
779  end_of_tests_cmd[0] = (char)3;
780  memcpy(end_of_tests_cmd+1, (char*)&testingNumber, 2);
781  memcpy(addr_cmd, (char*)&mem_address, sizeof(unsigned long long int));
782  out = out.append(addr_cmd,bytes_per_line);
783  //if not yet in the fault injection point just let em empty as expected from good tests
784  if(i < first_faultTests-1 || mem_address <= mem_addr_per_word)
785  {
786  out = out.append(filler_cmd,bytes_per_line);
787  out = out.append(filler_cmd,bytes_per_line);
788  }else{
789  memcpy(fault_cntr_cmd, (char*)&fault_cntr, sizeof(unsigned int));
790  out = out.append(fault_cntr_cmd,bytes_per_line);
791  memcpy(fault_addr_cmd, (char*)&mem_addr_per_word, sizeof(unsigned int));
792  out = out.append(fault_addr_cmd,bytes_per_line);
793  }
794  // memcpy(clock_cycles_cmd, (char*)&clock_cycles, sizeof(unsigned int));
795  // memcpy(clock_cycles_cmd+sizeof(unsigned int), (char*)&clock_cycles, sizeof(unsigned int));
796  // out = out.append(clock_cycles_cmd,bytes_per_line);
798  const unsigned int dummycc=1;
799  memcpy(clock_cycles_cmd,(char*)& dummycc, sizeof(unsigned int));
800  out = out.append(clock_cycles_cmd,bytes_per_line);//read
801  out = out.append(filler_cmd,bytes_per_line);//write
802  }
803  out = out.append(end_of_tests_cmd,bytes_per_line);
804  // out.append(stop_cmd,bytes_per_line);
805  return string(out);
806 }

◆ createUppercaseGoldenOutput()

std::string createUppercaseGoldenOutput ( std::string  input_string)

Create the expected output results for the uppercase.

Parameters
[in]input_stringthe input string of the uppercase
Returns
out the results of the uppercase

Definition at line 815 of file common.cpp.

815  {
816  std::string strGold;
817  strGold = input_string;
818  uppercase_conversion:
819  for (unsigned int i = 0; i < strGold.length(); i++ ) {
820  if (strGold[i] >= 'a' && strGold[i] <= 'z'){
821  strGold[i] = strGold[i] - ('a' - 'A');
822  }
823  }
824  return strGold;
825 }

◆ dumpDataToFile()

bool dumpDataToFile ( UdpWord udpWord,
std::ofstream &  outFileStream 
)

Dump a data word to a file.

Parameters
[in]udpWord,apointer to the data word to dump.
[in]outFileStream,theoutput file stream to write to.
Returns
OK if successful, otherwise KO.

◆ dumpFileToString() [1/2]

bool dumpFileToString ( const std::string  inpFileName,
std::string  strOutput,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.
Here is the caller graph for this function:

◆ dumpFileToString() [2/2]

bool dumpFileToString ( const string  inpFileName,
char *  charOutput,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.

Definition at line 424 of file common.cpp.

424  {
425  string strLine;
426  ifstream inpFileStream;
427  string datFile = "../../../../test/" + inpFileName;
428  UdpWord udpWord=NetworkWord(0,0,0);
429  unsigned int i = 0;
430  unsigned int bytes_per_line = 8;
431  ap_uint<8> value[bytes_per_line];
432 
433  for(i=0; i < bytes_per_line; i++){
434  value[i]=0;
435  }
436  i=0;
437  //-- STEP-1 : OPEN FILE
438  inpFileStream.open(datFile.c_str());
439  if ( !inpFileStream ) {
440  cout << "### ERROR : Could not open the input data file " << datFile << endl;
441  return(KO);
442  }
443 
444  //-- STEP-2 : SET DATA STREAM
445  while (inpFileStream) {
446 
447  if (!inpFileStream.eof()) {
448 
449  getline(inpFileStream, strLine);
450  //cout << strLine << endl;
451  if (strLine.empty()) continue;
452  sscanf(strLine.c_str(), "%llx %x %d", &udpWord.tdata, &udpWord.tkeep, &udpWord.tlast);
453  // Write to strOutput
454  //printf("Debug: (char)udpWord.tdata.to_long()=%c\n", (char)udpWord.tdata.to_long());
455  unpack_ap_uint_64_(udpWord.tdata, value);
456  for (unsigned int k = 0; k < bytes_per_line; k++) {
457  charOutput[i++] = value[k];
458  // Print Data to console
459  #if DEBUG_LEVEL == TRACE_ALL
460  printf("[%4.4d] TB is filling string with character %c\n",
461  simCnt, (char)value[k]);
462  #endif
463  }
464  }
465  }
466  //-- STEP-3: CLOSE FILE
467  inpFileStream.close();
468  //strLine.clear();
469 
470  return(OK);
471 }
int simCnt
Definition: tb_fmc.cpp:113
void unpack_ap_uint_64_(ap_uint< 64 > value, ap_uint< 8 > *buffer)
Unpack an ap_uint<64> word to an array of 8 x ap_uint<8>.
Definition: common.cpp:139
#define OK
Definition: nts_types.hpp:57
#define KO
Definition: nts_types.hpp:58
ap_uint< 64 > tdata
ap_uint< 1 > tlast
ap_uint< 8 > tkeep
Here is the call graph for this function:

◆ dumpFileToStringRawDataString() [1/2]

template<unsigned int bytes_per_line = 8>
std::string dumpFileToStringRawDataString ( const std::string  inpFileName,
int *  rawdatalines,
size_t  outputSize 
)

Initialize an input data stream from a file with only data.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.

◆ dumpFileToStringRawDataString() [2/2]

template<unsigned int bytes_per_line = 8>
string dumpFileToStringRawDataString ( const string  inpFileName,
int *  rawdatalines,
size_t  outputSize 
)

Initialize an input data stream from a file with only data.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.

Definition at line 481 of file common.cpp.

481  {
482  string strLine;
483  string tmp_Out;
484  ifstream inpFileStream;
485  string datFile = inpFileName;
486  string charOutput;
487  //charOutput.reserve(outputSize);
488  //strLine.reserve(outputSize);
489  //tmp_Out.reserve(bytes_per_line);
490  unsigned long long int mylongunsigned;
491  unsigned long long int zero_byte=0;
492  unsigned int i = 0;
493  char my_tmp_buf [bytes_per_line];
494  //-- STEP-1 : OPEN FILE
495  inpFileStream.open(datFile.c_str());
496 
497  if ( !inpFileStream ) {
498  cout << "### ERROR : Could not open the input data file " << datFile << endl;
499  return "";
500  }
501 
502  //-- STEP-2 : SET DATA STREAM
503  while (inpFileStream) {
504 
505  if (!inpFileStream.eof()) {
506 
507  getline(inpFileStream, strLine);
508  memcpy(my_tmp_buf,&zero_byte, bytes_per_line);
509  if (strLine.empty()) continue;
510  *rawdatalines+=1;
511  mylongunsigned=stoul(strLine,nullptr,16);
512  hex2ascii(strLine, tmp_Out);
513  // Write to strOutput
514  memcpy(my_tmp_buf,(char *)&mylongunsigned, sizeof(unsigned long long int));
515  charOutput.append(my_tmp_buf, bytes_per_line);
516  i++;
517  }
518  }
519  //-- STEP-3: CLOSE FILE
520  inpFileStream.close();
521  //tmp_Out.clear();
522 
523  return string(charOutput);
524 }
void hex2ascii(const string &in, string &out)
Convert a hexadecimal string to a ascii string FIXME:
Definition: common.cpp:554
Here is the call graph for this function:

◆ dumpStringToFile() [1/2]

bool dumpStringToFile ( const string  s,
const string  outFileName,
int  simCnt 
)

Fill an output file with data from an image.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.

Definition at line 222 of file common.cpp.

223 {
224  //string strLine;
225  ofstream outFileStream;
226  string datFile = "../../../../test/" + outFileName;
227  UdpWord udpWord=NetworkWord(0,0,0);
228  bool rc = OK;
229  unsigned int bytes_per_line = 8;
230 
231  //-- STEP-1 : OPEN FILE
232  outFileStream.open(datFile.c_str());
233  if ( !outFileStream ) {
234  cout << "### ERROR : Could not open the output data file " << datFile << endl;
235  return(KO);
236  }
237  #if DEBUG_LEVEL == TRACE_ALL
238  printf("came to dumpStringToFile: s.length()=%u\n", s.length());
239  #endif
240 
241  ap_uint<8> value[bytes_per_line];
242  unsigned int total_bytes = 0;
243 
244  //-- STEP-2 : DUMP STRING DATA TO FILE
245  for (unsigned int i = 0; i < s.length(); i+=bytes_per_line, total_bytes+=bytes_per_line) {
246  //if (NPIX == XF_NPPC8) {
247  for (unsigned int k = 0; k < bytes_per_line; k++) {
248  if (i+k < s.length()) {
249  value[k] = s[i+k];
250  }
251  else {
252  value[k] = 0;
253  }
254  #if DEBUG_LEVEL == TRACE_ALL
255  printf("DEBUG: In dumpStringToFile: value[%u]=%c\n", k, (char)value[k]);
256  #endif
257  }
258  udpWord.tdata = pack_ap_uint_64_(value);
259  udpWord.tkeep = 255;
260  // We are signaling a packet termination either at the end of the image or the end of MTU
261  if ((total_bytes >= (s.length() - bytes_per_line)) ||
262  ((total_bytes + bytes_per_line) % PACK_SIZE == 0)) {
263  udpWord.tlast = 1;
264  }
265  else {
266  udpWord.tlast = 0;
267  }
268  #if DEBUG_LEVEL == TRACE_ALL
269  printf("[%4.4d] IMG TB is dumping string to file [%s] - Data read [%u] = {val=%u, D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
270  simCnt, datFile.c_str(), total_bytes, value,
271  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
272  #endif
273  if (!dumpDataToFile(&udpWord, outFileStream)) {
274  rc = KO;
275  break;
276  }
277  }
278  //-- STEP-3: CLOSE FILE
279  outFileStream.close();
280 
281  return(rc);
282 }
ap_uint< 64 > pack_ap_uint_64_(ap_uint< 8 > *buffer)
Pack an array of 8 x ap_uint<8> into a ap_uint<64> word.
Definition: common.cpp:116
bool dumpDataToFile(UdpWord *udpWord, ofstream &outFileStream)
Dump a data word to a file.
Definition: common.cpp:153
#define PACK_SIZE
Definition: config.h:51
Here is the call graph for this function:

◆ dumpStringToFile() [2/2]

bool dumpStringToFile ( std::string  s,
const std::string  outFileName,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]inpFileNamethe name of the input file to read from.
[out]strOutputthe output string to set.
Returns
OK if successful otherwise KO.
Here is the caller graph for this function:

◆ dumpStringToFileOnlyRawData() [1/2]

bool dumpStringToFileOnlyRawData ( const std::string  s,
const std::string  outFileName,
int  simCnt,
size_t  out_size 
)

Fill an output file with data from an image.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.
Here is the caller graph for this function:

◆ dumpStringToFileOnlyRawData() [2/2]

bool dumpStringToFileOnlyRawData ( const string  s,
const string  outFileName,
int  simCnt,
size_t  out_size 
)

Fill an output file with data from an image.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
Returns
OK if successful, otherwise KO.

Definition at line 292 of file common.cpp.

293 {
294  //printStringHex(s, out_size);
295 
296  //string strLine;
297  ofstream outFileStream;
298  string datFile = outFileName; //"../../../../test/" + outFileName;
299  bool rc = OK;
300  unsigned int bytes_per_line = 8;
301  ap_uint<64> tdata = 0;
302 
303  //-- STEP-1 : OPEN FILE
304  outFileStream.open(datFile.c_str());
305  if ( !outFileStream ) {
306  cout << "### ERROR : Could not open the output data file " << datFile << endl;
307  return(KO);
308  }
309  #if DEBUG_LEVEL == TRACE_ALL
310  printf("came to dumpStringToFileOnlyRawData: s.length()=%u\n", out_size);
311  #endif
312 
313  ap_uint<8> value[bytes_per_line];
314  unsigned int total_bytes = 0;
315  //-- STEP-2 : DUMP STRING DATA TO FILE
316  for (unsigned int i = 0; i < out_size; i+=bytes_per_line, total_bytes+=bytes_per_line) {
317  for (unsigned int k = 0; k < bytes_per_line; k++) {
318  if (i+k < out_size) {
319  value[k] = s[i+k];
320  }
321  else {
322  value[k] = 0;
323  }
324  #if DEBUG_LEVEL == TRACE_ALL
325  printf("DEBUG: In dumpStringToFileOnlyRawData: value[%u]=%c\n", k, (char)value[k]);
326  #endif
327  }
328  tdata = pack_ap_uint_64_(value);
329  #if DEBUG_LEVEL == TRACE_ALL
330  printf("[%4.4d] IMG TB is dumping string to file [%s] - Data read [%u] = {val=%u, D=0x%16.16llX} \n",
331  simCnt, datFile.c_str(), total_bytes, value, tdata.to_long());
332  #endif
333  outFileStream << hex << setfill('0') << setw(16) << tdata.to_uint64();
334  //outFileStream << hex << noshowbase << setfill('0') << setw(16) << tdata.to_uint64();
335  outFileStream << "\n";
336  }
337  //-- STEP-3: CLOSE FILE
338  outFileStream.close();
339 
340  return(rc);
341 }
Here is the call graph for this function:

◆ dumpStringToFileWithLastSetEveryGnoPackets() [1/2]

bool dumpStringToFileWithLastSetEveryGnoPackets ( std::string  s,
const std::string  outFileName,
int  simCnt,
int  gno 
)

Fill an output file with data from a string and set the tlast every gno packets.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
[in]simCnt
[in]gnothe counter value at which this function set the tlast=1
Returns
OK if successful, otherwise KO.
Here is the caller graph for this function:

◆ dumpStringToFileWithLastSetEveryGnoPackets() [2/2]

bool dumpStringToFileWithLastSetEveryGnoPackets ( string  s,
const string  outFileName,
int  simCnt,
int  gno 
)

Fill an output file with data from a string and set the tlast every gno packets.

Parameters
[in]sDataStreamthe input image in xf::cv::Mat format.
[in]outFileNamethe name of the output file to write to.
[in]simCnt
[in]gnothe counter value at which this function set the tlast=1
Returns
OK if successful, otherwise KO.

Definition at line 354 of file common.cpp.

355 {
356  string strLine;
357  ofstream outFileStream;
358  string datFile = "../../../../test/" + outFileName;
359  UdpWord udpWord=NetworkWord(0,0,0);
360  bool rc = OK;
361  unsigned int bytes_per_line = 8;
362 
363  //-- STEP-1 : OPEN FILE
364  outFileStream.open(datFile.c_str());
365  if ( !outFileStream ) {
366  cout << "### ERROR : Could not open the output data file " << datFile << endl;
367  return(KO);
368  }
369  #if DEBUG_LEVEL == TRACE_ALL
370  printf("came to dumpStringToFile: s.length()=%u\n", s.length());
371  #endif
372 
373  ap_uint<8> value[bytes_per_line];
374  unsigned int total_bytes = 0;
375  int cntr = 0;
376 
377  //-- STEP-2 : DUMP STRING DATA TO FILE
378  for (unsigned int i = 0; i < s.length(); cntr += 1, i+=bytes_per_line, total_bytes+=bytes_per_line) {
379  //if (NPIX == XF_NPPC8) {
380  for (unsigned int k = 0; k < bytes_per_line; k++) {
381  if (i+k < s.length()) {
382  value[k] = s[i+k];
383  }
384  else {
385  value[k] = 0;
386  }
387  #if DEBUG_LEVEL == TRACE_ALL
388  printf("DEBUG: In dumpStringToFile: value[%u]=%c\n", k, (char)value[k]);
389  #endif
390  }
391  udpWord.tdata = pack_ap_uint_64_(value);
392  udpWord.tkeep = 255;
393  // We are signaling a packet termination either at the end of the image or the end of MTU
394  if ((total_bytes >= (s.length() - bytes_per_line)) ||
395  ((total_bytes + bytes_per_line) % PACK_SIZE == 0) || ( cntr!= 0 && ((cntr+1) % gno == 0))) {
396  udpWord.tlast = 1;
397  }
398  else {
399  udpWord.tlast = 0;
400  }
401  #if DEBUG_LEVEL == TRACE_ALL
402  printf("[%4.4d] IMG TB is dumping string to file [%s] - Data read [%u] = {val=%u, D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
403  simCnt, datFile.c_str(), total_bytes, value,
404  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
405  #endif
406  if (!dumpDataToFile(&udpWord, outFileStream)) {
407  rc = KO;
408  break;
409  }
410  }
411  //-- STEP-3: CLOSE FILE
412  outFileStream.close();
413 
414  return(rc);
415 }
Here is the call graph for this function:

◆ getOutputDataStream() [1/2]

bool getOutputDataStream ( stream< UdpWord > &  sDataStream,
const std::string  dataStreamName,
const std::string  outFileName,
int  simCnt 
)

Fill an output file with data from an output stream.

Parameters
[in]sDataStream,theoutput data stream to set.
[in]dataStreamName,thename of the data stream.
[in]outFileName,thename of the output file to write to.
Returns
OK if successful, otherwise KO.

◆ getOutputDataStream() [2/2]

bool getOutputDataStream ( stream< UdpWord > &  sDataStream,
const string  dataStreamName,
const string  outFileName,
int  simCnt 
)

Fill an output file with data from an output stream.

Parameters
[in]sDataStream,theoutput data stream to set.
[in]dataStreamName,thename of the data stream.
[in]outFileName,thename of the output file to write to.
Returns
OK if successful, otherwise KO.

Definition at line 176 of file common.cpp.

178 {
179  //string strLine;
180  ofstream outFileStream;
181  string datFile = "../../../../test/" + outFileName;
182  UdpWord udpWord=NetworkWord(0,0,0);
183  bool rc = OK;
184 
185  //-- STEP-1 : OPEN FILE
186  outFileStream.open(datFile.c_str());
187  if ( !outFileStream ) {
188  cout << "### ERROR : Could not open the output data file " << datFile << endl;
189  return(KO);
190  }
191 
192  //-- STEP-2 : EMPTY STREAM AND DUMP DATA TO FILE
193  while (!sDataStream.empty()) {
194  if (readDataStream(sDataStream, &udpWord) == VALID) {
195  // Print DUT/Data to console
196  #if DEBUG_LEVEL == TRACE_ALL
197  printf("[%4.4d] TB is draining output stream [%s] - Data read = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
198  simCnt, dataStreamName.c_str(),
199  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
200  #endif
201  if (!dumpDataToFile(&udpWord, outFileStream)) {
202  rc = KO;
203  break;
204  }
205  }
206  }
207 
208  //-- STEP-3: CLOSE FILE
209  outFileStream.close();
210 
211  return(rc);
212 }
bool readDataStream(stream< UdpAppData > &sDataStream, UdpAppData *udpWord)
Read data from a stream.
Definition: tb_nal.cpp:395
#define VALID
Definition: tb_nal.cpp:43
Here is the call graph for this function:

◆ hex2ascii() [1/2]

void hex2ascii ( const std::string &  in,
std::string &  out 
)

Convert a hexadecimal string to a ascii string.

Parameters
[in]inthe input hexadecimal string
[out]outthe output ascii string

◆ hex2ascii() [2/2]

void hex2ascii ( const string &  in,
string &  out 
)

Convert a hexadecimal string to a ascii string FIXME:

Parameters
[in]inthe input hexadecimal string
[out]outthe output ascii string

Definition at line 554 of file common.cpp.

555 {
556  out.clear();
557  out.reserve(in.length() / 2);
558  for (string::const_iterator p = in.begin(); p != in.end(); p++)
559  {
560  unsigned char c = hexval(*p);
561  p++;
562  if (p == in.end()) break; // incomplete last digit - should report error
563  c = (c << 4) + hexval(*p); // + takes precedence over <<
564  out.push_back(c);
565  }
566 }
unsigned char hexval(unsigned char c)
convert a char to its hexadecimal representation.
Definition: common.hpp:234
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hexval()

unsigned char hexval ( unsigned char  c)

convert a char to its hexadecimal representation.

Parameters
[in]cthe standard char value to convert to hex
Returns
the hexadecimal value of the input

Definition at line 537 of file common.cpp.

538 {
539  if ('0' <= c && c <= '9')
540  return c - '0';
541  else if ('a' <= c && c <= 'f')
542  return c - 'a' + 10;
543  else if ('A' <= c && c <= 'F')
544  return c - 'A' + 10;
545  else abort();
546 }

◆ isCornerPresent() [1/2]

bool isCornerPresent ( std::string  str,
std::string  corner 
)

Check the presence of a given corner value at the begin and the end of a string.

Parameters
[in]strthe input string to be checked
[in]cornerthe corner char to find
Returns
true if it is present, false otherwise
Here is the caller graph for this function:

◆ isCornerPresent() [2/2]

bool isCornerPresent ( string  str,
string  corner 
)

Check the presence of a given corner value at the begin and the end of a string.

Parameters
[in]strthe input string to be checked
[in]cornerthe corner char to find
Returns
true if it is present, false otherwise

Definition at line 606 of file common.cpp.

607 {
608  int n = str.length();
609  int cl = corner.length();
610 
611  // If length of corner string is more, it
612  // cannot be present at corners.
613  if (n < cl)
614  return false;
615 
616  // Return true if corner string is present at
617  // both corners of given string.
618  return (str.substr(0, cl).compare(corner) == 0 &&
619  str.substr(n-cl, cl).compare(corner) == 0);
620 }

◆ pack_ap_uint_64_()

ap_uint< 64 > pack_ap_uint_64_ ( ap_uint< 8 > *  buffer)

Pack an array of 8 x ap_uint<8> into a ap_uint<64> word.

Parameters
[in]bufferA pointer to an array of 8 x ap_uint<8>
Returns
An ap_uint<64> word.

Definition at line 116 of file common.cpp.

116  {
117 
118  ap_uint<64> value = 0;
119 
120  value = buffer[7];
121  value = (value << 8 ) + buffer[6];
122  value = (value << 8 ) + buffer[5];
123  value = (value << 8 ) + buffer[4];
124  value = (value << 8 ) + buffer[3];
125  value = (value << 8 ) + buffer[2];
126  value = (value << 8 ) + buffer[1];
127  value = (value << 8 ) + buffer[0];
128 
129  return value ;
130 
131 }
Here is the caller graph for this function:

◆ parseMemoryTestOutput() [1/2]

template<unsigned int bytes_per_line = 8>
std::vector<MemoryTestResult> parseMemoryTestOutput ( const std::string  longbuf,
size_t  charOutputSize,
int  rawdatalines 
)

Parse the memory test output contained in astring with a given size.

Parameters
[in]longbufthe buffer containing the output
[in]charOutputSizethe bytesize of the buffer
[in]rawdatalinesthe number of lines in the given outbuf
Returns
vectpr of MemoryTestResult data strcuture

◆ parseMemoryTestOutput() [2/2]

template<unsigned int bytes_per_line = 8>
std::vector<MemoryTestResult> parseMemoryTestOutput ( const string  longbuf,
size_t  charOutputSize,
int  rawdatalines 
)

Parse the memory test output contained in astring with a given size.

Parameters
[in]longbufthe buffer containing the output
[in]charOutputSizethe bytesize of the buffer
[in]rawdatalinesthe number of lines in the given outbuf
Returns
vectpr of MemoryTestResult data strcuture

Definition at line 855 of file common.cpp.

856 {
857  std::vector<MemoryTestResult> testResults_vector;
858 
859  int rawiterations = charOutputSize / 8; //should be equivalent to rawdatalines
860  unsigned int mem_word_size = 512;
861  unsigned int mem_word_byte_size = mem_word_size/8;
862  bool is_stop_present = rawdatalines % (3+1+1) == 0; //guard to check if multiple data of 3 64bytes or with
863 
864  int k = 1;
865  char myTmpOutBuff [bytes_per_line];
866  for (int i = 0; i < bytes_per_line; ++i)
867  {
868  myTmpOutBuff[i]=(char)0;
869  }
870  unsigned int testingNumber_out=0, fault_cntr_out=0, fault_addr_out=0;
871  unsigned long long int max_memory_addr_out=0, clock_cycles_read=0, clock_cycles_write=0;
872  for (int i = 1; i < rawdatalines+1; i++)
873  {
874  string tmp_outbuff;
875  tmp_outbuff= longbuf.substr((i-1)*bytes_per_line,bytes_per_line);
876  if(is_stop_present && k==7){
877  cout << "DEBUG the stop is present and is here" << endl;
878  } else if( ( (i == rawdatalines-1) || (i == rawdatalines) ) && k==6){ //check it is either the last or one before the last
879  //substr extraction and parsing
880  //strncpy(myTmpOutBuff,tmp_outbuff.c_str()+1,bytes_per_line-1);
881  //testingNumber_out = *reinterpret_cast<unsigned long long*>(myTmpOutBuff);
882  memcpy(&testingNumber_out,tmp_outbuff.c_str()+1,bytes_per_line/2);
883 
884  #if DEBUG_LEVEL == TRACE_ALL
885  cout << "DEBUG last command with the iterations " << testingNumber_out << endl;
886  #endif
887  }else if(k==5){
888  //strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line);
889  //clock_cycles_read = *reinterpret_cast<unsigned long long int*>(myTmpOutBuff);
890  memcpy(&clock_cycles_read,tmp_outbuff.c_str(),bytes_per_line);
891 
892  #if DEBUG_LEVEL == TRACE_ALL
893  cout << "DEBUG clock_cycles_read (or the fourth half data pckt) " << clock_cycles_read << endl;
894  cout << "DEBUG clock_cycles_write (or the fourth half data pckt) " << clock_cycles_write << endl;
895  #endif
896  MemoryTestResult tmpResult(max_memory_addr_out,fault_cntr_out,fault_addr_out,clock_cycles_write,clock_cycles_read);
897  testResults_vector.push_back(tmpResult);
898  if(!( (i+1 == rawdatalines-1) || (i+1 == rawdatalines) )){
899  k=0;
900  #if DEBUG_LEVEL == TRACE_ALL
901  cout << "DEBUG reinit the counter" << endl;
902  #endif
903  }
904  unsigned int written_words = max_memory_addr_out%mem_word_byte_size == 0 ? max_memory_addr_out/mem_word_byte_size : max_memory_addr_out/mem_word_byte_size + 1;
905  double rd_bndwdth = ( (double)written_words*(double)mem_word_size / ( (double)tmpResult.clock_cycles_read * ( 6.4 ) ) ); // Gbit/T
906  double wr_bndwdth = ( (double)written_words*(double)mem_word_size / ( (double)tmpResult.clock_cycles_write * ( 6.4 ) ) );
907  #if DEBUG_LEVEL == TRACE_ALL
908  cout << "Written " << written_words << " words" << endl;
909  cout << "DEBUG overall test results: target address " << tmpResult.target_address << " ";
910  cout << "Fault counter: " << tmpResult.fault_cntr << " ";
911  cout << "First fault at address: " << tmpResult.first_fault_address << " " << endl;
912  cout << " RD BW " << rd_bndwdth << "[GBit/s] with cc equal to " << tmpResult.clock_cycles_read << " " << endl;
913  cout << " WR BW " << wr_bndwdth << "[GBit/s] with cc equal to " << tmpResult.clock_cycles_write << " " << endl;
914  #endif
915  } else if(k==4){ //clock cycless
916  //char mySecondTmpOutBuff[bytes_per_line/2];
917  //string additional_string;
918  //init the buffer
919  //for(int i=0;i<bytes_per_line;i++){myTmpOutBuff[i]=(char)0;mySecondTmpOutBuff[i%(bytes_per_line/2)]=(char)0;}
920  // additional_string=tmp_outbuff.substr(bytes_per_line/2,bytes_per_line/2);
921  //
922  // tmp_outbuff = tmp_outbuff.erase(bytes_per_line/2,bytes_per_line/2);
923  // strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line/2);
924  // clock_cycles_read = *reinterpret_cast<unsigned int*>(myTmpOutBuff);
925  //
926  // strncpy(mySecondTmpOutBuff,additional_string.c_str(),bytes_per_line/2);
927  // clock_cycles_write = *reinterpret_cast<unsigned int*>(mySecondTmpOutBuff);
928  //strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line);
929  //clock_cycles_write = *reinterpret_cast<unsigned long long int*>(myTmpOutBuff);
930  memcpy(&clock_cycles_write,tmp_outbuff.c_str(),bytes_per_line);
931 
932  }else if(k==3){ // first fault address
933  //substr extraction and parsing
934  //strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line);
935  //fault_addr_out = *reinterpret_cast<unsigned long long int *>(myTmpOutBuff);
936  memcpy(&fault_addr_out,tmp_outbuff.c_str(),bytes_per_line/2);
937 
938  #if DEBUG_LEVEL == TRACE_ALL
939  cout << "DEBUG first fault address (or the third data pckt) " << fault_addr_out << endl;
940  #endif
941  }else if(k==2){ // fault cntr
942  //strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line);
943  //fault_cntr_out = *reinterpret_cast<unsigned long long int *>(myTmpOutBuff);
944  memcpy(&fault_cntr_out,tmp_outbuff.c_str(),bytes_per_line/2);
945 
946  #if DEBUG_LEVEL == TRACE_ALL
947  cout << "DEBUG the fault counters (or the second data pack) " << fault_cntr_out << endl;
948  #endif
949  }else { //max addrss
950  //substr extraction and parsing
951  // strncpy(myTmpOutBuff,tmp_outbuff.c_str(),bytes_per_line);
952  // max_memory_addr_out = *reinterpret_cast<unsigned long long *>(myTmpOutBuff);
953  memcpy(&max_memory_addr_out,tmp_outbuff.c_str(),bytes_per_line);
954  #if DEBUG_LEVEL == TRACE_ALL
955  cout << "DEBUG max address (or the first data pack) " << max_memory_addr_out << endl;
956  #endif
957  }
958  k++;
959  tmp_outbuff.clear();
960  }
961  return testResults_vector;
962 }

◆ printBits()

void printBits ( size_t const  size,
void const *const  ptr 
)

print the binary representation of a target pointer buffer of a given size. Assumes little endian.

Parameters
[in]sizethe bytesize to print from ptr.
[in]ptrthe buffer pointer.
Returns
nothing, print to stdout.

Definition at line 1010 of file common.cpp.

1011 {
1012  unsigned char *b = (unsigned char*) ptr;
1013  unsigned char byte;
1014  int i, j;
1015 
1016  for (i = size-1; i >= 0; i--) {
1017  for (j = 7; j >= 0; j--) {
1018  byte = (b[i] >> j) & 1;
1019  printf("%u", byte);
1020  }
1021  }
1022  puts("");
1023 }
ap_uint< 32 > size

◆ printCharBuffHex()

void printCharBuffHex ( const char *  inStr,
size_t  strSize 
)

print byte-per-byte a given char buff in hexadecimal format

Parameters
[in]inStrchar buff to print
[in]strSizebytsize to print (can be even less, NOT more )

Definition at line 990 of file common.cpp.

990  {
991  #if DEBUG_LEVEL == TRACE_ALL
992  printf("Going to prit a hex char buff :D\n");
993  #endif
994  for (size_t i = 0; i < strSize; i++)
995  {
996  printf("%x",inStr[i]);
997  }
998  printf("\n");
999 
1000 }

◆ printStringHex() [1/2]

void printStringHex ( const std::string  inStr,
size_t  strSize 
)

print byte-per-byte a given string in hexadecimal format

Parameters
[in]inStrstring to print
[in]strSizebytsize to print (can be even less, NOT more )

◆ printStringHex() [2/2]

void printStringHex ( const string  inStr,
size_t  strSize 
)

print byte-per-byte a given string in hexadecimal format

Parameters
[in]inStrstring to print
[in]strSizebytsize to print (can be even less, NOT more )

Definition at line 971 of file common.cpp.

971  {
972  #if DEBUG_LEVEL == TRACE_ALL
973  printf("Going to print a hex string :D\n");
974  #endif
975  for (size_t i = 0; i < strSize; i++)
976  {
977  printf("%x",inStr[i]);
978  }
979  printf("\n");
980 
981 }

◆ reverseStr() [1/2]

void reverseStr ( std::string &  str)

reverse a given string

Parameters
[in]strthe string to reverse.
Returns
nothing, print to stdout.

◆ reverseStr() [2/2]

void reverseStr ( string &  str)

reverse a given string

Parameters
[in]strthe string to reverse.
Returns
nothing, print to stdout.

Definition at line 835 of file common.cpp.

836 {
837  int n = str.length();
838 
839  // Swap character starting from two
840  // corners
841  for (int i = 0; i < n / 2; i++)
842  swap(str[i], str[n - i - 1]);
843 }

◆ setInputDataStream() [1/2]

bool setInputDataStream ( stream< UdpWord > &  sDataStream,
const std::string  dataStreamName,
const std::string  inpFileName,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]sDataStreamthe input data stream to set.
[in]dataStreamNamethe name of the data stream.
[in]inpFileNamethe name of the input file to read from.
Returns
OK if successful otherwise KO.

◆ setInputDataStream() [2/2]

bool setInputDataStream ( stream< UdpWord > &  sDataStream,
const string  dataStreamName,
const string  inpFileName,
int  simCnt 
)

Initialize an input data stream from a file.

Parameters
[in]sDataStreamthe input data stream to set.
[in]dataStreamNamethe name of the data stream.
[in]inpFileNamethe name of the input file to read from.
Returns
OK if successful otherwise KO.

Definition at line 45 of file common.cpp.

46  {
47  string strLine;
48  ifstream inpFileStream;
49  string datFile = "../../../../test/" + inpFileName;
50  UdpWord udpWord=NetworkWord(0,0,0);
51 
52  //-- STEP-1 : OPEN FILE
53  inpFileStream.open(datFile.c_str());
54  if ( !inpFileStream ) {
55  cout << "### ERROR : Could not open the input data file " << datFile << endl;
56  return(KO);
57  }
58 
59  //-- STEP-2 : SET DATA STREAM
60  while (inpFileStream) {
61 
62  if (!inpFileStream.eof()) {
63 
64  getline(inpFileStream, strLine);
65  if (strLine.empty()) continue;
66  sscanf(strLine.c_str(), "%llx %x %d", &udpWord.tdata, &udpWord.tkeep, &udpWord.tlast);
67 
68  // Write to sDataStream
69  if (sDataStream.full()) {
70  printf("### ERROR : Stream is full. Cannot write stream with data from file \"%s\".\n", inpFileName.c_str());
71  return(KO);
72  } else {
73  sDataStream.write(udpWord);
74  // Print Data to console
75  #if DEBUG_LEVEL == TRACE_ALL
76  printf("[%4.4d] TB is filling input stream [%s] - Data write = {D=0x%16.16llX, K=0x%2.2X, L=%d} \n",
77  simCnt, dataStreamName.c_str(),
78  udpWord.tdata.to_long(), udpWord.tkeep.to_int(), udpWord.tlast.to_int());
79  #endif
80  }
81  }
82  }
83 
84  //-- STEP-3: CLOSE FILE
85  inpFileStream.close();
86  //strLine.clear();
87 
88  return(OK);
89 }

◆ string2hexnumerics() [1/2]

template<typename T >
void string2hexnumerics ( const std::string &  in,
char *  out,
size_t  byteSize 
)

Convert a hex string to a T type into a char buffer with the SAME dimensions.

Parameters
[in]inthe input hex string
[out]outthe output numerical hexadec string string
[in]byteSizethe bytesize of the input string and the buffer, it assumes equal dimension

◆ string2hexnumerics() [2/2]

template<typename T >
void string2hexnumerics ( const string &  in,
char *  out,
size_t  byteSize 
)

Convert a hex string to a integer into a char buffer with the SAME dimensions FIXME:

Parameters
[in]inthe input hex string
[out]outthe output numerical hexadec string string
[in]byteSizethe bytesize of the input string and the buffer, it assumes equal dimension

Definition at line 630 of file common.cpp.

631 {
632  for (unsigned int i = 0; i < byteSize; i++)
633  {
634  std::sprintf(out+i, "%d", (T)in[i]);
635  }
636 }

◆ string2hexnumericsString()

void string2hexnumericsString ( const string &  in,
string &  out,
size_t  byteSize 
)

Convert a hex string to a integer into a char buffer with the SAME dimensions FIXME:

Parameters
[in]inthe input hex string
[out]outthe output numerical hexadec string string
[in]byteSizethe bytesize of the input string and the buffer, it assumes equal dimension

Definition at line 652 of file common.cpp.

653 {
654  char tmp_out [byteSize];
655  for (unsigned int i = 0; i < byteSize; i++)
656  {
657  std::sprintf(tmp_out+i, "%d", (int)in[i]);
658  }
659  out.append(tmp_out);
660 }

◆ stringHex2Unsigned()

void stringHex2Unsigned ( const string &  in,
unsigned int *  out,
size_t  byteSize 
)

Definition at line 638 of file common.cpp.

639 {
640  for (unsigned int i = 0; i < byteSize; i++)
641  {
642  std::sprintf((char*)out+i, "%u", (unsigned int)in[i]);
643  }
644 }

◆ unpack_ap_uint_64_()

void unpack_ap_uint_64_ ( ap_uint< 64 >  value,
ap_uint< 8 > *  buffer 
)

Unpack an ap_uint<64> word to an array of 8 x ap_uint<8>.

Parameters
[in]bufferA pointer to an ap_uint<64> word
Returns
An ap_uint<64> word.

Definition at line 139 of file common.cpp.

139  {
140 
141  for (unsigned int i=0; i<8; i++) {
142  buffer[i] = (value >> 8*i );
143  }
144 }
Here is the caller graph for this function: