Monday, 23 June 2014

How to insert delays in a TB - part 2

This is an update to previous post. If you want to wait for no of clocks in TB/sequence rather than giving delay, which can be done by events as shown below, but not recommended. Recommended solution is given below that.

we can use the same uvm_event.
  we can get the event with the help of uvm_event_pool, the sharing of the event happens with respect to the name with which you have set your clock event.
Please find the code snippet below.
example:
class my_sequence extends uvm_sequence;
//factory registration 
//other stuff
 
  uvm_event_pool my_event_pool;
  uvm_event clk_event;
  .
  .
  .
  clk_event = new();
  my_event_pool =  uvm_event_pool::get_global_pool();
  `uvm_info(get_full_name(),my_event_pool.get_type_name(),UVM_HIGH);
 
  task body();
      clk_event = my_event_pool.get("CLOCK EVENT");//this clock event will be triggered and set in the event pool with the same name in some other place where you have the access to the virtual interface handle.
      .
      .
      .
      clk_event.wait_trigger;
      .
      .
  endtask
endclass
 
 
You can use the same uvm_event which you have mentioned .

You can get the event with the help of uvm_event_pool, the sharing of 
the event happens with respect to the name with which you have set your 
clock event.

Please find the code snippet below.

example:
class my_sequence extends uvm_sequence;
//factory registration 
//other stuff
 
  uvm_event_pool my_event_pool;
  uvm_event clk_event;
  .
  .
  .
  clk_event = new();
  my_event_pool =  uvm_event_pool::get_global_pool();
  `uvm_info(get_full_name(),my_event_pool.get_type_name(),UVM_HIGH);
 
  task body();
      clk_event = my_event_pool.get("CLOCK EVENT");//this clock event will be triggered and set in the event pool with the same name in some other place where you have the access to the virtual interface handle.
      .
      .
      .
      clk_event.wait_trigger;
      .
      .
  endtask
endclass
 
 
 
Better solution is: 


Using a uvm_event_pool is not recommended as it results in an environment that is very co-dependent on other components and isn't very portable.
Our recommendation it to create an agent which can be used for time/clock advancement. It would have an interface connected to a system clock and have a sequence which would complete when a specified number of clocks have passed.
This technique is recommended since it removes all timing from the HVL testbench and is portable to both simulation and emulation.

-courtesy cgales
 

Thursday, 19 June 2014

How to insert delays in a TB - part 1

It is not recommended to insert hard coded delays in your TB. If TB is a part of SOC, there always exists an ambiguity on which delay simulator takes, since there are many blocks which uses different timescales.

As mentioned below, a global task can be created and used it all through the TB to insert delays. Problem of having different timescale units in different files can be solved by normalizing the amount of delay you want before applying it.

can go through below example, to understand it.
Go through below link for complete information.

http://tenthousandfailures.com/blog/2014/4/6/the-delayps-task


// `timescale 1ps/1ps
 `timescale 1fs/1fs

 package shared;

 class helper;

     static task delay_ps(real delay);
         real t0, t1;
         t0 = $realtime;
        
         $printtimescale;
         $display("delay_ps(%g)", delay);        
         #(delay*1ps);

         t1 = $realtime;
         if (t0 == t1) $error("%m timescale not precise enough"); 
  endtask // delay_ps

 endclass // helper   
    
 endpackage // shared

 `timescale 1ps/1ps
 // `timescale 1fs/1fs
    
 module tb ();

     task print_time();
         $display("\n%f is tb time\n", $realtime);
     endtask
    
     initial begin

         $display("\n");
         $printtimescale;
         $display("\n");

         print_time();
         #2ps; $display("delay 2ps"); print_time();
         shared::helper::delay_ps(2); print_time();
shared::helper::delay_ps(2ps/1ps); print_time();
         shared::helper::delay_ps(0.002ns/1ps); print_time();
         shared::helper::delay_ps(0.000002us/1ps); print_time();
         #2fs; $display("delay 2fs"); print_time();
            
         $finish();
        
     end
    
 endmodule