Setting a sequence item Param from another sequence

Hi,

I have a write control sequence item and some rand Params, example a and b, declared inside. It has a corresponding write sequence.

I also have a write data sequence item and some other rand params declared, example data_size. It has a corresponding write data sequence.

From the write data sequence, can I set one of the write data sequence item params depending on some values in the write sequence Params.

Example I want to set data_size == a*b.

Please advise how to do this.

Hi everyone,

Any ideas, please share.

In reply to UVM_learner6:

Hi,
I have a write control sequence item and some rand Params, example a and b, declared inside. It has a corresponding write sequence.
I also have a write data sequence item and some other rand params declared, example data_size. It has a corresponding write data sequence.
From the write data sequence, can I set one of the write data sequence item params depending on some values in the write sequence Params.
Example I want to set data_size == a*b.
Please advise how to do this.

This detail isn’t clear. Please post some sudo-code or specific detail of your requirement.

In reply to UVM_learner6:

The use of the word “Param” is probably confusing people. A class parameter is not random variable, it’s a constant.

It would also help to explain the relationship between the two sequences. Does one create the other?

In reply to dave_59:

Sorry for the confusion. Yes, param is the wrong word to use.

The first sequence item that has these random variables a and b, is controlled by a write control sequence.

The second sequence item that has the random variable data, is controlled by a write data sequence. I would like this variable data to be set(data== a * b) after a and b are first randomized.

Is there a way to access a and b variables from the other sequence?

In the test, I will call the write control sequence first, followed by write data sequence.

If I need to create a wrapper top sequence, pls let me know how it needs to look like?

In reply to UVM_learner6:


class seq1 extends ..
rand int a,b;
endclass

class seq2 extends ..
rand int data;
rand int a,b;
constraint c1 { data == a*b; }
endclass

///test case
seq1.randomize();
seq1.start();

seq2.randomize()with{ a==seq1.a; b==seq1.b; };
seq2.start();




In reply to Rahulkumar Patel:

In reply to UVM_learner6:


class seq1 extends ..
rand int a,b;
endclass
class seq2 extends ..
rand int data;
rand int a,b;
constraint c1 { data == a*b; }
endclass
///test case
seq1.randomize();
seq1.start();
seq2.randomize()with{ a==seq1.a; b==seq1.b; };
seq2.start();

Hi Rahul,

The above seq2.randomize did not work as expected, seq2 a and b take random values and not the ones assigned from the testcase. I followed the same order of sequence randomization and sequence calls as you mentioned.

The seq1 params after randomization don’t get properly transferred to seq2. Is there any other way of handling this?

Thanks.

In reply to UVM_learner6:

It should work. I hope width of data is sufficient to hold the ab. For example, a,b are 32 bit then data should be at least 64bit(data=ab). This is just an example code. Please check variables width in your code.


class myPacket;
  rand  int a,b;
  constraint c1 { a inside {[1:10]}; b inside {[1:10]}; }
  
  function display ();
    $display ("a : 0x%0h b : 0x%0h", a, b);
  endfunction
endclass
 
class myPacket_1;
 
  rand int a,b;
  rand bit[63:0] data;
  constraint c1 { data==a*b; }
  
  function display ();
    $display ("data : 0x%0h, a : 0x%0h b : 0x%0h", data, a, b);
  endfunction
endclass

module tb_top;
  myPacket pkt;
  myPacket_1 pkt_1;
 
  initial begin
    pkt = new ();
    pkt.randomize ();
    pkt.display ();

    pkt_1 = new();
    pkt_1.randomize () with { a==pkt.a; b==pkt.b; };
    pkt_1.display ();     
  end
endmodule 

In reply to Rahulkumar:

In reply to UVM_learner6:


class seq1 extends ..
rand int a,b;
endclass
class seq2 extends ..
rand int data;
rand int a,b;
constraint c1 { data == a*b; }
endclass
///test case
seq1.randomize();
seq1.start();
seq2.randomize()with{ a==seq1.a; b==seq1.b; };
seq2.start();

Hi Rahul,

In this example you showed, the sequences are started one after another.

Seq1 is write request seq ans seq2 is wdata sequence in my case.

Is there a way where I can randomize the write sequence with random a and b values.

Then randomize the wdata sequence with the data size = a*b.

And then start both in parallel with fork join?

I want to test the case where both write request and write data come at the same clock.

Can virtual sequences help? If so on which sequencer should I start it?
Could you please show me a sample code of how to use virtual sequence in this case? i have a write request sequencer and wdata sequencer?

Thank you

In reply to UVM_learner6:

Yes


class seq1 extends ..
rand int a,b;
endclass
 
class seq2 extends ..
rand int data;
rand int a,b;
constraint c1 { data == a*b; }
endclass
 
///test case
seq1.randomize();
seq2.randomize()with{ a==seq1.a; b==seq1.b; };

fork
  seq1.start();
  seq2.start();
join