In Vera terminology packets are called tranctions. Tranctions contains the physical data that are to be sent to dut. It also contains some more properties which help in building tranctions. Tranctions are built by extending rvm_data. rvm_data has set of standered methods like copy(),compare(),byte_pack(),byte_unp
ack() etc.
// Constrain the len according the payload_size control field
constraint len_size {
(payload_size == SMALL_P ) => len in { 5 : 6};
(payload_size == MEDIUM_P ) => len in { 7 : 8};
(payload_size == LARGE_P ) => len in {9 : 10}; }
// Constrain length of data == len
constraint data_size { data.size() ==len;}
constraint len_siz { solve len before data.size() ;}
// May be assigned either a good or bad value,parity will be calculated in portrandomize
constraint parity_type {
(packet_kind == GOOD_P ) => parity == 0;
(packet_kind == BAD_P ) => parity != 0;}
//All data object methods should be virtual
//All data object methods shall be nonblocking
tasknew();
task do_cfg(Configuration cfg);
virtualfunctionstring psdisplay(string prefix );
virtualfunction rvm_data copy(rvm_data to);
virtualfunctioninteger byte_unpack(bit [7:0] bytes[*],integer offset = 0,integer kind = -1);
virtualfunctionbit[7:0] parity_cal();
function rvm_data packet::copy(rvm_data to = null){
packet cpy;
// Copying to a new instance?
if (to == null)
cpy = new;
else
// Copying to an existing instance. Correct type?
if (!cast_assign(cpy, to,CHECK))
{
rvm_fatal(this.log, "Attempting to copy to a non packet instance");
copy = null;
return;
}
//unpacking function for converting recived data to class properties
functioninteger packet::byte_unpack(bit [7:0] bytes[*],integer offset ,integer kind){
sprintf(msg," bytes size %d",bytes.size());
da = bytes[1];
sa = bytes[2];
len = bytes[3];
functionbit[7:0] packet::parity_cal(){
integer i;
bit[7:0] result ;
result = result ^ this.da;
result = result ^ this.sa;
result = result ^ this.len;
for (i = 0;i<this.len;i++)
{
result = result ^ this.data[i];
}
parity_cal = result;
}
//post randomize fun to cal parity
task packet::post_randomize(){
parity = parity ^ parity_cal();
sprintf(msg," %x %x %x %x",mem[0],mem[1],mem[2],mem[3]);
rvm_note(this.log,msg);
}
compare = 1; // Assume success by default.
diff = "No differences found";
if (!cast_assign(cmp, to,CHECK))
{ rvm_fatal(this.log, "Attempting to compare to a non packet instance");
compare = 0;
diff = "Cannot compare non packets";
return;
}
// data types are the same, do comparison:
if (this.da != cmp.da)
{
diff = psprintf("Different DA values: %b != %b", this.da, cmp.da);
compare = 0;
return;
}
if (this.sa != cmp.sa)
{
diff = psprintf("Different SA values: %b != %b", this.sa, cmp.sa);
compare = 0;
return;
}
if (this.len != cmp.len)
{
diff = psprintf("Different LEN values: %b != %b", this.len, cmp.len);
compare = 0;
return;
}