Data randomization using SCV (a very power full mechanism for doing
randomization).
-
In this site I show how to random simple fields in an
ECC project.
If more constraint driven complex scheme of randomization is required, one can use the
SCV, which comes freely with systemc.
-
How to use SCV is well documented and can be easily found on WEB. In this
example, however, I show to use it in a small c++ (cpp) project (not
necessarily systemc project).
-
First a structure for the randomization target has to be declared.
struct ecc_errors_t {
unsigned char num_err; //number of errors
unsigned char loc_err; //error array location
unsigned char bit_err; //error bit location
};
-
Next extend the SCV by the following:
#ifndef DATA_EXT_H
#define DATA_EXT_H
#include "scv.h"
#include "data.h"
//declarations below this point are due to the --EXTEND_ALL option
template<>
class scv_extensions<ecc_errors_t> : public scv_extensions_base<ecc_errors_t> {
public:
scv_extensions<unsigned char > num_err;
scv_extensions<unsigned char > loc_err;
scv_extensions<unsigned char > bit_err;
SCV_EXTENSIONS_CTOR(ecc_errors_t) {
SCV_FIELD(num_err);
SCV_FIELD(loc_err);
SCV_FIELD(bit_err);
}
};
#endif //DATA_EXT_H
-
Last we use it in a simple main cpp program:
#include "systemc.h"
#include "data_ext.h"
int main (int argc, char *argv[]) {
if(argc > 1) {
scv_random::set_global_seed(atoi(argv[1]));
}
scv_smart_ptr<ecc_errors_t> data_p("My_data");
data_p->num_err.keep_only(0, 2);
data_p->loc_err.keep_only(5, 255);
data_p->bit_err.keep_only(0, 7);
data_p->next();
cout <<
"num=" << (unsigned)data_p->num_err << endl;
cout <<
"loc=" << (unsigned)data_p->loc_err << endl;
cout <<
"bit=" << (unsigned)data_p->bit_err << endl;
return 0;
}
-
I use the make file, which is given in the SCV examples:
make -f Makefile.osci
TOPDIR=/mnt/Home/pini/Home_1/pini/systemc_2.2.0/examples/scv
SOURCE_FILES=scv_rand_1.cpp
include ${TOPDIR}/Makefile.rules
This creates an executable named run.x and runs it. To run it, without
the makefile (./run.x), you need to define the following variable:
LD_LIBRARY_PATH=.:/mnt/Home/pini/Home_1/pini/systemc_2.2.0/lib-linux:/mnt/Home/pini/Home_1/pini/systemc_2.2.0/lib-linux
export LD_LIBRARY_PATH
-
Recently I tried to use systemc and scv on linux machine with
cadence tools. I wanted a little, standalone program, which randomize
some numbers with the simple constrains as scv allows. I did not have
much time to spend on the best way do it with cadence installation, so
I came out with the following script to
compile and link the program. This
is not ideal, but worked well for me:
- #!/bin/bash
- echo $LD_LIBRARY_PATH | grep cadence
- if [ $? -ne 0 ] ; then
- setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/tools/cadence/INCISIV12.2-s005/tools.lnx86/lib/64bit
- fi
- rm -f a.out *.o
- clear
- g++ -I/tools/cadence/INCISIV12.2-s005/tools.lnx86/systemc/include -I/tools/cadence/INCISIV12.2-s005/tools.lnx86/tbsc/include main.cpp -ldl -L/tools/cadence/INCISIV12.2-s005/tools.lnx86/lib/64bit -lrnc /tools/oss/packages/x86_64-rhel4/gcc/4.1.2/lib64/libstdc++.a /tools/cadence/INCISIV12.2-s005/tools.lnx86/systemc/lib/64bit/libsystemc_ar.a /tools/cadence/INCISIV12.2-s005/tools.lnx86/tbsc/lib/64bit/libscv.a
- echo $LD_LIBRARY_PATH
|