quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

Difference between a HDL and other programming language is notion of time and concurrancy. In this chapter we will see the time data type in detail.

   

space.gif

We will be covering following topics

   

space.gif

  • sc_time
  • sc_start()
  • sc_time_stamp()
  • wait(sc_time)
  • sc_simulation_time()
  • sc_event
   

space.gif

  ../images/main/bulllet_4dots_orange.gif sc_time

sc_time is special data type which is used to represent simulation time and time intervals, including delays and time-outs. An object of class sc_time is constructed from a double and an sc_time_unit. Time shall be represented internally as an unsigned integer of at least 64 bits. Like any other data type in SystemC, sc_time also allows arthmetic operations.

   

space.gif

Enum types that denote various time units are as below

   

space.gif

  • SC_FS = 0
  • SC_PS = 1
  • SC_NS = 2
  • SC_US = 3
  • SC_MS = 4
  • SC_SEC= 5
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Time Resolution

Time shall be represented internally as an integer multiple of the time resolution. The default time resolution is 1 picosecond. The time resolution can only be changed by calling the function sc_set_time_resolution. This function shall only be called during elaboration, shall not be called more than once, and shall not be called after constructing an object of type sc_time with a non-zero time value.

   

space.gif

The function sc_get_time_resolution shall return the time resolution.

   

space.gif

  ../images/main/bullet_star_pink.gif SC_ZERO_TIME

SC_ZERO_TIME represents 0 time delay. It is good practice to use this constant whenever writing a time value of zero, for example, when creating a delta notification or a delta time-out.

   

space.gif

  ../images/main/bullet_star_pink.gif Example : sc_time
   

space.gif


  1 #include <systemc.h>
  2 
  3 int sc_main (int argc, char* argv[]) {
  4   // sc_set_time_resol... should be called before sc_time
  5   // variable declration
  6   sc_set_time_resolution(1,SC_PS);
  7   // Declare the sc_time variables
  8   sc_time             t1(10,SC_NS);
  9   sc_time             t2(5,SC_PS);
 10   sc_time             t3,t4(1,SC_PS),t5(1,SC_PS);
 11   // Print all the variables
 12   cout <<"Value of t1 "<< t1.to_string() << endl;
 13   cout <<"Value of t2 "<< t2.to_string() << endl;
 14   cout <<"Value of t3 "<< t3.to_string() << endl;
 15   cout <<"Value of t4 "<< t4.to_string() << endl;
 16   cout <<"Value of t5 "<< t5.to_string() << endl;
 17   // Start the sim
 18   sc_start(0);
 19   sc_start(1);
 20   // Get the current time
 21   t3 = sc_time_stamp();
 22   cout <<"Value of t3 "<< t3.to_string() << endl;
 23   // Run for some more time
 24   sc_start(20);
 25   // Get the current time
 26   t4 = sc_time_stamp();
 27   // Print the variables for new time
 28   cout <<"Value of t4 "<< t4.to_string() << endl;
 29   // This is how you do arth operation
 30   t5 = t4 - t3;
 31   cout <<"Value of t5 "<< t5.to_string() << endl;
 32   // This is how we do compare operation
 33   if (t5 > t2) {
 34     cout <<" t5 is greated then t2" << endl;
 35   } else {
 36     cout <<" t2 is greated then t5" << endl;
 37   }
 38   return 1;
 39 }
You could download file sc_time.cpp here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation Output : sc_time
   

space.gif

 Value of t1 10 ns
 Value of t2 5 ps
 Value of t3 0 s
 Value of t4 1 ps
 Value of t5 1 ps
 Value of t3 1 ns
 Value of t4 21 ns
 Value of t5 20 ns
  t5 is greated then t2
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com