Uvm_config_db to set and get values

Generally uvm_config_db is used, where we will set at the top and retrieve at lower components.

Now, my requirement is, there is a variable declared in the driver. I wanted to set some value from the driver and get from the top level. How to do this, when I tried with the following code, it gives me an error message

//inside driver
int shared_variable = 'hFF;

uvm_config_db#(int shared_variable)::set(this, “”, “shared_variable”, 'hFF);

//from tb_top
int value_received;

uvm_config_db#(int shared_variable)::get(this, “”, “shared_variable”, value_received);

This is the example code, please check and let me know.
I wanted to set some value at lower components and get it at top level. Kindly help me to get this or point me to a similar example for this.

Though not very recommended (due to reuse concerns, maybe, you need to think about it) - it is diable. Few issues in your code snippet:

uvm_config_db#(int shared_variable)::get(this

You need it as:

uvm_config_db#(int )::get(this

Same for set.

And to ensure the top sees the bottom scope, use “null” as the cntxt argument. e.g. in your driver, use:

 uvm_config_db#(int)::set(null, "", "shared_variable", 'hFF);
    `uvm_info ("SET", "set to ff", UVM_LOW)

Notice that I used “null” instead of “this”.

Another issue is that your driver/set build happens after your get - you need to delay the get, I did something like this:

  initial begin : get_from_top
     `uvm_info ("GET", $sformatf ("value_received: %x", value_received), UVM_LOW)
    #10;
    uvm_config_db#(int )::get(null, "", "shared_variable", value_received);
    `uvm_info ("GET", $sformatf ("value_received: %x", value_received), UVM_LOW)
  end : get_from_top

Good luck

Quick add - I use a dedicated scope to share such variables - if I had to do that - some more code, to create a “common_shared_scope” and use that as “path_name” in set & get.

Thank you Srini.