UVM Config db
Table of Contents
The configuration database provides access to a centralized database, where type specific information can be stored and received. config_db can contain scalar objects, class handles, queues, lists, or even virtual interfaces.
The database has both a name table and a type table and each resource is entered into both. Resources are stored in a database so that each resource can be retrieved by name or by type, and the database is globally accessible.
uvm config db get and set
uvm_config_db::set and uvm_config_db::get methods are used to store and retrieve the information from the database respectively.
uvm config db set method
void uvm_config_db#(type T = int)::set(uvm_component cntxt, string inst_name, string field_name, T value);
Where,
- T is the type of element being configured. Type can be scalar objects, class handles, queues, lists, or even virtual interfaces)
- cntxt is the hierarchical starting point of where the database entry is accessible.
- inst_name is a hierarchical path that limits the accessibility of the database entry.
example:
top.env.agent.monitor
top.* – all of the scopes whose top-level component is top.
top.env.*.monitor – all of the scopes in env that end in the monitor;
- field_name is the label used as a lookup for the database entry
- value is the value to be stored in the database
uvm_config_db set example
Below example shows, setting the interface handle intf, type mem_if, label mem_intf with global scope.
mem_if intf(clk,reset); //interface instance uvm_config_db#(virtual mem_if)::set(null,"*","mem_intf",intf); //set method
The above diagrams illustrate how a resource whose name is mem_intf and type is mem_if is stored in the pool.
uvm config db get method
bit uvm_config_db#(type T=int)::get(uvm_component cntxt, string inst_name, string field_name, ref T value);
- value is the variable to which the value is to be retrieved from the database
* The other fields are the same as in set method.
The method returns 1 if it is successful and 0 if there is no such resource of this type in the database.
uvm_config_db get example
Below example shows. Using the get method to get a virtual interface handle from a database and assigns it to mem_vif. If the get method fails, the fatal message will be displayed.
virtual interface mem_if mem_vif; //virtual interface declaration if( !uvm_config_db#(virtual mem_if)::get(this,"*", "mem_intf", mem_vif)) `uvm_fatal(get_full_name(),{"virtual interface must be set for:",".mem_vif"} ); //get method