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
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