UVM : Config_db() Examples

     Hello , welcome back. In this blog spot we will try some example on     config_db().

    config_db() is configuration database where we are setting value from higher component and get that value in lower component.for example virtual interface in which we are setting it in top module and we retrieve it in driver and monitor components.

Example 1 : Describe how to set value in test and get that value in env class.


env.sv 

 


class env extends uvm_env;

    //---------------------------------------------------------------------------
    `uvm_component_utils(env)
    //---------------------------------------------------------------------------
    int loop_count;
   //----------------------------------------------------------------------------
   function new(string name="",uvm_component parent);
     super.new(name,parent);
   endfunction
   //----------------------------------------------------------------------------
 
   //---------------------- build phase -----------------------------------------
   function void build_phase(uvm_phase phase);
     super.build_phase(phase);
     if(uvm_config_db#(int)::get(null,"uvm_test_top","loop_count",loop_count))
       `uvm_info("ENV",$sformatf("loop_count is  %0d",loop_count),UVM_LOW)
   endfunction
   //----------------------------------------------------------------------------
 
endclass:env

test.sv

 

class test extends uvm_test;

    //--------------------------------------------------------------------------
    `uvm_component_utils(test)
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    function new(string name="",uvm_component parent);
    super.new(name,parent);
    endfunction
    //--------------------------------------------------------------------------

    env env_h;

    //--------------------------------------------------------------------------
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      env_h = env::type_id::create("env_h",this);
      
      uvm_config_db#(int)::set(null,"uvm_test_top","loop_count",200);
      
    endfunction
    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    task run_phase(uvm_phase phase);
        phase.raise_objection(this);
        `uvm_info("TEST","Running test",UVM_LOW)
        #10;
        phase.drop_objection(this);
    endtask
    //--------------------------------------------------------------------------

endclass:test

 tb_pkg.sv

 


`ifndef TB_PKG
`define TB_PKG
`include "uvm_macros.svh"
package tb_pkg;
 import uvm_pkg::*;
 `include "env.sv"                  // environment class

 `include "test.sv"                 // test1
endpackage
`endif 

 top.sv

 

