Home > Community > Forums > Functional Verification > Packing of Random variables into List of bytes

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

 Packing of Random variables into List of bytes 

Last post Thu, Oct 25 2007 2:09 AM by archive. 4 replies.
Started by archive 25 Oct 2007 02:09 AM. Topic has 4 replies and 1177 views
Page 1 of 1 (5 items)
Sort Posts:
  • Thu, Oct 25 2007 2:09 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    Packing of Random variables into List of bytes Reply

    Example:

    // class -1
      class fc_field;
       
        rand bit [1:0] protocol_ver;
          constraint pro_ver {
              protocol_ver == 0;
          }
     
        rand bit [1:0] pkt_type;
          constraint Pkt_type {
              pkt_type == 2;
          }
     
        rand bit [3:0] pkt_sub_type;
          constraint Pkt_sub_type {
              pkt_sub_type == 11;
          }
     
        rand bit to_ds;
          constraint To_ds {
              to_ds == 0;
          }
     
        rand bit from_ds;
          constraint From_ds {
              from_ds == 0;
          }
     
        rand bit more_fragment;
          constraint More_fragment {
              more_fragment == 0;
          }
     
        rand bit retry;
          constraint Retry {
              retry == 1;
          }
     
        rand bit pwr_mgmt;
          constraint Pwr_mgmt {
              pwr_mgmt == 0;
          }
     
        rand bit more_data;
          constraint More_data {
              more_data == 0;
          }
     
        rand bit protected_frame;
          constraint Protected_frame {
              protected_frame == 1;
          }
     
        rand bit order;
          constraint Order {
              order == 1;
          }
     
      endclass
     
    // Class-2

      class seq_control_field;
       
        rand bit [3:0] fragment_number;
          constraint Fragment_number {
              fragment_number == 0;
          }

        rand bit [11:0] sequence_number;
          constraint Sequence_number {
              sequence_number == 0;
          }

      endclass   

    // Main Class. This instantiates the fc_field and seq_control_field class objects

      class mac_header;
       
        rand fc_field fc_obj = new();       // Object of fc_field
       
        rand bit [15:0] duration_id;
          constraint Duration_id {
              duration_id == 0;
          }

        rand bit [47:0] address_1;
          constraint Address_1 {
              address_1 == 48'h001122334455;
          }

        rand bit [47:0] address_2;
          constraint Address_2 {
              address_2 == 48'h009988776655;
          }

        rand bit [47:0] address_3;

        rand seq_control_field seq_obj = new();      // Object of fc_field

        rand bit [47:0] address_4;

        rand bit [15:0] qos;
          constraint Qos {
              qos == 16'h0000;
          }

      endclass   

    In the above example, how can i pack the mac_header into list of bytes? This shouldn't affect the constraints on the class member functions, of all the threee different classes.

    Also, is there any way to print the class object?

    All of the above can be done eeasily in specman, is it possible in the systemverilog implicitly?

    -Vivek Prasad


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
  • Sat, Oct 27 2007 8:36 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: Packing of Random variables into List of bytes Reply

    >> In the above example, how can i pack the mac_header into list of bytes?

    For packing you can use bit-streaming operator. I didn't try on your code, but it works as below:

    program pack_pgm; class mac_header; .. mac_header mac_header_0; byte byte_array []; initial begin : test mac_header_0 = new(); byte_array = {byte << {mac_header_0}}; end : test

    >> is there any way to print the class object?

    I know some tools allow it as part of regular $display. But I generally find it is much better to write your own do_print () method - so that you have your design specific format. This brings in consistency for the whole team - for a small price (of maybe 20 lines of typing).

    HTH
    Ajeetha, CVC
    www.noveldv.com


    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Mon, Oct 29 2007 7:08 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: Packing of Random variables into List of bytes Reply

    Ajeetha,

    Thanks for the same.

    NCSim is giving error for that statement. "Illegal Expression Primary".

    I am attaching the code. Can you help me?

    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
  • Mon, Oct 29 2007 8:43 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: Packing of Random variables into List of bytes Reply

    NCSim is giving error for that statement. "Illegal Expression Primary".


    I would imagine that may be Unsupported in your version. Write a simple function to to the pack - make it hierarchical - each class will pack its own contents and the derived classes would simply use the super.pack() and build on it.

    HTH
    Ajeetha, CVC
    www.noveldv.com


    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Mon, Oct 29 2007 9:48 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: Packing of Random variables into List of bytes Reply

    Which Tool and Version are you referring to?

    I am using the ncsim 6.1ius-s002.


    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
Page 1 of 1 (5 items)
Sort Posts:
Started by archive at 25 Oct 2007 02:09 AM. Topic has 4 replies.