Tutorials

Learn More

uvm_analysis_port, uvm_subscriber and multiple analysis imp on the same component
`include "uvm_macros.svh"
import uvm_pkg::*;
`uvm_analysis_imp_decl (_PORT_A)
`uvm_analysis_imp_decl (_PORT_B)

`include "seq_item.sv"

class producer extends uvm_component;
  seq_item req;
  uvm_analysis_port #(seq_item) a_put;
  
  `uvm_component_utils(producer)
  
  function new(string name = "producer", uvm_component parent = null);
    super.new(name, parent);
    a_put = new("a_put", this);
  endfunction
  
  task run_phase(uvm_phase phase);
    super.run_phase(phase);
    
    req = seq_item::type_id::create("req");
    assert(req.randomize());
    `uvm_info(get_type_name(), $sformatf("Send value = %0h", req.value), UVM_NONE);
    a_put.write(req);
  endtask
endclass

class consumer extends uvm_component;
  seq_item req;
  uvm_analysis_imp_PORT_A #(seq_item, consumer) analysis_imp_A;
  uvm_analysis_imp_PORT_B #(seq_item, consumer) analysis_imp_B;
  
  `uvm_component_utils(consumer)
  
  function new(string name = "consumer", uvm_component parent = null);
    super.new(name, parent);
    analysis_imp_A = new("analysis_imp_A", this);
    analysis_imp_B = new("analysis_imp_B", this);
  endfunction
  
  virtual function void write_PORT_A (seq_item req);
    `uvm_info(get_type_name(), $sformatf("Port A: Received value = %0h", req.value), UVM_NONE);
  endfunction
  
  virtual function void write_PORT_B (seq_item req);
    `uvm_info(get_type_name(), $sformatf("Port B: Received value = %0h", req.value), UVM_NONE);
  endfunction
endclass

class subscriber_comp extends uvm_subscriber #(seq_item);
  seq_item req;
  `uvm_component_utils(subscriber_comp)
  
  function new(string name = "subscriber_comp", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  virtual function void write (seq_item t);
    req = t;
    `uvm_info(get_type_name(), $sformatf("Received value = %0h", req.value), UVM_NONE);
  endfunction
endclass

class env extends uvm_env;
  producer pro;
  consumer con;
  subscriber_comp subscr;
  
  `uvm_component_utils(env)
  
  function new(string name = "env", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    pro = producer::type_id::create("pro", this);
    con = consumer::type_id::create("con", this);
    subscr = subscriber_comp::type_id::create("subscr", this);
  endfunction
  
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    pro.a_put.connect(con.analysis_imp_A);
    pro.a_put.connect(con.analysis_imp_B);
    pro.a_put.connect(subscr.analysis_export);
  endfunction
endclass
              
class test extends uvm_test;
  env env_o;
  `uvm_component_utils(test)
  
  function new(string name = "test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    env_o = env::type_id::create("env_o", this);
  endfunction
 
  task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #50;
    phase.drop_objection(this);
  endtask
endclass

module tb_top;
  initial begin
    run_test("test");
  end
endmodule

Output:

UVM_INFO testbench.sv(24) @ 0: uvm_test_top.env_o.pro [producer] Send value = 0
UVM_INFO testbench.sv(43) @ 0: uvm_test_top.env_o.con [consumer] Port A: Received value = 0
UVM_INFO testbench.sv(47) @ 0: uvm_test_top.env_o.con [consumer] Port B: Received value = 0
UVM_INFO testbench.sv(61) @ 0: uvm_test_top.env_o.subscr [subscriber_comp] Received value = 0