其他分享
首页 > 其他分享> > TLM通信示例10:实现非阻塞can_get方法

TLM通信示例10:实现非阻塞can_get方法

作者:互联网

在调用 trans_in.try_get() 方法之前,comp_b 通过调用 trans_in.can_get() 方法检查 comp_a 状态。

在调用 trans_in.can_get() 时,如果 comp_a 准备好发送事物数据包,则返回 1,否则返回 0。

1.在comp_b中调用try_get方法前,调用can_get()方法检查comp_a状态

class component_b extends uvm_component;
  
  transaction trans;
  uvm_nonblocking_get_port#(transaction) trans_in;  

  `uvm_component_utils(component_b)
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
    trans_in = new("trans_in", this);
  endfunction : new 
  
  //---------------------------------------
  // run_phase 
  //---------------------------------------
  virtual task run_phase(uvm_phase phase);
    phase.raise_objection(this);

    `uvm_info(get_type_name(),$sformatf(" Checking component_a status to get the transaction"),UVM_LOW)
    if(trans_in.can_get) begin //{
    
      `uvm_info(get_type_name(),$sformatf(" component_a can send the transaction"),UVM_LOW)
      `uvm_info(get_type_name(),$sformatf(" Requesting transaction."),UVM_LOW)
      `uvm_info(get_type_name(),$sformatf(" Before calling port get method"),UVM_LOW)
      
      if(trans_in.try_get(trans)) begin //{
        `uvm_info(get_type_name(),$sformatf(" recived transaction from get method"),UVM_LOW)
        `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)
      end //} 
      else begin //{
        `uvm_info(get_type_name(),$sformatf(" Not recived transaction from get method"),UVM_LOW)
      end //}
      
      `uvm_info(get_type_name(),$sformatf(" After  calling port get method"),UVM_LOW)
    
    end //}
    else begin //{
      `uvm_info(get_type_name(),$sformatf(" component_a is not ready to send the transaction"),UVM_LOW)
    end //}
      
    phase.drop_objection(this);
  endtask : run_phase
  
endclass : component_b

2.在comp_a中实现can_get()方法

class component_a extends uvm_component;
  
  uvm_nonblocking_get_imp#(transaction,component_a) trans_out; 
  
  `uvm_component_utils(component_a)
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
    trans_out = new("trans_out", this); 
  endfunction : new

  //---------------------------------------
  // Imp port try_get method
  //---------------------------------------
  virtual function bit try_get(output transaction trans);
    
    `uvm_info(get_type_name(),$sformatf(" Recived transaction imp port get request"),UVM_LOW)
    trans = transaction::type_id::create("trans", this);
    
    void'(trans.randomize());
    `uvm_info(get_type_name(),$sformatf(" tranaction randomized"),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)

    `uvm_info(get_type_name(),$sformatf(" Sendting trans packet"),UVM_LOW)
    
    return 1;
  endfunction   
  
  //---------------------------------------
  // Imp port can_get method
  //---------------------------------------
  virtual function bit can_get();
    `uvm_info(get_type_name(),$sformatf(" component_b requested for status"),UVM_LOW)
    return 0;
  endfunction
endclass : component_a

 

仿真结果:

UVM_INFO @ 0: reporter [RNTST] Running test basic_test...
------------------------------------------------------
Name Type Size Value
------------------------------------------------------
uvm_test_top basic_test - @336
env environment - @349
comp_a component_a - @358
trans_out uvm_nonblocking_get_imp - @367
comp_b component_b - @377
trans_in uvm_nonblocking_get_port - @386
------------------------------------------------------
UVM_INFO component_b.sv(26) @ 0: uvm_test_top.env.comp_b [component_b] Checking component_a status to get the transaction
UVM_INFO component_a.sv(40) @ 0: uvm_test_top.env.comp_a [component_a] component_b requested for status
UVM_INFO component_b.sv(45) @ 0: uvm_test_top.env.comp_b [component_b] component_a is not ready to send the transaction

标签:10,name,get,示例,component,uvm,trans,UVM
来源: https://www.cnblogs.com/fuqiangblog/p/16677857.html