ruwan2 Posted June 30, 2014 Report Share Posted June 30, 2014 Hi, I see the below code snippet from an example. I wonder that when sc_time_stamp().to_default_time_units() returns 0. static bool first = true; if (first || sc_time_stamp().to_default_time_units() == 0) { first = false; clock.write(0); } I have found its origin definition: 00161 // conversion functions0016200163 double00164 sc_time::to_default_time_units() const00165 {00166 sc_time_params* time_params = sc_get_curr_simcontext()->m_time_params;00167 return ( sc_dt::uint64_to_double( m_value ) /00168 sc_dt::uint64_to_double( time_params->default_time_unit ) );00169 }00170 I think that if sc_time_stamp().to_default_time_units() returns non-zero, it is equivalent to 1. It returns 0 when m_value is 0. My question is what does m_value is 0 mean? Thanks, Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted June 30, 2014 Report Share Posted June 30, 2014 First of all, all "time units" related functions are deprecated and should not be used. These functions predate the IEEE standard for SystemC. That said, at the beginning of the simulation, sc_time_stamp() is SC_ZERO_TIME (i.e. 0). As a result, the conversion to "default time units" is zero as well. /Philipp Quote Link to comment Share on other sites More sharing options...
ruwan2 Posted June 30, 2014 Author Report Share Posted June 30, 2014 Thank you for your reply. Now, I have the left question on its purpose, see below please. If you think it is out of date, what code would you write? I am new to SystemC now. Please help me on the analysis and an example good style code for this clock generator. void clock_generator() { static bool first = true; if (first || sc_time_stamp().to_default_time_units() == 0) { first = false; clock.write(0); } else { bool nextClockValue = (clock.read() == true) ? false : true; clock.write(nextClockValue); } clock_event.notify(100, SC_NS); } Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted June 30, 2014 Report Share Posted June 30, 2014 I would use the clock generator coming with SystemC by instantiating an sc_clock (see Section 6.7 in IEEE 1666-2011): sc_clock clk( "clk" // name , sc_time(100, SC_NS) // period , 0.5 // duty cycle , sc_time(100, SC_NS) // start time , true ); // start with positive edge I've selected the parameters guessing from your code snippet. In "your" code, the first rising edge seems to occur at 100ns (start time). Play with the values as you need them. You can then bind this clock to any sc_in<bool> port in your system. /Philipp ruwan2 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.