|
|
Once started, the scheduler will run until either it completes, or the application calls the function sc_stop, or an exception occurs. Once the function sc_stop has been called, function sc_start shall not be called again. Function sc_start may be called from function sc_main, and only from function sc_main. |
|
|
1 #include <systemc.h>
2
3 SC_MODULE (some_block) {
4 sc_in<bool> clock;
5 sc_in<sc_bit> data;
6 sc_in<sc_bit> reset;
7 sc_in<sc_bit> inv;
8 sc_out<sc_bit> out;
9
10 void body () {
11 if (reset.read() == 1) {
12 out = sc_bit(0);
13 } else if (inv.read() == 1) {
14 out = ~out.read();
15 } else {
16 out.write(data.read());
17 }
18 }
19
20 SC_CTOR(some_block) {
21 SC_METHOD(body);
22 sensitive << clock.pos();
23 }
24 };
25
26
27 SC_MODULE (signal_bind) {
28 sc_in<bool> clock;
29
30 sc_signal<sc_bit> data;
31 sc_signal<sc_bit> reset;
32 sc_signal<sc_bit> inv;
33 sc_signal<sc_bit> out;
34 some_block *block;
35
36 void do_test() {
37 while (true) {
38 wait();
39 cout << "@" << sc_time_stamp() <<" Starting test"<<endl;
40 wait();
41 wait();
42 inv = sc_bit('0');
43 data = sc_bit('0');
44 cout << "@" << sc_time_stamp() <<" Driving 0 all inputs"<<endl;
45 // Assert reset
46 reset = sc_bit('1');
47 cout << "@" << sc_time_stamp() <<" Asserting reset"<<endl;
48 // Deassert reset
49 wait();
50 wait();
51 reset = sc_bit('0');
52 cout << "@" << sc_time_stamp() <<" De-Asserting reset"<<endl;
53 // Assert data
54 wait();
55 wait();
56 cout << "@" << sc_time_stamp() <<" Asserting data"<<endl;
57 data = sc_bit('1');
58 wait();
59 wait();
60 cout << "@" << sc_time_stamp() <<" Asserting inv"<<endl;
61 inv = sc_bit('1');
62 wait();
63 wait();
64 cout << "@" << sc_time_stamp() <<" De-Asserting inv"<<endl;
65 inv = sc_bit('0');
66 wait();
67 wait();
68 cout<<"Terminating Simulation"<<endl;
69 sc_stop(); // sc_stop triggers end of simulation
70 }
71 }
72
73 void monitor() {
74 cout << "@" << sc_time_stamp() << " data :" << data
75 << " reset :" << reset << " inv :"
76 << inv << " out :" << out <<endl;
77 }
78
79 SC_CTOR(signal_bind) {
80 block = new some_block("SOME_BLOCK");
81 block->clock (clock) ;
82 block->data (data) ;
83 block->reset (reset) ;
84 block->inv (inv) ;
85 block->out (out) ;
86
87 SC_CTHREAD(do_test,clock.pos());
88 SC_METHOD(monitor);
89 sensitive << data << reset << inv << out;
90 }
91 };
92
93 int sc_main (int argc, char* argv[]) {
94 sc_clock clock ("my_clock",1,0.5);
95
96 signal_bind object("SIGNAL_BIND");
97 object.clock (clock.signal());
98 sc_trace_file *wf = sc_create_vcd_trace_file("sc_start");
99 sc_trace(wf, object.clock, "clock");
100 sc_trace(wf, object.reset, "reset");
101 sc_trace(wf, object.data, "data");
102 sc_trace(wf, object.inv, "inv");
103 sc_trace(wf, object.out, "out");
104 sc_start(0); // First time called will init schedular
105 sc_start(1); // Increment simulation by 1 time unit
106 sc_start(); // Run the simulation till sc_stop is encountered
107 // sc_start() is terminated and return to next startment after
108 // encountering sc_stop()
109 cout<<"Closing VCD File"<<endl;
110 sc_close_vcd_trace_file(wf);
111 return 0;// Terminate simulation
112 }
You could download file sc_start.cpp here
|