`include "tb_pkg.sv"
module top;
  import uvm_pkg::*;
  import tb_pkg::*;
  
  //----------------------------------------------------------------------------
  initial begin
    run_test("test");
  end
  //----------------------------------------------------------------------------
endmodule

/* OUTPUT
# KERNEL: UVM_INFO /home/runner/env.sv(17) @ 0: uvm_test_top.env_h [ENV] loop_count is  200
# KERNEL: UVM_INFO /home/runner/test.sv(34) @ 0: uvm_test_top [TEST] Running test
*/

Link : https://www.edaplayground.com/x/JSS_

Example 2 : From test set value of loop_count and get that value in env , agent1 , agen2 classes.  

 agent1.sv

class agent1 extends uvm_agent;

    //----------------------------------------------------------------------------
    `uvm_component_utils(agent1)
    //----------------------------------------------------------------------------
      int loop_count;
    //----------------------------------------------------------------------------
    function new(string name="",uvm_component parent);
      super.new(name,parent);
    endfunction
    //----------------------------------------------------------------------------
  
    //---------------------- build phase -----------------------------------------
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
       if(uvm_config_db#(int)::get(null,"uvm_test_top","loop_count",loop_count))
         `uvm_info("AGENT1",$sformatf("loop_count is  %0d",loop_count),UVM_LOW)
    endfunction
    //----------------------------------------------------------------------------
  
endclass:agent1

 agent2.sv

class agent2 extends uvm_agent;

    //----------------------------------------------------------------------------
    `uvm_component_utils(agent2)
    //----------------------------------------------------------------------------
    int loop_count;
    //----------------------------------------------------------------------------
    function new(string name="",uvm_component parent);
      super.new(name,parent);
    endfunction
    //----------------------------------------------------------------------------
  
    //---------------------- build phase -----------------------------------------
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
       if(uvm_config_db#(int)::get(null,"uvm_test_top","loop_count",loop_count))
         `uvm_info("AGENT2",$sformatf("loop_count is  %0d",loop_count),UVM_LOW)
    endfunction
    //----------------------------------------------------------------------------
  
endclass:agent2

Rest of  code is similar to example1

/* OUTPUT
# KERNEL: UVM_INFO /home/runner/env.sv(22) @ 0: uvm_test_top.env_h [ENV] loop_count is  200
# KERNEL: UVM_INFO /home/build/vlib1/vlib/uvm-1.2/src/base/uvm_resource_db.svh(121) @ 0: 
reporter [CFGDB/GET] Configuration 'uvm_test_top.loop_count' (type bit signed[31:0]) read by 
 = (bit signed[31:0]) 200
# KERNEL: UVM_INFO /home/runner/agent1.sv(17) @ 0: uvm_test_top.env_h.ag1 [AGENT1] loop_count
 is  200
# KERNEL: UVM_INFO /home/build/vlib1/vlib/uvm-1.2/src/base/uvm_resource_db.svh(121) @ 0:
 reporter [CFGDB/GET] Configuration 'uvm_test_top.loop_count' (type bit signed[31:0]) read by
  = (bit signed[31:0]) 200
# KERNEL: UVM_INFO /home/runner/agent2.sv(17) @ 0: uvm_test_top.env_h.ag2 [AGENT2] loop_count
 is  200
# KERNEL: UVM_INFO /home/runner/test.sv(34) @ 0: uvm_test_top [TEST] Running test
*/

 Link : https://www.edaplayground.com/x/NGy9

UVM TB FOR ADDER USING CONFIG_DB : EXAMPLE
Adder Architecture is shown below in which concept of configuration database is used.
 
adder_test has set() method for config_db().
adder_env and adder_agent has get() method for config_db().

adder_test.sv


class adder_test extends uvm_test;

    //--------------------------------------------------------------------------
    `uvm_component_utils(adder_test)
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    function new(string name="adder_test",uvm_component parent);
      super.new(name,parent);
    endfunction
    //--------------------------------------------------------------------------

    adder_env env_h;
    int file_h;

    //////////////////////////////// CONFIGURATION /////////////////////////////
    bit agent_is_active = 1;
    bit has_coverage    = 1;
    bit has_scoreboard  = 1;
    ////////////////////////////////////////////////////////////////////////////

    adder_sequence seq;
    adder_add_zero_in1 seq1_1;
    adder_add_zero_in1 seq1_2;

    adder_add_zero_in2 seq2_1;
    adder_add_zero_in2 seq2_2;

    add_F seq3_1;
    add_F seq3_2;
  
    reset rst;

    //--------------------------------------------------------------------------
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      env_h = adder_env::type_id::create("env_h",this);

      uvm_config_db#(bit)::set(null,"uvm_test_top","agent_is_active",agent_is_active);
      uvm_config_db#(bit)::set(null,"uvm_test_top","has_coverage",      has_coverage);
      uvm_config_db#(bit)::set(null,"uvm_test_top","has_scoreboard",  has_scoreboard);

      seq   =adder_sequence::type_id::create("seq");
      seq1_1=adder_add_zero_in1::type_id::create("seq1_1");
      seq1_2=adder_add_zero_in1::type_id::create("seq1_2");
      seq2_1=adder_add_zero_in2::type_id::create("seq2_1");
      seq2_2=adder_add_zero_in2::type_id::create("seq2_2");
      seq3_1=add_F::type_id::create("seq3_1");
      seq3_2=add_F::type_id::create("seq3_2");
      rst   =reset::type_id::create("rst");
    endfunction
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    function void end_of_elobartion_phase(uvm_phase phase);
      //super.end_of_elobartion_phase(phase);
      //factory.print();
      $display("End of eleboration phase in agent");
    endfunction
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    function void start_of_simulation_phase(uvm_phase phase);
      //super.start_of_simulation_phase(phase);
      $display("start_of_simulation_phase");
      file_h=$fopen("LOG_FILE.log","w");
      set_report_default_file_hier(file_h);
      set_report_severity_action_hier(UVM_INFO,UVM_DISPLAY+UVM_LOG);
      set_report_verbosity_level_hier(UVM_LOW);
      seq.loop_count=100;
    endfunction
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    task run_phase(uvm_phase phase);
        phase.raise_objection(this);
           // seq.start(env_h.agent_h.sequencer_h);
            rst.start(env_h.agent_h.sequencer_h);
            seq.start(env_h.agent_h.sequencer_h);
            seq3_1.start(env_h.agent_h.sequencer_h);
            seq1_1.start(env_h.agent_h.sequencer_h);
            seq2_1.start(env_h.agent_h.sequencer_h);
            
            #10;
        phase.drop_objection(this);
    endtask
    //--------------------------------------------------------------------------

endclass:adder_test


adder_env.sv


class adder_env extends uvm_env;

   //---------------------------------------------------------------------------
   `uvm_component_utils(adder_env)
   //---------------------------------------------------------------------------

  //----------------------------------------------------------------------------
  function new(string name="",uvm_component parent);
    super.new(name,parent);
  endfunction
  //----------------------------------------------------------------------------

  //-------------------- class handles -----------------------------------------
  adder_agent      agent_h;
  adder_coverage   coverage_h;
  adder_scoreboard scoreboard_h;
  //----------------------------------------------------------------------------

  bit has_scoreboard;
  bit has_coverage;

  //---------------------- build phase -----------------------------------------
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
      agent_h      = adder_agent::type_id::create("agent_h",this);
      if(uvm_config_db#(bit)::get(null,"uvm_test_top","has_scoreboard",has_scoreboard))
        `uvm_info(get_type_name(),"HAS SCOREBOARD value get",UVM_LOW)
      else begin
        `uvm_error(get_type_name(),"Not getting has scoreboard")
      end
      if(uvm_config_db#(bit)::get(null,"uvm_test_top","has_coverage",has_coverage))
        `uvm_info(get_type_name(),"HAS COVERAGE value get",UVM_LOW)
      else begin
        `uvm_error(get_type_name(),"Not getting has coverage")
      end

      if(has_coverage==1) begin
        coverage_h   = adder_coverage::type_id::create("coverage_h",this);
      end
      if(has_scoreboard==1) begin
        scoreboard_h = adder_scoreboard::type_id::create("scoreboard_h",this);
      end
   endfunction
  //----------------------------------------------------------------------------

  //-------------------------- connect phase -----------------------------------
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
      if(has_coverage==1) begin
        agent_h.monitor_h.ap_mon.connect(coverage_h.analysis_export);
      end
      
      if(has_scoreboard==1) begin
        agent_h.monitor_h.ap_mon.connect(scoreboard_h.aport_mon);
        agent_h.driver_h.drv2sb.connect(scoreboard_h.aport_drv);
      end
  endfunction
  //----------------------------------------------------------------------------
endclass:adder_env


adder_agent.sv


class adder_agent extends uvm_agent;

  //----------------------------------------------------------------------------
  `uvm_component_utils(adder_agent)
  //----------------------------------------------------------------------------

  //----------------------------------------------------------------------------
  function new(string name="",uvm_component parent);
    super.new(name,parent);
  endfunction
  //----------------------------------------------------------------------------
  bit agent_is_active;
  //----------------- class handles --------------------------------------------
  adder_sequencer sequencer_h;
  adder_driver    driver_h;
  adder_monitor   monitor_h;
  //----------------------------------------------------------------------------

  //---------------------- build phase -----------------------------------------
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    if(uvm_config_db#(bit)::get(null,"uvm_test_top","agent_is_active",agent_is_active))
      `uvm_info(get_type_name(),"AGENT IS ACTIVE value get",UVM_LOW)
    else begin
      `uvm_error(get_type_name(),"Not getting agent_is_active")
    end
    monitor_h   = adder_monitor::type_id::create("monitor_h",this);

    if(agent_is_active==1) begin
      driver_h    = adder_driver::type_id::create("driver_h",this);
      sequencer_h = adder_sequencer::type_id::create("sequencer_h",this);
    end
    
  endfunction
  //----------------------------------------------------------------------------

  //----------------------- connect phase --------------------------------------
  function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    driver_h.seq_item_port.connect(sequencer_h.seq_item_export);
  endfunction
  //----------------------------------------------------------------------------

endclass:adder_agent



Thank you for reading , i will update more examples on config_db .

Share:
Copyright © VLSI Verification Concepts . Designed by OddThemes