Time In SystemC Part I

Print

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.

We will be covering following topics

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.
Enum types that denote various time units are as below

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.
The function sc_get_time_resolution shall return the time resolution.

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.

Example : sc_time

  1 #include

  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 }

Simulation Output : sc_time

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

 Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

 

Last Updated ( Tuesday, 29 March 2022 00:47 )