SV: randomize() question

S

Shenli

Guest
Hi all,

There is a randomize() problem.
I want to randomize a Packet_seq which includes two Packet object.

First, I call Packet_seq randomize() to get pkt_seq. From pkt_seq to
get Packet's cmd by constraint.
Second, I call Packet randomize() from Packet_seq's post_randomize()
to make Packet's other attribute randomized.

But the random solver said there is a error when solve my constraint?
Any suggestions are welcome!


// Code listed below
module top;

typedef enum { WRITE=1,READ=2,IDLE=4} cmd_t;
typedef enum { WRITE_IDLE, READ_IDLE} packet_seq_t;

class Packet;

rand bit [7:0] addr;
rand bit [31:0] data;
cmd_t cmd;
rand bit [2:0] dly;

function new (cmd_t cmd_new = IDLE,
bit [31:0] data_new = 0,
bit [7:0] addr_new = 0,
bit [2:0] dly_new = 1);
cmd = cmd_new;
data = data_new;
addr = addr_new;
dly = dly_new;
endfunction

function void do_print ();
begin
$display("Packet_tr: cmd=%s, addr=%0d, data=%0d, dly=%0d",
cmd.name(), addr, data, dly);
end
endfunction
endclass : Packet

class Packet_seq;
rand packet_seq_t pkt_seq;
Packet pkt[2];

constraint pkt_seq_1_cst { pkt_seq == WRITE_IDLE -> (pkt[0].cmd
== WRITE && pkt[1].cmd == IDLE); }
constraint pkt_seq_2_cst { pkt_seq == READ_IDLE -> (pkt[0].cmd
== READ && pkt[1].cmd == IDLE); }

function new ();
for (int i=0;i<2;i++) begin
pkt = new();
end
endfunction

function void post_randomize();
int random;
for (int i=0;i<2;i++) begin
random = pkt.randomize();
end
endfunction

function void do_print ();
$display ("Packet Sequence is %s", pkt_seq.name());
for (int i=0;i<2;i++) begin
pkt.do_print();
end
endfunction

endclass : Packet_seq

//------------------
// Main routain
//------------------
Packet_seq pkt_seq[3];
initial begin
int random;
for(int i=0;i<3;i++) begin
pkt_seq = new();
random = pkt_seq.randomize();
pkt_seq.do_print();
end
end


endmodule
 
On 24 May 2007 01:15:06 -0700, Shenli <zhushenli@gmail.com> wrote:

Hi all,

There is a randomize() problem.
I want to randomize a Packet_seq which includes two Packet object.

First, I call Packet_seq randomize() to get pkt_seq. From pkt_seq to
get Packet's cmd by constraint.
Second, I call Packet randomize() from Packet_seq's post_randomize()
to make Packet's other attribute randomized.

But the random solver said there is a error when solve my constraint?
Any suggestions are welcome!


// Code listed below
[snip]

It seems to me that Packet::cmd and Packet_seq::pkt both must
be declared "rand". The constraint solver cannot change their
values if they are not "rand".

Is it really necessary to have Packet_seq::post_randomize() ???
Surely the array pkt[] will have its contents randomized for you
if you declare it to be "rand"?
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On May 24, 6:17 pm, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
On 24 May 2007 01:15:06 -0700, Shenli <zhushe...@gmail.com> wrote:

Hi all,

There is a randomize() problem.
I want to randomize a Packet_seq which includes two Packet object.

First, I call Packet_seq randomize() to get pkt_seq. From pkt_seq to
get Packet's cmd by constraint.
Second, I call Packet randomize() from Packet_seq's post_randomize()
to make Packet's other attribute randomized.

But the random solver said there is a error when solve my constraint?
Any suggestions are welcome!

// Code listed below

[snip]

It seems to me that Packet::cmd and Packet_seq::pkt both must
be declared "rand". The constraint solver cannot change their
values if they are not "rand".

Is it really necessary to have Packet_seq::post_randomize() ???
Surely the array pkt[] will have its contents randomized for you
if you declare it to be "rand"?
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Hi Jonathan,

I have solve the problem by just add rand to Packet object and use
randomize only once at pkt_seq.randomize().
Thanks :)

Best regards,
Shenli
 

Welcome to EDABoard.com

Sponsor

Back
Top