In this Phase, we will develop Transaction as per the verification plan. We will define required methods and constraints. We will also develop a small logic to test our implementation of this class.
Packet
We will write the packet class in Packet.sv file. Packet class variables and constraints have been derived from stimulus generation plan.
One way to model Packet is by extending uvm_sequence_item. uvm_sequence_item provides basic functionality for sequence items and sequences to operate in a sequence mechanism. Packet class should be able to generate all possible packet types randomly. To define copy, compare, record, print and sprint methods, we will use UVM field macros. For packing and Unpacking, we will define the logic and not use the field macros.
Revisit Stimulus Generation Plan
1) Packet DA: Generate packet DA with the configured address.
2) Payload length: generate payload length ranging from 2 to 255.
3) Generate good and bad FCS.
1) Define enumerated type data for fcs.
typedefenum { GOOD_FCS, BAD_FCS } fcs_kind_t;
2) Define transaction by extending uvm_sequence_item.
7) Define cal_fcs() method which computes the fcs value.
///// method to calculate the fcs /////
virtualfunctionbyte cal_fcs;
return da ^ sa ^ length ^ data.xor() ^ fcs;
endfunction : cal_fcs
8) Using uvm_field_* macros, define transaction required method.
We will define packing and unpacking methods manually, so use UVM_NOPACK for excluding atomic creation of packing and un packing method.
Now we will write a small logic to test our packet implantation. This module is not used in normal verification.
Define a module and take the instance of packet class. Randomize the packet and call the print method to analyze the generation. Then pack the packet in to bytes and then unpack bytes and then call compare method to check all the method implementation.
Randomization Sucessesfull. ---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- pkt1 Packet - pkt1@3 --da integral 8 'ha5 --sa integral 8 'ha1 --length integral 8 'h6 --data da(integral) 6 - ----[0] integral 8 'h58 ----[1] integral 8 'h60 ----[2] integral 8 'h34 ----[3] integral 8 'hdd ----[4] integral 8 'h9 ----[5] integral 8 'haf --fcs integral 8 'h75 ---------------------------------------------------------------------- Size of pkd bits 10 ---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- pkt2 Packet - pkt2@5 --da integral 8 'ha5 --sa integral 8 'ha1 --length integral 8 'h6 --data da(integral) 6 - ----[0] integral 8 'h58 ----[1] integral 8 'h60 ----[2] integral 8 'h34 ----[3] integral 8 'hdd ----[4] integral 8 'h9 ----[5] integral 8 'haf --fcs integral 8 'h75 ---------------------------------------------------------------------- Packing,Unpacking and compare worked