Hi,
I am trying to set the config from the top module and trying to retrieve it in env component.
But, I am getting the following error:
*UVM_ERROR Env.sv(30) @ 0: uvm_test_top.m_env [Env] m_config
xmsim: E,TRNULLID: NULL pointer dereference.
File: ./Env.sv, line = 32, pos = 33
Scope: worklib.VerPkg::Env@1951_1.build_phase
Time: 0 FS + 9
To give an insight into my code.
I have following files.
VerPkg.sv - list of all the files in env.
config.sv - have a couple of variables like coverageEn, checkEn etc.
top.sv - have the instance of the config and set it via uvm_config.
Env.sv - In the build_phase get the config via uvm_config
VerPkg:
package VerPkg;
`include "SequenceItem.sv"
`include "Config.sv"
`include "Sequencer.sv"
`include "Driver.sv"
`include "Monitor.sv"
`include "Agent.sv"
`include "BaseSequence.sv"
`include "Coverage.sv"
`include "Env.sv"
`include "BaseTest.sv"
endpackage: VerPkg
Config.sv:
`include "uvm_macros.svh"
import uvm_pkg::*;
class Config extends uvm_object;
`uvm_object_utils(Config)
virtual Interface vif;
uvm_active_passive_enum is_active = UVM_ACTIVE;
bit checks_enable;
bit coverage_enable;
int unsigned count;
extern function new(string name="");
endclass: Config
function Config::new(string name = "");
super.new(name);
endfunction: new
top.sv:
`timescale 1ns/1ps
`include "uvm_macros.svh"
`include "Interface.sv"
`include "VerPkg.sv"
module Top;
import uvm_pkg::*;
import VerPkg::*;
Config m_config;
Interface Intf();
dut dutInst (.Intf(Intf));
initial
begin
skp = 0;
forever #5 skp = ~skp;
end
initial
begin
m_config = new("m_config");
if(!m_config.randomize()) `uvm_fatal("top_tb","Failed to randomize config object.")
m_config.vif = Intf;
m_config.is_active = UVM_ACTIVE;
m_config.checks_enable = 1;
m_config.coverage_enable = 1;
$display("PP: Config is being set at thime: %t",$time);
uvm_config_db #(virtual Interface)::set(uvm_root::get(),"*","Interface",Intf);
uvm_config_db #(Config)::set(uvm_root::get(),"*","Config",m_config);
$display("PP: DONE SETTING VIF and CONFIG");
uvm_top.finish_on_completion = 1;
run_test();
end
endmodule: Top
Env.sv:
`include "uvm_macros.svh"
import uvm_pkg::*;
class Env extends uvm_env;
`uvm_component_utils(Env)
Config m_Config;
Agent m_Agent;
Coverage m_Coverage;
Config m_config;
extern function new(string name, uvm_component parent);
extern function void build_phase (uvm_phase phase);
extern function void connect_phase (uvm_phase phase);
extern function void end_of_elaboration_phase (uvm_phase phase);
extern task run_phase(uvm_phase phase);
endclass:Env
function Env::new(string name, uvm_component parent);
super.new(name,parent);
m_Config = new("m_Config");
endfunction: new
function void Env::build_phase(uvm_phase phase);
`uvm_info(get_type_name(),$sformatf("In build_phase"),UVM_HIGH)
m_Agent = Agent::type_id::create("m_Agent",this);
m_Coverage = Coverage::type_id::create("m_Coverage",this);
if(!uvm_config_db#(Config)::get(this,"","config",m_config))
`uvm_error(get_type_name(),$sformatf("Unable to get m_config"))
m_Config.vif = m_config.vif;
m_Config.is_active = m_config.is_active;
m_Config.checks_enable = m_config.checks_enable;
m_Config.coverage_enable = m_config.coverage_enable;
uvm_config_db#(Config)::set(this,"m_Agent","config",m_Config);
if(m_config.is_active == UVM_ACTIVE)
uvm_config_db#(Config)::set(this,"m_Agent.m_seqr","config",m_Config);
endfunction: build_phase
function void Env::connect_phase(uvm_phase phase);
m_Agent.analysis_port.connect(m_Coverage.analysis_export);
endfunction: connect_phase
function void Env::end_of_elaboration_phase(uvm_phase phase);
uvm_factory factory = uvm_factory::get();
factory.print();
endfunction: end_of_elaboration_phase
task Env::run_phase(uvm_phase phase);
uvm_objection objection = phase.get_objection();
objection.set_propagate_mode(0);
objection.set_drain_time(this,100ns);
uvm_top.set_timeout(1ms);
endtask: run_phase
Thanks for your time, pointer, and advice.