其他分享
首页 > 其他分享> > TLM通信示例16:connecting the same analysis port to multiple analysis imp ports of multiple components.

TLM通信示例16:connecting the same analysis port to multiple analysis imp ports of multiple components.

作者:互联网

此例显示将同一analysis port连接到多个组件的多个analysis imp port。

TesetBench 组件

——————————————————————- 
Name                              Type 
——————————————————————- 
uvm_test_top                  basic_test 
env                                environment 
comp_a                     component_a 
analysis_port        uvm_analysis_port 
comp_b                     component_b 
analysis_imp_a     uvm_analysis_imp_port_ba 
analysis_imp_b     uvm_analysis_imp_port_bb 
comp_c                     component_c 
analysis_imp_a     uvm_analysis_imp_port_ca 
analysis_imp_b     uvm_analysis_imp_port_cb
——————————————————————-

在 comp_a 中实现analysis port

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

  //---------------------------------------
  // run_phase 
  //---------------------------------------
  virtual task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    
    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(" Before calling port write method"),UVM_LOW)
    analysis_port.write(trans);
    `uvm_info(get_type_name(),$sformatf(" After  calling port write method"),UVM_LOW)
    
    phase.drop_objection(this);
  endtask : run_phase

endclass : component_a

在 comp_b 中实现analysis imp_port

//Step-1. Define analysis imp ports
`uvm_analysis_imp_decl(_port_ba)
`uvm_analysis_imp_decl(_port_bb)

class component_b extends uvm_component;
  
  transaction trans;
  //Step-2. Declare the analysis imp ports
  uvm_analysis_imp_port_ba #(transaction,component_b) analysis_imp_a;  
  uvm_analysis_imp_port_bb #(transaction,component_b) analysis_imp_b; 
  
  `uvm_component_utils(component_b)
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
    //Step-3. Create the analysis imp ports
    analysis_imp_a = new("analysis_imp_a", this);
    analysis_imp_b = new("analysis_imp_b", this);
  endfunction : new
  
  //---------------------------------------
  // Analysis port write method
  //---------------------------------------
  //Step-4. Implement the write method write_port_ba
  virtual function void write_port_ba(transaction trans);
    `uvm_info(get_type_name(),$sformatf(" Inside write_port_ba method. Recived trans On Analysis Imp Port"),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)
  endfunction 
  
  //---------------------------------------
  // Analysis port write method
  //---------------------------------------
  //Step-4. Implement the write method write_port_bb
  virtual function void write_port_bb(transaction trans);
    `uvm_info(get_type_name(),$sformatf(" Inside write_port_bb method. Recived trans On Analysis Imp Port"),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)
  endfunction 
  
endclass : component_b

在 comp_c 中实现analysis imp_port 

 

`uvm_analysis_imp_decl(_port_ca)
`uvm_analysis_imp_decl(_port_cb)

class component_c extends uvm_component;
  
  transaction trans;
  uvm_analysis_imp_port_ca #(transaction,component_c) analysis_imp_a;  
  uvm_analysis_imp_port_cb #(transaction,component_c) analysis_imp_b; 
  
  `uvm_component_utils(component_c)
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
    analysis_imp_a = new("analysis_imp_a", this);
    analysis_imp_b = new("analysis_imp_b", this);
  endfunction : new
  
  //---------------------------------------
  // Analysis port write method
  //---------------------------------------
  virtual function void write_port_ca(transaction trans);
    `uvm_info(get_type_name(),$sformatf(" Inside write_port_ca method. Recived trans On Analysis Imp Port"),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)
  endfunction 
  
  //---------------------------------------
  // Analysis port write method
  //---------------------------------------
  virtual function void write_port_cb(transaction trans);
    `uvm_info(get_type_name(),$sformatf(" Inside write_port_cb method. Recived trans On Analysis Imp Port"),UVM_LOW)
    `uvm_info(get_type_name(),$sformatf(" Printing trans, \n %s",trans.sprint()),UVM_LOW)
  endfunction 
  
endclass : component_c

在 env 中连接analysis port 和analysis imp_ports

`include "transaction.sv"
`include "component_a.sv"
`include "component_b.sv"
`include "component_c.sv"

