Friday, November 21, 2008     Register | Login | Search | Contact Us
     

Many of you already received communications about the move of the Cadence user community into cadence.com. And many of you have already joined, with over 4000 registrations in the first two weeks.

The new Cadence Community enhances the ability of Cadence users to connect and collaborate. In addition to moving the community into cadence.com -- enabling single sign-on for community, Sourcelink and Cadence events -- the new site is organized around nine technology segments, giving you easy access to product information, training, forums and blogs. Some of the new features include:
  • Ability to respond to posts via e-mail
  • Technology-specific blogs
  • Latest Web 2.0 social networking capabilities
  • Public profile options
  • Private messaging
  • Friends lists
Visit the new Cadence Community today at www.cadence.com/community and join the discussions!

Registration note: Due to the scope of the enhancements and the new SSO registration system, we were not able to migrate existing cdnusers.org member accounts. So new registrations are required, but this enables a broader set of functionality we think you'll enjoy.

Forum note: Under the guidance of forum moderators, we have taken the 20+ cdnusers.org forums and consolidated them into 11 forums on the new site. Posts have been brought over so you can leverage that posting history. CDNusers forums will be set to read only starting 7/30, and cdnusers.org will be redirected to the new community on 8/4.

Best regards,
Mike and Tom

Michael A. Catrambone - Steering Committee Chairman
Distinguished Engineer
PCB/Mechanical
UTStarcom, Inc.

Tom Diederich
Cadence Community Manager
Home
Forums
Subject: randomize() question
Posting to forums is available to community members only.
Login or Register
Rate this topic:
   
Author Messages
davyzhu
Posts: 90
Online: User is Offline
5/24/2007 1:07 AM  

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


Attachment: test_rand_sv.txt

ajeetha
Posts: 97
Online: User is Offline
5/24/2007 9:17 AM  
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  
ajeetha
Posts: 97
Online: User is Offline
5/24/2007 9:18 AM  
Sorry, forgot to add that calling randomize() inside post_randomize is a bad style, avoid it if you can

Ajeetha, CVC
www.noveldv.com
davyzhu
Posts: 90
Online: User is Offline
5/27/2007 7:17 PM  
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

Posting to forums is available to community members only.
Login or Register

Forums > Functional Verification > SystemVerilog > randomize() question


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.