1、time resolution is a global variable that is used by the simulation kernel and all objects of sc_time, changes to time resolution are restricted.
sc_set_time_resolution() : may be used tochange time resolution once andonly once in a simulation.
The change must occur before both creating objects of sc_time and starting the simulation. The time resolution set methos requires two parameters:
the first argument is a double that must be a positive power of ten,and the second argument is ansc_time_unit.
sc_get_time_resolution() : get time resolution, default is ps.
sc_set_default_time_unit(1,SC_MS); // establish the default time unit
sc_simulation_time() returns time as a double in the current default time unit.
#include <systemc.h>
#include <iostream>
using namespace std;
int sc_main(int sc_argc,char * argv[])
{
cout<<"=== my time resolution is "<<sc_get_time_resolution()<<endl;
double t1 = sc_get_time_resolution().to_seconds();
cout<<"=== my time resolution is "<<t1<<"s."<<endl;
sc_time mytime(5,SC_MS);
sc_start(mytime);
cout<<"Current time is "<<sc_time_stamp()<<endl;
system("pause");
return 0;
}
输出:

In SystemC, there are three alternatives to convert 'sc_time' to a'double' value. Choose the one fitting your needs:
sc_time_stamp().to_double();
sc_time_stamp().to_seconds();
sc_time_stamp().to_default_time_units();
#include <systemc.h>
#include <iostream>
using namespace std;
int sc_main(int sc_argc,char * argv[])
{
sc_set_time_resolution(10,SC_NS); //before use sc_time,sc_get_time_resolution have used sc_time
cout<<"=== my time resolution is "<<sc_get_time_resolution()<<endl;
double t1 = sc_get_time_resolution().to_seconds();
cout<<"=== my time resolution is "<<t1<<"s."<<endl;
sc_time mytime(5,SC_MS);
sc_start(mytime);
cout<<"Current time is "<<sc_time_stamp()<<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);
sc_set_time_resolution(1,SC_SEC);
cout<<"=== my time resolution is "<<sc_get_time_resolution()<<endl;
double t1 = sc_get_time_resolution().to_seconds();
cout<<"=== my time resolution is "<<t1<<"s."<<endl;
sc_start(7296,SC_SEC);
sc_time t = sc_time_stamp();
cout<<"Current time is "<<t<<endl;
double t2 = sc_simulation_time();
unsigned hours = (int)(t2/3600.0);
t2 -= 3600 * hours;
unsigned minutes = (int)(t2/60.0);
t2 -= 60 * minutes;
double seconds = t2;
cout <<"Time is "<< hours <<" hours "
<< minutes << " minutes "
<< seconds << " seconds "
<< endl;
system("pause");
return 0;
}
输出:
Features in libraries are deprecated because they are replaced by something either more robust, more powerfully featured, more secure,
or generally better. It is also the case that many library systems, when migrating a major version number, remove deprecated features
(I'm not sure about the SystemC policy on this). For both reasons, you should never rely on deprecated features.
I would like to say that you can turn off this deprecated feature by placing the following statement as the first line in the sc_main() function:
sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING);
#include "systemc.h"
void my_sc_set_time_resolution( double v, sc_time_unit tu )
{
static bool already_set = false;
if ( already_set )
return;
already_set = true;
sc_set_time_resolution( v,tu );
}
int sc_main (int argc, char *argv[] )
{
/* Error: called twice
sc_set_time_resolution( 10, SC_FS ); // OK
sc_set_time_resolution( 1, SC_FS ); // error: 2nd call
sc_time how_long (15, SC_MS);
sc_start(how_long);
*/
/* Error: called after first sc_time has been constructed
sc_time how_long (15, SC_MS);
sc_set_time_resolution( 10, SC_FS ); //
sc_start(how_long);
*/
/* Error: called after elaboration
sc_initialize();
sc_set_time_resolution( 10, SC_FS ); //
sc_time how_long (15, SC_MS);
sc_start(how_long);
*/
/* OK */
sc_set_time_resolution( 10, SC_FS ); // OK
sc_time how_long (15, SC_MS);
sc_start(how_long);
return 0;
}