Getting a config db variable value in higher hierarchy

In my Env class, I am setting a variable through uvm_config_db and accessing it in higher hierarchy i.e one of the sequences to form a case.

class env extends uvm_env;
...
typedef enum bit {ERROR_FROM_SEQUENCE=0, ERROR_FROM_CALLBACK } err_gen_src;
err_gen_src error_source;

function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      uvm_config_db#(int)::set(this, "*", error_source, ERROR_FROM_SEQUENCE);
endfunction
endclass

Now can I do something like this in Case?

class my_seq extends uvm_sequence#(item);
...
   task body();
      item t;
      forever begin
         p_sequencer.fifo.get_peek_export.get(my_req);
         **case(uvm_config_db#(int)::get(this, "", error_source, ??)**
            **ERROR_FROM_SEQUENCE:** `uvm_do_with(item, {item.data == 100;})
         
            **ERROR_FROM_CALLBACK:** `uvm_do_with(item, {item.data == 300;})
         endcase
      end
   endtask

endclass
         

In reply to smukerji:

Your sequence does not belong to the hierarchy of your class-based testbench. It is simply a transient object that will be generated at any time and disappear at another time.
The uvm_config db has no limitations regarding the directions.
What you are doing in your sequence Looks a Little bit strange, especially

p_sequencer.fifo.get_peek_export.get(my_req);


and this

uvm_config_db#(int)::get(this, "", error_source, ??)

The question marks are not legal.
Please explain what your intention is.

In reply to chr_sue:

Thanks for pointing out. I didnt know what to put there, so a question mark. My intention is to have a config variable called error_source of type enum in the environment class and use it in my sequence, to decide what sequence to send to sequencer. The value of the error_source is used as a Case switch.Is there any way to implement that?

The line
p_sequencer.fifo.get_peek_export.get(my_req);

I got from

http://www.verilab.com/files/mastering_reactive_slaves.pdf

In reply to smukerji:

OK, I understand. It Looks like you do not understand the mechanism of the uvm_config_db. You do not store variables there. You store simple values of certain types. The value is assiciated with a name. The Name consists of the path and a simple Name (string). In your case the simple name is ‘error_source’. And the path is the concatenation of ‘this’ and an empty string. Where you have the question marks you have to use a local variable where the value will be stored in.

In reply to chr_sue:

So, then this should work?

case(uvm_config_db#(int)::get(this, “”, “error_source”, error_source))

ERROR_FROM_SEQUENCE : uvm_do_with(item, {item.data == 100;}) ERROR_FROM_CALLBACK : uvm_do_with(item, {item.data == 300;})
endcase

In reply to smukerji:
In the set command you have also to use a string as the simple name:

function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      uvm_config_db#(int)::set(this, "*", "error_source", ERROR_FROM_SEQUENCE);
endfunction


This presumes ERROR_FROM_SEQUENCE is the value you want to put to the config_db.

In reply to smukerji:

Hi Chr_sue,
We cannot directly use uvm_config_db#(int)::get(this, “”, error_source, ??) in the sequence. Am I correct?
I think it needs to be accessed by replacing m_sequencer instead of “this” in the above statement.
Please correct me if I am wrong.

In reply to mbhat:

Of course, you can do this as shown inmy last Reply. It depends always how you are doing the set.

Please read the following link for seperate solutions:

https://verificationacademy.com/cookbook/config/configuringsequences