-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbench.cpp
More file actions
68 lines (54 loc) · 1.37 KB
/
Copy pathtestbench.cpp
File metadata and controls
68 lines (54 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "testbench.h"
#include <bitset>
#include <iostream>
using namespace std;
void tbreg::send(){
//send the data to encode
din_vld.write(0);
for(int i=0;i<128; i++){
din_vld.write(1);
din.write(i);
do{
wait();
}while(!din_rdy.read());
din_vld.write(0);
}
//send the data to decode
codedin_vld.write(0);
for(int i=0;i<128; i++){
codedin_vld.write(1);
coded_din.write(i);
do{
wait();
}while(!codedin_rdy.read());
codedin_vld.write(0);
}
}
void tbreg::receive(){
sc_uint <15> coded_data_tmp;
codedout_rdy.write(0);
cout << "\n ****** THE ENCODING ****** \n"<<endl;
for(int i=0;i<128; i++){
codedout_rdy.write(1);
do{
wait();
}while(!codedout_vld.read());
coded_data_tmp=coded_dout.read();
cout <<" a word of <11> bits : "<< std::bitset<11>(i) << " -> its Hamming code on <15> bits : " << std::bitset<15>(coded_data_tmp) <<endl;
codedout_rdy.write(0);
}
cout << "\n ****** THE DECODING ****** \n"<<endl;
sc_uint <11> corrected_data_tmp;
dout_rdy.write(0);
for(int i=0;i<128; i++){
dout_rdy.write(1);
do{
wait();
}while(!dout_vld.read());
corrected_data_tmp=dout.read();
//wait();
cout <<" a Hamming code word on <15> bits: "<< std::bitset<15>(i) << " -> after the correction and the decoding <11> bits : " << std::bitset<11>(corrected_data_tmp) <<endl;
dout_rdy.write(0);
}
sc_stop(); //stop the simulation
}