SystemC -- A notion of time 1、simulation kernel用sc_time数据类型来跟踪仿真时间指定delay和timeouts。sc_time是用一个64bit的无符号整型数来表示。SC_SECseconds 10^0 秒SC_MSmilliseconds 10^-3 毫秒SC_USmicroseconds 10^-6 微秒SC_NSnanoseconds 10^-9 纳秒SC_PSpicoseconds 10^-12 皮秒SC_FSfemtoseconds 10^-15 飞秒sc_time_stamp()用来获取当前的仿真时间返回值是一个sc_time对象。sc_simulation_time()returns time as a double in the currentdefault time unit.Info: (I804) /IEEE_Std_1666/deprecated: sc_simulation_time() is deprecated use sc_time_stamp()To establish the default time unit, call sc_set_default_time_unit(). you must call this routine prior to call time specifications and prior tothe initiation of sc_start().sc_start()启动仿真括号中可带参数指定的时间流逝后仿真停止。If you provide a time argument, simulation stops after the specified simulation time has elapsed.#include stdafx.h #include systemc.h #include iostream using namespace std; SC_MODULE(My_Module) { SC_CTOR(My_Module) { SC_THREAD(mytime); } void mytime(); }; void My_Module::mytime() { int a 5,b3,c; c a b; wait(5,SC_NS); coutThe time is now sc_time_stamp()!endl; sc_time t_delay(2,SC_MS); t_delay * 2; coutDelaying t_delayendl; wait(t_delay); coutThe time is now sc_time_stamp()!endl; } int sc_main(int sc_argc,char * argv[]) { My_Module md(); sc_time m_time(5,SC_SEC); //sc_start(); //sc_start(10.0,SC_MS); //limit sim to 10 ms sc_start(m_time);//start sim and maximum simulation time system(pause); return 0; }输出#include stdafx.h #include systemc.h #include iostream using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_set_time_resolution(1.0,SC_MS); sc_start(7200,SC_SEC);//limit simulation to 2 hours(or 7200 secs) sc_time st sc_time_stamp();//获取当前仿真时刻和时间单位 double t sc_simulation_time();//仅仅获取当前仿真时刻而无时间单位 //sc_cycle、sc_initialize用于完成周期级仿真。 unsigned hours int(t/3600.0); t - 3600*hours; unsigned minutes int(t/60.0); t - 60.0*minutes; double seconds t; cout hours hours minutes minutes seconds seconds endl; //system(pause); return 0; }输出上面时间输出错误没有考虑到time units。sc_report_handler::set_actions(/IEEE_Std_1666/deprecated, SC_DO_NOTHING); 加入该句可以关闭有关deprecated 的warnings。#include systemc.h #include iostream #include math.h using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_report_handler::set_actions(/IEEE_Std_1666/deprecated, SC_DO_NOTHING); cout my time resolution is sc_get_time_resolution()endl;//ps 10^-12s double t1 sc_get_time_resolution().to_seconds(); cout my time resolution is t1s.endl; sc_start(7296,SC_SEC); sc_time t sc_time_stamp(); coutCurrent time is tendl; double t2 sc_simulation_time();//ns? long long index pow((double)10,(double)9); double ts t2/index; // ns -- s unsigned hours (int)(ts/3600.0); ts - 3600 * hours; unsigned minutes (int)(ts/60.0); ts - 60 * minutes; double seconds ts; cout Time is hours hours minutes minutes seconds seconds endl; system(pause); return 0; }输出#include systemc.h #include iostream using namespace std; int sc_main(int sc_argc,char * argv[]) { sc_report_handler::set_actions(/IEEE_Std_1666/deprecated, SC_DO_NOTHING); /* for example,if the specified time resolution is 100ps, then coding 20ps will result in an effective value of 0 ps */ sc_set_time_resolution(1,SC_NS); sc_set_default_time_unit(1,SC_MS); //establish the default time unit cout my time resolution is sc_get_time_resolution()endl;//ns 10^-9s double t1 sc_get_time_resolution().to_seconds(); cout my time resolution is t1s.endl; sc_start(7296,SC_SEC); sc_time t sc_time_stamp(); coutCurrent time is tendl; double t2 sc_simulation_time();//default time unit double ts t2/1000; // ms -- s unsigned hours (int)(ts/3600.0); ts - 3600 * hours; unsigned minutes (int)(ts/60.0); ts - 60 * minutes; double seconds ts; cout Time is hours hours minutes minutes seconds seconds endl; system(pause); return 0; }输出