1#include <systemc> 2#include <cstring> 3using namespace sc_core; 4using namespace sc_dt; 5using std::cout; 6using std::endl; 7 8// 2) sc_clock - start_time and posedge_first (in addition to period and duty_cycle) 9 10SC_MODULE(M) 11{ 12 SC_CTOR(M) 13 { 14 SC_THREAD(T); 15 } 16 void T() 17 { 18 wait(10, SC_NS); 19 sc_stop(); 20 } 21}; 22 23struct Top: sc_module 24{ 25 sc_clock clk; 26 M *m; 27 Top(sc_module_name) 28 : clk("clk", 20, SC_NS, 0.75, 5, SC_NS, false) 29 { 30 m = new M("m"); 31 sc_assert(strcmp(clk.name(), "top.clk") == 0); 32 sc_assert(strcmp(clk.kind(), "sc_clock") == 0); 33 sc_assert(clk.period() == sc_time(20, SC_NS)); 34 sc_assert(clk.duty_cycle() == 0.75); 35 sc_assert(clk.start_time() == sc_time(5, SC_NS)); 36 sc_assert(clk.posedge_first() == false); 37 } 38}; 39 40int sc_main(int argc, char* argv[]) 41{ 42 cout << "Should be silent..." << endl; 43 44 Top top("top"); 45 sc_start(); 46 47 cout << endl << "Success" << endl; 48 return 0; 49} 50