Jump to content

How to unpack when there is some fields dependency in a class?


Recommended Posts

Hi UVM Exports,

As title, there is no problem to packing thie kind of packet when Tx. but when Rx, the only way I could do now is to write my packet parser to reconstruct it to an object, is there any suggestion or hint that I could leverage the unpack feature UVM provided? thanks so much in advanced!

  class pkt extends uvm_object;
    rand bit [7:0] aa_size;
    rand bit [7:0] aa[];
    constraint c {aa.size() == aa_size; }
 
    `uvm_object_utils_begin(pkt)
      `uvm_field_int       (aa_size,  UVM_ALL_ON)
      `uvm_field_array_int (aa,       UVM_ALL_ON)
    `uvm_object_utils_end
 
    function new(string name="pkt", uvm_component parent=null);
      super.new(name);
    endfunction: new
  endclass
Link to comment
Share on other sites

You'll need to create a custom do_unpack and do_pack function (and set the UVM_NO_PACK in the field macros). In your custom function, you can call the packer.unpack in the same order as you do for the pack (which will be customized to the order you need). After retrieving each field, you can do other things (allocating the array after reading the size, for example) or conditionally creating a child object or conditionally packing/unpacking fields. Look at the methods in the uvm_packer class for some details on how to do this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...