test205.cpp revision 12855:588919e0e4aa
1#include <systemc> 2using namespace sc_core; 3using namespace sc_dt; 4using sc_core::wait; 5using std::cout; 6using std::endl; 7 8// 5) wait( int ) for SC_THREAD, primitives and global 9 10void global() 11{ 12 wait(); 13 sc_assert(sc_time_stamp() == sc_time(0, SC_NS)); 14 wait(3); 15 sc_assert(sc_time_stamp() == sc_time(3, SC_NS)); 16} 17 18struct Prim: sc_prim_channel 19{ 20 void method() 21 { 22 wait(); 23 sc_assert(sc_time_stamp() == sc_time(4, SC_NS)); 24 wait(3); 25 sc_assert(sc_time_stamp() == sc_time(7, SC_NS)); 26 } 27}; 28 29SC_MODULE(M) 30{ 31 sc_in_clk clk; 32 Prim prim; 33 SC_CTOR(M) 34 { 35 SC_THREAD(T); 36 sensitive << clk.pos(); 37 } 38 void T() 39 { 40 global(); 41 prim.method(); 42 wait(); 43 sc_assert(sc_time_stamp() == sc_time(8, SC_NS)); 44 wait(3); 45 sc_assert(sc_time_stamp() == sc_time(11, SC_NS)); 46 sc_stop(); 47 } 48}; 49 50struct Top: sc_module 51{ 52 M *m; 53 sc_clock clk; 54 Top(sc_module_name) 55 { 56 m = new M("m"); 57 m->clk.bind(clk); 58 } 59}; 60 61int sc_main(int argc, char* argv[]) 62{ 63 cout << "Should be silent..." << endl; 64 Top top("top"); 65 sc_start(); 66 67 cout << endl << "Success" << endl; 68 return 0; 69} 70