Jump to content

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


Link to comment
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!

Link to comment
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.



Link to comment
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).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...