Why Config DB Matters
The Problem: Without Config DB, you'd have to hardcode settings in every component. Want to change the baud rate? Edit 10 files.
The Solution: Config DB lets you set values once (in the test) and they automatically reach the right components. Change one line, update everything.
The uvm_config_db is a type-safe, string-based database used to pass
configuration
parameters vertically (Top-to-Bottom) through the UVM hierarchy. It is the primary way to
decouple componentsallowing a Test to change an Agent's behavior without modifying the
Agent's source code.
1. The API Breakdown
Both set() and get() require four parameters:
- Context (uvm_component): The starting point of the search. Usually
this. - Inst Name (string): The hierarchical path to the target component (supports
wildcards like
*). - Field Name (string): The key used to find the data.
- Value (TYPE): The actual data being passed.
// Inside the top-level module (harness)
initial begin
uvm_config_db#(virtual my_if)::set(null, "uvm_test_top*", "vif", vif);
end
// Inside the Driver
virtual my_if vif;
function void build_phase(uvm_phase phase);
if(!uvm_config_db#(virtual my_if)::get(this, "", "vif", vif))
`uvm_fatal("NOVIF", "Could not get virtual interface handle!")
endfunction
Why use `null` as the context in the harness?
In a SystemVerilog module (top-level), there is no UVM component context. Passing
null
tells UVM to start the search from uvm_root. The star
"uvm_test_top*"
ensures the configuration is visible to the test and everything inside it.