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 (and is attached) 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 Ε:0] addr; rand bit ⎫:0] data; cmd_t cmd; rand bit ΐ:0] dly; function new (cmd_t cmd_new = IDLE, bit ⎫:0] data_new = 0, bit Ε:0] addr_new = 0, bit ΐ: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ΐ] constraint pkt_seq_1_cst { pkt_seq == WRITE_IDLE -> (pktΎ].cmd == WRITE && pktΏ].cmd == IDLE); } constraint pkt_seq_2_cst { pkt_seq == READ_IDLE -> (pktΎ].cmd == READ && pktΏ].cmd == IDLE); } function new (); for (int i=0;i<2;i++) begin pkt[i] = new(); end endfunction
function void post_randomize(); int random; for (int i=0;i<2;i++) begin random = pkt[i].randomize(); end endfunction function void do_print (); $display ("Packet Sequence is %s", pkt_seq.name()); for (int i=0;i<2;i++) begin pkt[i].do_print(); end endfunction endclass : Packet_seq
//------------------ // Main routain //------------------ Packet_seq pkt_seqΑ] initial begin int random; for(int i=0;i<3;i++) begin pkt_seq[i] = new(); random = pkt_seq[i].randomize(); pkt_seq[i].do_print(); end end endmodule
|