class environment extends uvm_env;
  
  //---------------------------------------
  // Components Instantiation
  //---------------------------------------
  component_a comp_a;
  component_b comp_b;
  component_c comp_c;  
  
  `uvm_component_utils(environment)
  
  //--------------------------------------- 
  // Constructor
  //---------------------------------------
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction : new

  //---------------------------------------
  // build_phase - Create the components
  //---------------------------------------
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);

    comp_a = component_a::type_id::create("comp_a", this);
    comp_b = component_b::type_id::create("comp_b", this);
    comp_c = component_c::type_id::create("comp_c", this);
  endfunction : build_phase
  
  //---------------------------------------
  // Connect_phase 
  //---------------------------------------
  function void connect_phase(uvm_phase phase);
    comp_a.analysis_port.connect(comp_b.analysis_imp_a);
    comp_a.analysis_port.connect(comp_b.analysis_imp_b);
    comp_a.analysis_port.connect(comp_c.analysis_imp_a);
    comp_a.analysis_port.connect(comp_c.analysis_imp_b);
  endfunction : connect_phase
endclass : environment

仿真结果:

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
analysis_port uvm_analysis_port - @367
comp_b component_b - @377
analysis_imp_a uvm_analysis_imp_port_ba - @386
analysis_imp_b uvm_analysis_imp_port_bb - @396
comp_c component_c - @406
analysis_imp_a uvm_analysis_imp_port_ca - @415
analysis_imp_b uvm_analysis_imp_port_cb - @425
-----------------------------------------------------------
UVM_INFO component_a.sv(29) @ 0: uvm_test_top.env.comp_a [component_a] tranaction randomized
UVM_INFO component_a.sv(30) @ 0: uvm_test_top.env.comp_a [component_a] Printing trans,
---------------------------------
Name Type Size Value
---------------------------------
trans transaction - @443
addr integral 4 'hf
wr_rd integral 1 'h0
wdata integral 8 'he9
---------------------------------

UVM_INFO component_a.sv(32) @ 0: uvm_test_top.env.comp_a [component_a] Before calling port write method
UVM_INFO component_b.sv(29) @ 0: uvm_test_top.env.comp_b [component_b] Inside write_port_ba method. Recived trans On Analysis Imp Port
UVM_INFO component_b.sv(30) @ 0: uvm_test_top.env.comp_b [component_b] Printing trans,
---------------------------------
Name Type Size Value
---------------------------------
trans transaction - @443
addr integral 4 'hf
wr_rd integral 1 'h0
wdata integral 8 'he9
---------------------------------

UVM_INFO component_b.sv(37) @ 0: uvm_test_top.env.comp_b [component_b] Inside write_port_bb method. Recived trans On Analysis Imp Port
UVM_INFO component_b.sv(38) @ 0: uvm_test_top.env.comp_b [component_b] Printing trans,
---------------------------------
Name Type Size Value
---------------------------------
trans transaction - @443
addr integral 4 'hf
wr_rd integral 1 'h0
wdata integral 8 'he9
---------------------------------

UVM_INFO component_c.sv(29) @ 0: uvm_test_top.env.comp_c [component_c] Inside write_port_ca method. Recived trans On Analysis Imp Port
UVM_INFO component_c.sv(30) @ 0: uvm_test_top.env.comp_c [component_c] Printing trans,
---------------------------------
Name Type Size Value
---------------------------------
trans transaction - @443
addr integral 4 'hf
wr_rd integral 1 'h0
wdata integral 8 'he9
---------------------------------

UVM_INFO component_c.sv(37) @ 0: uvm_test_top.env.comp_c [component_c] Inside write_port_cb method. Recived trans On Analysis Imp Port
UVM_INFO component_c.sv(38) @ 0: uvm_test_top.env.comp_c [component_c] Printing trans,
---------------------------------
Name Type Size Value
---------------------------------
trans transaction - @443
addr integral 4 'hf
wr_rd integral 1 'h0
wdata integral 8 'he9
---------------------------------

UVM_INFO component_a.sv(34) @ 0: uvm_test_top.env.comp_a [component_a] After calling port write method
UVM_INFO /apps/vcsmx/vcs/S-2021.09//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 0: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/S-2021.09//etc/uvm-1.2/src/base/uvm_report_server.svh(904) @ 0: reporter [UVM/REPORT/SERVER]

因为都是在@0时刻,所以各个analysis imp port 是同时收到广播的。

标签:multiple,示例,component,analysis,imp,uvm,trans,port
来源: https://www.cnblogs.com/fuqiangblog/p/16683421.html