|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



UVM TRANSACTION




A transaction is data item which is eventually or directly processed by the DUT. The packets, instructions, pixels are data items. In uvm, transactions are extended from uvm_transactions class or uvm_sequence_item class. uvm_transaction is a typedef of uvm_sequence_item.



(S)Example of a transaction:

class Packet extends uvm_transaction;
rand bit [7:0] da;
rand bit [7:0] sa;
rand bit [7:0] length;
rand bit [7:0] data[];
rand byte fcs;
endclass


Core Utilities:



uvm_transaction class is extended from uvm_object. uvm_transaction adds more features line transaction recording , transaction id and timings of the transaction.

The methods used to model, transform or operate on transactions like print, copying, cloning, comparing, recording, packing and unpacking are already defined in uvm_object.

FIG: UVM OBJECT UTILITIES



User Defined Implementations:



User should define these methods in the transaction using do_<method_name> and call them using <method_name>. Following table shows calling methods and user-defined hook do_<method_name> methods. Clone and create methods, does not use hook methods concepts.





Shorthand Macros:



Using the field automation concept of uvm, all the above defines methods can be defined automatically.
To use these field automation macros, first declare all the data fields, then place the field automation macros between the `uvm_object_utils_begin and `uvm_object_utils_end macros.



(S) Example of field automation macros:

class Packet extends uvm_transaction;

rand bit [7:0] da;
rand bit [7:0] sa;
rand bit [7:0] length;
rand bit [7:0] data[];
rand byte fcs;

`uvm_object_utils_begin(Packet)
`uvm_field_int(da, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(sa, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(length, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_array_int(data, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(fcs, UVM_ALL_ON|UVM_NOPACK)
`uvm_object_utils_end

endclass.


For most of the data types in systemverilog, uvm defined corresponding field automation macros. Following table shows all the field automation macros.




Each `uvm_field_* macro has at least two arguments: ARG and FLAG.
ARG is the instance name of the variable and FLAG is used to control the field usage in core utilities operation.

Following table shows uvm field automation flags:



By default, FLAG is set to UVM_ALL_ON. All these flags can be ored. Using NO_* flags, can turn of particular field usage in a paerticuler method. NO_* flags takes precedency over other flags.


(S)Example of Flags:

`uvm_field_int(da, UVM_ALL_ON|UVM_NOPACK)


The above macro will use the field "da" in all utilities methods except Packing and unpacking methods.


(S)Lets see a example:


In the following example, all the utility methods are defined using field automation macros except Packing and unpacking methods. Packing and unpacking methods are done in do_pack() amd do_unpack() method.



`include "uvm.svh"
import uvm_pkg::*;


//Define the enumerated types for packet types
typedef enum { GOOD_FCS, BAD_FCS } fcs_kind_t;

class Packet extends uvm_transaction;

rand fcs_kind_t fcs_kind;

rand bit [7:0] length;
rand bit [7:0] da;
rand bit [7:0] sa;
rand bit [7:0] data[];
rand byte fcs;

constraint payload_size_c { data.size inside { [1 : 6]};}

constraint length_c { length == data.size; }

function new(string name = "");
super.new(name);
endfunction : new

function void post_randomize();
if(fcs_kind == GOOD_FCS)
fcs = 8'b0;
else
fcs = 8'b1;
fcs = cal_fcs();
endfunction : post_randomize

///// method to calculate the fcs /////
virtual function byte cal_fcs;
integer i;
byte result ;
result = 0;
result = result ^ da;
result = result ^ sa;
result = result ^ length;
for (i = 0;i< data.size;i++)
result = result ^ data[i];
result = fcs ^ result;
return result;
endfunction : cal_fcs

`uvm_object_utils_begin(Packet)
`uvm_field_int(da, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(sa, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(length, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_array_int(data, UVM_ALL_ON|UVM_NOPACK)
`uvm_field_int(fcs, UVM_ALL_ON|UVM_NOPACK)
`uvm_object_utils_end

function void do_pack(uvm_packer packer);
super.do_pack(packer);
packer.pack_field_int(da,$bits(da));
packer.pack_field_int(sa,$bits(sa));
packer.pack_field_int(length,$bits(length));
foreach(data[i])
packer.pack_field_int(data[i],8);
packer.pack_field_int(fcs,$bits(fcs));
endfunction : do_pack

function void do_unpack(uvm_packer packer);
int sz;
super.do_pack(packer);

da = packer.unpack_field_int($bits(da));
sa = packer.unpack_field_int($bits(sa));
length = packer.unpack_field_int($bits(length));

data.delete();
data = new[length];
foreach(data[i])
data[i] = packer.unpack_field_int(8);
fcs = packer.unpack_field_int($bits(fcs));
endfunction : do_unpack

endclass : Packet


/////////////////////////////////////////////////////////
//// Test to check the packet implementation ////
/////////////////////////////////////////////////////////
module test;

Packet pkt1 = new("pkt1");
Packet pkt2 = new("pkt2");
byte unsigned pkdbytes[];

initial
repeat(10)
if(pkt1.randomize)
begin
$display(" Randomization Sucessesfull.");
pkt1.print();
uvm_default_packer.use_metadata = 1;
void'(pkt1.pack_bytes(pkdbytes));
$display("Size of pkd bits %d",pkdbytes.size());
pkt2.unpack_bytes(pkdbytes);
pkt2.print();
if(pkt2.compare(pkt1))
$display(" Packing,Unpacking and compare worked");
else
$display(" *** Something went wrong in Packing or Unpacking or compare *** \n \n");
end
else
$display(" *** Randomization Failed ***");

endmodule


(S)Download the source code


uvm_transaction.tar
Browse the code in uvm_transaction.tar


(S)Command to run the simulation


VCS Users : make vcs
Questa Users: make questa



(S)Log report:





Randomization Sucessesfull. ---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- pkt1 Packet - pkt1@3 da integral 8 'h1d sa integral 8 'h26 length integral 8 'h5 data da(integral) 5 - [0] integral 8 'hb1 [1] integral 8 'h3f [2] integral 8 'h9e [3] integral 8 'h38 [4] integral 8 'h8d fcs integral 8 'h9b ---------------------------------------------------------------------- Size of pkd bits 9 ---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- pkt2 Packet - pkt2@5 da integral 8 'h1d sa integral 8 'h26 length integral 8 'h5 data da(integral) 5 - [0] integral 8 'hb1 [1] integral 8 'h3f [2] integral 8 'h9e [3] integral 8 'h38 [4] integral 8 'h8d fcs integral 8 'h9b ---------------------------------------------------------------------- Packing,Unpacking and compare worked






Index
Introduction
Uvm Testbench
Uvm Reporting
Uvm Transaction
Uvm Configuration
Uvm Factory
Uvm Sequence 1
Uvm Sequence 2
Uvm Sequence 3
Uvm Sequence 4
Uvm Sequence 5
Uvm Sequence 6
Uvm Tlm 1
Uvm Tlm 2
Uvm Callback

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer