UVM resource DB - vineethkumarv/uvm-repos GitHub Wiki

  • Resource is container that contain the different types of data. It is used to supply the data type to different testbenches. With the help of resource db methods we can put any data type into the resource database and with help of some resource db methods we can retrieve that data type during simulation time.

  • uvm_resource_db is parent class of uvm_config_db.

  • uvm_resource_db is a type-parameterized class that serves the same purpose as congfig_db but does not follow the hierarchical order.It is not instantiated and the methods in it are accessed using scope resolution operator because all of the functions in uvm_resource_db are static, so they must be called using the :: operator.

    Ex: uvm_resource_db#(int)::set(scope,name,val);

There are several common methods of the uvm_resource_db class that allow you to add or retrieve data. The following table highlights the most common functions used.

Sr. No. Method Description
1. get_by_type Get a resource by type.
2. get_by_name Imports a resource by name.
3. set Create a new resource, write a val to it, and set it into the database using name and scope as the lookup parameters.
4. set_default add a new item into the resources database.
5. set_anonymous Create a new resource, write a val to it, and set it into the database.
6. read_by_type Read a value by type.
7. read_by_name locate a resource by name and scope and read its value.
8. write_by_name write a val into the resources database.
9. write_by_type write a val into the resources database.

Methods:

1.get_by_type

It gets the resource by the type specified as a parameter in the class. So, ‘scope’ is the only argument for this function.

syntax
uvm_resource_db#(type T =uvm_object)::get_by_type(string scope)

2.get_by_name

This function gets a resource by using both the scope and name given when it was added to the database.he rpterr argument indicates whether to generate a warning or not if a resource match is not found.

syntax
uvm_resource_db#(type T =uvm_object)::get_by_name(string scope, string name, bit rpterr=1)

3.set

This function creates a new resource in the database with a scope, name and value that will be used for retrieval. The accessor is used for auditting.

syntax
uvm_resource_db#(type T =uvm_object)::set(string scope, string name , value, uvm_object_accessor = null)

4.set_default

It creates a new resource using name and scope as lookup parameters without writing a new val. The resource will have its default value.

syntax
uvm_resource_db#(type T =uvm_object)::set_default(string scope, string name)

5.set_anonymous

It creates a new resource and writes/ sets val to it using the scope as a lookup parameter. The resource is not updated in the name map as it has no name .But is does have a scope for lookup purposes. The accessor is used for auditting.

syntax
uvm_resource_db#(type T =uvm_object)::set_anonymous(string scope, value, uvm_object_accessor = null)

6. read_by_type

This function locates the resource using only the scope as a lookup and returns the value through an output argument.The accessor is used for auditing. The return bit indicates whether read_by_name is successful or not.

syntax
uvm_resource_db#(type T =uvm_object)::read_by_type(string scope, value, uvm_object accessor = null)

7. read_by_name

locate a resource by name and scope and read its value. The value is returned through the output argument val. The return value is a bit that indicates whether or not the read was successful.The accessor is used for auditing. The return bit indicates whether read_by_name is successful or not.

syntax
uvm_resource_db#(type T =uvm_object)::read_by_name(string scope, name, variable, uvm_object accessor = null)

8.write_by_name

Write a val into the database. First lookup for the resource by name and scope. If it is not located then add a new resource to the database and then write its value.

syntax
uvm_resource_db#(type T =uvm_object)::write_by_name(string scope, string name, value, uvm_object accessor = null)

9.write_by_type

Write a val into the database. First lookup for the resource by type. If it is not located then add a new resource to the database and then write its value.

syntax
uvm_resource_db#(type T =uvm_object)::write_by_type(string scope, value, uvm_object accessor = null)

Code Snippet:

