DIFFERENCE:
- wait() sử dụng cho 1 thread, next_trigger() sử dụng cho 1 method
- Không giống wait(), việc dùng next_trigger() không suspend 1 process
EXAMPLE:
#include <systemc.h>
SC_MODULE(next_trigger_and_wait) {
sc_in<bool> clock;
sc_event e1, e2;
int cnt,cnt0;
void do_wait_thread() {
while (1) {
cout << "[ THREAD] "<<sc_time_stamp().to_string()<<endl;
switch (cnt0) {
case 0: cout << " @" << sc_time_stamp() << " Default trigger clk triggered" << endl;
wait(e1);
break;
case 1: cout << " @" << sc_time_stamp() << " Event e1 triggered" << endl;
wait(10, SC_NS);
break;
case 2: cout << " @" << sc_time_stamp() << " Event e1 occured or time 10ns passed" << endl;
wait(e1 | e2);
break;
case 3: cout << " @" << sc_time_stamp() << " Event e1 or e2 triggered" << endl;
break;
default:cout << " @" << sc_time_stamp() << " Default trigger clk triggered" << endl;
cnt0 = 0;
break;
}
cnt0++; cout << " THREAD : count ++" << sc_time_stamp().to_string()<<endl;
}
}
void do_next_trigger_method() {
cout << "[ METHOD] " << sc_time_stamp().to_string()<<endl;
switch (cnt) {
case 0: cout << " @" << sc_time_stamp() << " Default trigger clk triggered" << endl;
next_trigger(e1);
break;
case 1: cout << " @" << sc_time_stamp() << " Event e1 triggered" << endl;
next_trigger(10, SC_NS);
break;
case 2: cout << " @" << sc_time_stamp() << " Event e1 occured or time 10ns passed" << endl;
next_trigger(e1 | e2);
break;
case 3: cout << " @" << sc_time_stamp() << " Event e1 or e2 triggered" << endl;
break;
default:cout << " @" << sc_time_stamp() << " Default trigger clk triggered" << endl;
cnt = 0;
break;
}
cnt++; cout << " METHOD : count ++" << sc_time_stamp().to_string()<<endl;
}
void event_thread() {
while (true) {
wait(2);
// Trigger event e1
cout << "@" << sc_time_stamp() << " Triggering e1" << endl;
e1.notify();
wait(20);
cout << "@" << sc_time_stamp() << " Triggering e2" << endl;
e2.notify();
// Wait for 2 posedge of clocks
wait(2);
cout << "@" << sc_time_stamp() << " Terminating simulation" << endl;
sc_stop(); // sc_stop triggers end of simulation
}
}
void clock_thread() {
cout << "clock positive at : " << sc_time_stamp().to_string()<<endl;
}
SC_CTOR(next_trigger_and_wait) {
cnt = 0; cnt0 = 0;
SC_THREAD(do_wait_thread);
SC_METHOD(clock_thread);
sensitive << clock.pos();
SC_METHOD(do_next_trigger_method);
SC_CTHREAD(event_thread, clock.pos());
}
};
int sc_main(int argc, char* argv[]) {
sc_clock clock("my_clock", 1, 0.5);
next_trigger_and_wait object("wait");
object.clock(clock);
sc_start(); // Run the simulation till sc_stop is encountered
return 0;// Terminate simulation
}
OUTPUT:
SystemC 2.3.2-Accellera --- Nov 27 2018 17:08:10
Copyright (c) 1996-2017 by all Contributors,
ALL RIGHTS RESERVED
Info: (I804) /IEEE_Std_1666/deprecated:
sc_clock(const char*, double, double, double, bool)
is deprecated use a form that includes sc_time or
sc_time_unit
clock positive at : 0 s
[ METHOD] 0 s
@0 s Default trigger clk triggered
METHOD : count ++0 s
[ THREAD] 0 s
@0 s Default trigger clk triggered
clock positive at : 0 s
clock positive at : 1 ns
clock positive at : 2 ns
@2 ns Triggering e1
[ METHOD] 2 ns
@2 ns Event e1 triggered
METHOD : count ++2 ns
THREAD : count ++2 ns
[ THREAD] 2 ns
@2 ns Event e1 triggered
clock positive at : 3 ns
clock positive at : 4 ns
clock positive at : 5 ns
clock positive at : 6 ns
clock positive at : 7 ns
clock positive at : 8 ns
clock positive at : 9 ns
clock positive at : 10 ns
clock positive at : 11 ns
[ METHOD] 12 ns
@12 ns Event e1 occured or time 10ns passed
METHOD : count ++12 ns
THREAD : count ++12 ns
[ THREAD] 12 ns
@12 ns Event e1 occured or time 10ns passed
clock positive at : 12 ns
clock positive at : 13 ns
clock positive at : 14 ns
clock positive at : 15 ns
clock positive at : 16 ns
clock positive at : 17 ns
clock positive at : 18 ns
clock positive at : 19 ns
clock positive at : 20 ns
clock positive at : 21 ns
clock positive at : 22 ns
@22 ns Triggering e2
[ METHOD] 22 ns
@22 ns Event e1 or e2 triggered
METHOD : count ++22 ns
THREAD : count ++22 ns
[ THREAD] 22 ns
@22 ns Event e1 or e2 triggered
THREAD : count ++22 ns
[ THREAD] 22 ns
@22 ns Default trigger clk triggered
THREAD : count ++22 ns
[ THREAD] 22 ns
@22 ns Event e1 triggered
clock positive at : 23 ns
clock positive at : 24 ns
@24 ns Terminating simulation
Analytics output log:
Khi 1 process gặp next_trigger(args)/wait(args) function, method/thread đó sẽ bị lock bởi điều kiện trong args. NHƯNG,
[+] Khi do_wait_thread() được gọi, cnt0 = 0 nên “Default trigger clk triggered” in ra màn hình, và sau đó, nó gặp wait(e1) và nó sẽ suspend ở đây.
[+] Không giống như wait(), khi do_next_trigger_method() được gọi, cnt = 0 nên “Default trigger clk triggered” in ra màn hình, và sau đó, nó gặp next_trigger(e1) nhưng nó sẽ KHÔNG suspend ở đây. Nó sẽ chạy đến hết do_next_trigger_method() function. “METHOD : count ++0 s “ in ra màn hình.
Free Source C WE ARE DEVELOPER