Jump to content
Sign in to follow this  

Trouble setting object using config_db

Recommended Posts

I'm having trouble using the config_db mechanism to set a property in a uvm component that is an object.


Using the same flow/mechanisms for an integer property seems to work fine but the setting of a property defined using uvm_field_object doesn't work.


The essence of the code is extracted below.


Any ideas?








  // my_foo_struct_t is class that extends foo_struct_t class
  my_foo_struct_t foo_struct;

  virtual function void build_phase(uvm_phase phase);


    chip = chip_t::type_id::create("c", this);

    foo_struct = new();

    // Set the foo_struct property in any sub-component to this component's foo_struct
    // foo_struct is a uvm_field_object in one component type
    // This doesn't work
    uvm_config_db#(foo_struct_t)::set(this, "*", "foo_struct", foo_struct);

    // Set the foo property in any sub-component
    // foo is a uvm_field_int in several component types
    // This does work
    uvm_config_db#(int)::set(this, "*", "foo", 33);

  endfunction : build_phase


Share this post

Link to post
Share on other sites

When setting it, use the generic uvm_object instead:

uvm_config_db#(foo_struct_t)::set(this, "*", "foo_struct", foo_struct);
uvm_config_db#(uvm_object)::set(this, "*", "foo_struct", foo_struct);

Now, in your sub-components, make sure you use the correct field macros:

class agent_c extends uvm_agent;
    `uvm_field_object(foo_struct, UVM_REFERENCE)

  foo_struct_t foo_struct;

  virtual void build_phase(uvm_phase phase);
    // foo_struct is now set!

Share this post

Link to post
Share on other sites

Thanks.  That worked.


I couldn't find and example or discussion of exactly how to do this in either the reference manual, user's guide, or any of the examples.  It's essentially what is discussed as a configuration object in the user's guide but the details are not covered.  It seems like a good example of this somewhere is warranted.


Also, it's not clear to me why it is essential to use the uvm_object type; i.e. why using my object type (which is derived from uvm_object) won't work.  I tried it.  It doesn't.  Even if the field is defined using UVM_REFERENCE.


Anyway, thanks again.



Share this post

Link to post
Share on other sites

It all has to do with the fact that there is a separate repository of the 'config_db' for each type you specialize it with. This repository is modeled as a static variable. This means that any set operations to a specialization have to be paired up with gets from the same specialization. Basically, even though 'foo_struct' is a child class of 'uvm_object' and so the two are related, there is no relation between uvm_config_db #(foo_struct) and uvm_config_db #(uvm_object).


The reason you have to use uvm_config_db #(uvm_object) when doing the set is because the field automation macro for objects (`uvm_field_object...) expands to include a call to uvm_config_db #(uvm_object).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this