-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_counter_tb.cpp
73 lines (67 loc) · 1.84 KB
/
first_counter_tb.cpp
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
69
70
71
72
73
#include "systemc.h"
#if 0
#include "first_counter.cpp"
#else
#include "counter_vhdl.cpp"
#endif
int sc_main (int argc, char* argv[]) {
sc_signal<bool> clock;
sc_signal<bool> reset;
sc_signal<bool> enable;
sc_signal<sc_uint<4> > counter_out;
int i = 0;
// Connect the DUT
first_counter counter("COUNTER");
counter.clock(clock);
counter.reset(reset);
counter.enable(enable);
counter.counter_out(counter_out);
sc_start(1, SC_NS);
// Open VCD file
sc_trace_file *wf = sc_create_vcd_trace_file("counter");
// Dump the desired signals
sc_trace(wf, clock, "clock");
sc_trace(wf, reset, "reset");
sc_trace(wf, enable, "enable");
sc_trace(wf, counter_out, "count");
// Initialize all variables
reset = 0; // initial value of reset
enable = 0; // initial value of enable
for (i=0;i<5;i++) {
clock = 0;
sc_start(1, SC_NS);
clock = 1;
sc_start(1, SC_NS);
}
reset = 1; // Assert the reset
cout << "@" << sc_time_stamp() <<" Asserting reset\n" << endl;
for (i=0;i<10;i++) {
clock = 0;
sc_start(1, SC_NS);
clock = 1;
sc_start(1, SC_NS);
}
reset = 0; // De-assert the reset
cout << "@" << sc_time_stamp() <<" De-Asserting reset\n" << endl;
for (i=0;i<5;i++) {
clock = 0;
sc_start(1, SC_NS);
clock = 1;
sc_start(1, SC_NS);
}
cout << "count=" << counter_out << endl;
cout << "@" << sc_time_stamp() <<" Asserting Enable\n" << endl;
enable = 1; // Assert enable
for (i=0;i<20;i++) {
clock = 0;
sc_start(1, SC_NS);
clock = 1;
sc_start(1, SC_NS);
}
cout << "count=" << counter_out << endl;
cout << "@" << sc_time_stamp() <<" De-Asserting Enable\n" << endl;
enable = 0; // De-assert enable
cout << "@" << sc_time_stamp() <<" Terminating simulation\n" << endl;
sc_close_vcd_trace_file(wf);
return 0;// Terminate simulation
}