How to access member of parent sequence

Hi,

I have a member tx_cnt in the virtual sequence which spawns of other child sequences. I want the child sequence have access this member which is updated dynamically through out the sim. Any ideas how to do this?

I tried to pass do the following

  • child_seq.start(seqr,this/parent sequence/)
  • in body of child seq i had child_seq_iem.cnt = m_parent_sequence.tx_cnt;

pass the parent_sequence through start and then access using m_parent_sequence.tx_cnt but i get error that tx_cnt variable is not found .

In reply to CRVAddict:

Can you try by dynamic casting from m_parent_sequence to your parent virtual sequence where tx_cnt variable located.

Alternative way, you can set the variable to sequencer in your parent virtual sequence using uvm_config_db, then you get it in your child sequence.

In reply to cuonghle:

Thanks for your ideas.

  • yes option one will work theoretically if i cast but will not work in my case because in order of compilation the child seq is compiled before the virtual seq(parent seq)
  • this might work so let me try

Thanks

In reply to CRVAddict:

Do you know if
at time 0 - set tx_cnt to sequencer
time 1 - sequencer gets tx_cnt
time 10 - tx_cnt value changes

Will sequencer get updated value of tx_cnt?

In reply to CRVAddict:
#1) $cast is dynamic casting, it will check the compatible in run time, not compilation time. Then, I don’t think it will be an issue because of compilation order. Can you try again?

#2) The answer is “no”. Either you set again when the tx_cnt value is changed in parent, or you can create wrapper object configuration, set the handler of this object to database, then get it in children sequences:


class seq_cfg extends uvm_object;
  int tx_cnt;
  // ...
endclass

class parent_seq extends uvm_sequence;
  seq_cfg cfg;
  // ...
  task pre_body();
    uvm_config_db#(seq_cfg)::set(seqr, "*", "cfg", cfg);
  endtask
endclass

class child_seq extends uvm_sequence;
  seq_cfg cfg;
  // ...
  task pre_body(); 
    uvm_config_db#(seq_cfg)::get(m_sequencer, "", "cfg", cfg);
  endtask

With it, everytime the value tx_cnt is changed, the child seq is able to get the updated value.

In reply to cuonghle:
hi
As for #1 option(dynamic casting) i have attached a sample which i tried.
You need a type of parent to $cast isnt it, so for it to work with the forward referencing using typedef this will not work because of order of compilation or am i missing something.


typedef class v_seq;
  
class seq extends uvm_sequence #(seq_item);
  `uvm_object_utils(seq)
  
   seq_item req;
   v_seq p;
  
  function new(string name = "seq");
  super.new(name);
  // do_not_randomize = 1'b1; // Required for ModelSim
endfunction

  task body();
    m_parent_sequence.print();
    $cast(p,m_parent_sequence);
    $display("tx_cnt %d",p.tx_cnt);
    

In reply to CRVAddict:

I don’t see any problem with m_parent_sequence casting in your code, class forward declaration should be used due to your compilation order issue.

You can check the link below to see how it works:

In reply to cuonghle:

I mean to say , it cant work without forward referencing using typedef and typedef works only if the sequences are in same files. In a normal UVM TB we dont have the seq and virtual seq in same file isnt it

In reply to CRVAddict:

Sorry I was wrong for forward referencing they dont have to be in same file.
Thanks a lot for your help Chris