Home > Community > Forums > Functional Verification > randomize() question

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 randomize() question 

Last post Thu, May 24 2007 1:07 AM by archive. 3 replies.
Started by archive 24 May 2007 01:07 AM. Topic has 3 replies and 1128 views
Page 1 of 1 (4 items)
Sort Posts:
  • Thu, May 24 2007 1:07 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,910
    randomize() question Reply

    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 [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[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[3];
       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


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Thu, May 24 2007 9:17 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,910
    RE: randomize() question Reply

    Davy,
         What you are looking for is so called "E-Sequences" or in SV, it is better called "Scenarios" (as the term sequence is used inside SVA domain). Having said that, the way you are approaching does seem the best/optimal way to me atleast. You should try using an array of "Pkt_Cmd" and use SV's "foreach" constraints. Now I'm not sure of tool support for this in your tool set, check with the vendor. We showed how to build a custom scenario for a Vending machine example in our VMM adoption book (www.noveldvocm or www.systemverilog.us). To be honest and fair, it is not that trivial to do this. eRM has sequences precisely for this and perhaps equivalent exists in URM. FWIW, VMM scenario does precisely this and you get this in few lines of code.

    I know I didn't give you direct answer, but hopefully a right direction.

    Good Luck
    Ajeetha, CVC
    www.noveldv.com  


    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Thu, May 24 2007 9:18 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,910
    RE: randomize() question Reply

    Sorry, forgot to add that calling randomize() inside post_randomize is a bad style, avoid it if you can

    Ajeetha, CVC
    www.noveldv.com


    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Sun, May 27 2007 7:17 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,910
    RE: randomize() question Reply

    Hi Ajeetha,

    I have solve the problem by just add rand to Packet object and use randomize only one time at pkt_seq[i].randomize().
    Thanks :)

    Bests regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
Page 1 of 1 (4 items)
Sort Posts:
Started by archive at 24 May 2007 01:07 AM. Topic has 3 replies.