UVM入门与进阶6

一、TLM2.0

与TLM1.0相比,

二、同步通信元件

uvm_event, uvm_event_pool, uvm_event_callback

 1 class edata extends uvm_object;
 2   int data;
 3   `uvm_object_utils(edata)
 4  5 endclass
 6 
 7 class ecb extends uvm_event_callbacks;
 8   `uvm_object_utils(ecb)
 9 10   function bit pre_trigger(uvm_event e, uvm_object data = null);
11     `uvm_info("EPRETRIG", $sformatf("before trigger event %s", e.get_name()), UVM_LOW)
12     return 0;
13   endfunction
14   function bit post_trigger(uvm_event e, uvm_object data = null);
15     `uvm_info("EPOSTRIG", $sformatf("after trigger event %s", e.get_name()), UVM_LOW)
16   endfunction
17 endclass
18 
19 class comp1 extends uvm_component;
20   uvm_event e1;
21 22   function void build_phase(uvm_phase phase);
23     super.build_phase(phase);
24     e1 =uvm_event_pool::get_global("e1"); //在uvm_event_pool中寻找是否有e1,如果有直接调用,如果没有,自动创建e1的实例
25   endfunction
26   task run_phase(uvm_phase phase);
27     edata d = new();
28     ecb cb = new();
29     d.data = 100;
30     #10ns;
31     e1.add_callback(cb);
32     e1.trigger(d);
33     `uvm_info("ETRIG",$sformatf("trigger sync event is %t ps", $time),UVM_LOW)
34   endtask
35 endclass 
36 class comp2 extends uvm_component;
37   uvm_event e1;
38   uvm_component_utils(comp2);
39 40   function void build_phase(uvm_phase phase);
41     super.build_phase(phase);
42     e1 =uvm_event_pool::get_global("e1"); //在uvm_event_pool中寻找是否有e1,如果有直接调用,如果没有,自动创建e1的实例
43   endfunction
44   task run_phase(uvm_phase phase);
45     uvm_object tmp;
46     edata d;
47     `uvm_info("ESYNC",$sformatf("wait sync event at %t ps", $time), UVM_LOW)
48     e1.wait_trigger_data(tmp);
49     void($cast(d,tmp));
50     `uvm_info("ESYNC",$sformatf("get data %0d after sync at %t ps", $time), UVM_LOW)
51   endtask
52 endclass 
53 
54 class env1 extends uvm_env;
55   comp1 c1;
56   comp2 c2;
57   `uvm_component_utils(env);
58 59 
60 endclass

uvm_event与event相比,有几个重要特性:

 

uvm_barrier

对多个组件进行同步协调,与uvm_event_pool类似,存放于uvm_barrier_pool

class comp1 extends uvm_compoent;
  uvm_barrier b1;
  `uvm_component_utils(comp1);
  …
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    b1 = uvm_barrier_pool::get_global("b1");
  endfunction
  task run_phase(uvm_phase phase);
    #10ns;
    `uvm_info("BSYNC",$sformatf("c1 wait for b1 at %0t ps", $time), UVM_LOW)
    b1.wait_for();
    `uvm_info("BSYNC",$sformatf("c1 is activated at %0t ps", $time), UVM_LOW)
  endtask
endclass
class comp2 extends uvm_compoent;
  uvm_barrier b1;
  `uvm_component_utils(comp2);
  …
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    b1 = uvm_barrier_pool::get_global("b1");
  endfunction
  task run_phase(uvm_phase phase);
    #20ns;
    `uvm_info("BSYNC",$sformatf("c2 wait for b1 at %0t ps", $time), UVM_LOW)
    b1.wait_for();
    `uvm_info("BSYNC",$sformatf("c2 wait for b1 at %0t ps", $time), UVM_LOW)
  endtask
endclass

class env1 extends uvm_env;
  comp1 c1;
  comp2 c2;
  uvm_barrier b1;
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    c1 = comp1::type_id::create("c1",this);
    c2 = comp2::type_id::create("c2",this);
    b1 = uvm_barrirer_pool::get_global("b1");
  endfunction
  task run_phase(uvm_phase phase);
    b1.set_threshold(3);
    `uvm_info("BSYNC", $sformatf("env set  b1 threshold %d at %0t ps", b1.get_threshold(), $time), UVM_LOW)
    #50ns;
     b1.set_threshold(2);  
    `uvm_info("BSYNC", $sformatf("env set  b1 threshold %d at %0t ps", b1.get_threshold(), $time), UVM_LOW)
  endtask 
endclass

 

uvm_callback

 

posted on 2021-08-11 09:13  薛定谔's猫  阅读(143)  评论(0)    收藏  举报

导航