ASIC/FPGA Design and Verification Out Source Services
C++ Reference model for ECC main code.
-
This code is part of the following
project:
A reference model, in c++, that generates ECC for a 256 bytes.
-
The tasks of the c++ main is to inject random data, check the
results of the ECC and print debug messages.
-
Code Description:
ECC class and data arrays instantiation:
unsigned char a_data[ARRAY_SZ];
unsigned char b_data[ARRAY_SZ];
unsigned char bit_err;
c_ecc *ecc, *err;
c_e_ccc_correct *correct;
Random variables:
unsigned char shift, loc;
c_pk_dist *dist;
map<unsigned char, unsigned char> map_dist;
Note: The
distribution allows to specify the
probability of each desired number of errors in
percents:
link
map_dist[0] = 80; //80% single error
map_dist[1] = 95; //15% double error
map_dist[2] = 98; // 3%
map_dist[6] = 100; // 2%
dist = new c_pk_dist(map_dist);
-
The input data is generated in random:
for(i=0; i < ARRAY_SZ; i++) {a_data[i]=rand() % 256; b_data[i]=a_data[i];}
Once the number of error is generated, it is inserted in
random location (determined by two parameters: byte and
bit location).
- for(i = 0; i <= dist->result; i++) {
- shift=rand()%8; //bit location
- loc =rand()%ARRAY_SZ; //byte location
- bit_err=1 << shift;
- if(a_data[loc] & bit_err) a_data[loc] &= ~bit_err; else a_data[loc] |= bit_err;
- }
If a single error was inserted, it must be fixed.
If not the
main code issues an error message.
- for(i=0; i < ARRAY_SZ; i++)
- if(b_data[i] != a_data[i]) {
- if(j == 1) cout << "Error * ";
|