Jump to content

When the method to_default_time_units() returns 0?


ruwan2

Recommended Posts

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 functions
00162
00163 double
00164 sc_time::to_default_time_units() const
00165 {
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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
}
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...