class environ extends uvm_env;                                                                      
  `uvm_component_utils(environ)                                                                     
   int a,b,c,b1,d;                                                                                  
  function new(string n="environ",uvm_component p=null);                                            
    super.new(n,p);                                                                                 
  endfunction                                                                                       
  virtual function void build_phase(uvm_phase phase);                                               
  super.build_phase(phase);                                                                         
  $display("this is get by type method value of top.env %p", uvm_resource_db#(int)::get_by_type("top.env"));
  $display("this is get by name method value of top.env %p", uvm_resource_db#(int)::get_by_name("top.env","num1"));
  $display("this is get by name method value of top.env %p", uvm_resource_db#(int)::get_by_name("top.env","num2"));
  $display("this is get by name method value of top.env %p", uvm_resource_db#(int)::get_by_name("top.env","num3"));
  //$display("this is get by name method value of top.env %p", uvm_resource_db#(int)::get_by_name("top.env","num4"));
  uvm_resource_db#(int)::read_by_name("top.env","num1",a);                                          
  uvm_resource_db#(int)::get_by_name("top.env","n",0);                                              
  //uvm_resource_db#(int)::read_by_name("top.env","num4",b);                                        
  $display("............................................");                                         
  $display (uvm_resource_db#(int)::read_by_name("top.env","num2",b));                               
  $display (uvm_resource_db#(int)::read_by_name("top.env","num3",b1));                              
  $display (uvm_resource_db#(int)::read_by_type("top.env",c));                                      
  //$display (uvm_resource_db#(int)::read_by_type("top.env",d));                                    
  $display(" the value of 'a'(num1) retrieved is %0d",a);                                           
  $display(" the value of 'b'(num2) retrieved is %0d",b);                                           
  $display(" the value of 'c' retrieved via read_by_type is %0d",c);                                
  //$display(" the value of 'c'(num4) retrieved is %0d",d);                                         
  $display(" the value of 'b'(num3) retrieved is %0d",b1);                                          
  endfunction                                                                                       
endclass  
  class test extends uvm_test;                                                                        
environ e;                                                                                          
                                                                                                    
`uvm_component_utils(test)                                                                          
function new(string n="environ",uvm_component p=null);                                              
    super.new(n,p);                                                                                 
  endfunction                                                                                       
  virtual function void build_phase(uvm_phase phase);                                               
  super.build_phase(phase);                                                                         
  e=environ::type_id::create("e",this);                                                             
  uvm_resource_db#(int)::set("top.env","num1",999);                                                 
  uvm_resource_db#(int)::set_default("top.env","num2");//takes no value                             
  uvm_resource_db#(int)::set_default("top.env","num3");                                             
  //uvm_resource_db#(int)::set_default("top.env","num4");                                           
  uvm_resource_db#(int)::set_anonymous("top.env",5);                                                
  uvm_resource_db#(int)::write_by_name("top.env","num1",143); //overrides num1                      
 // uvm_resource_db#(int)::write_by_name("top.env","num4",143);//shows error                        
  uvm_resource_db#(int)::write_by_name("top.env","num2",140);                                       
  uvm_resource_db#(int)::write_by_name("top.env","num3",100);                                       
  uvm_resource_db#(int)::write_by_type("top.env",146);                                              
  //uvm_resource_db#(int)::write_by_type("top.env",79); multiple values cannot be put               
  uvm_resource_db#(int)::dump();                                                                    
                                                                                                    
  endfunction                                                                                       
endclass    

To be Noted
1.set creates a new resource,and sets the value to it.
2.set_default creates a new resource but won't write a value to it and to write a value to that created resource name we use write_by_name,which overrides the existing resource value.
3.get_by_type ,returns a packed array that gives the details of the resource and recent value of write_by_type.
4.get_by_name ,returns a packed array that gives the details of the resource and recent value of write_by_name.
5.to retrieve any value by name use read_by_name.
6.to retrieve any value by type use read_by_value.
7.write and read methods do not work if no source is created before them so be careful while using.
8.rpterr is a field in get_by_name that allows us to restrict the error message if no value or item is found by the given name.