UVM Reference
uvm_config_db
A typed lookup table. A higher component stores a value under a path and a name; a lower one fetches it.
Syntax
uvm_config_db#(T)::set(context, "inst.path", "field", value);
if (!uvm_config_db#(T)::get(this, "", "field", variable))
`uvm_fatal("NOCFG", "field was not set")Rules
- The type
Tmust be exactly the same insetandget.intandbit [31:0]do not match. - The field name must match exactly, as a string.
- The path is the context's full name joined to the instance string.
"*"matches any component below. getreturns 0 when nothing matches. Always check it.- During the build phase, a
setfrom higher in the hierarchy wins over one from lower. - Call
setbefore the receiving component runs itsbuild_phase.
Example
import uvm_pkg::*;
`include "uvm_macros.svh"
class my_agent extends uvm_component;
`uvm_component_utils(my_agent)
int depth;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
function void build_phase(uvm_phase phase);
if (!uvm_config_db#(int)::get(this, "", "depth", depth)) depth = -1;
$display("%s depth=%0d", get_full_name(), depth);
endfunction
endclass
class my_test extends uvm_test;
`uvm_component_utils(my_test)
my_agent a, b;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
function void build_phase(uvm_phase phase);
uvm_config_db#(int)::set(this, "a", "depth", 8);
a = my_agent::type_id::create("a", this);
b = my_agent::type_id::create("b", this);
endfunction
endclass
module tb;
initial run_test("my_test");
endmoduleuvm_test_top.a depth=8
uvm_test_top.b depth=-1Common Mistake
A type that almost matches
uvm_config_db#(int)::set(this, "*", "depth", 8);
uvm_config_db#(bit [31:0])::get(this, "", "depth", depth); // returns 0Each type has its own table. A value stored as int is not in the bit [31:0] table, so get finds nothing.
Fix: Use one type in both calls. For a virtual interface, give the full type, parameters included.
Learn It Properly
These lessons teach it step by step, with practice problems.
Standard
IEEE 1800.2-2020, C.4.