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


Tutorials



OVM TRANSACTION




A transaction is data item which is eventually or directly processed by the DUT. The packets, instructions, pixels are data items. In ovm, transactions are extended from ovm_transactions class or ovm_sequence_item class. Generally transactions are extended from ovm_transaction if randomization is not done in sequence and transactions are extended from ovm_sequence_item if the randomization is done in sequence. In this section, we will see ovm_transaction only, ovm_sequence_item will be addressed in another section.



(S)Example of a transaction:

class Packet extends ovm_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:



ovm_transaction class is extended from ovm_object. Ovm_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 ovm_object.

FIG: OVM 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 ovm, 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 `ovm_object_utils_begin and `ovm_object_utils_end macros.



(S) Example of field automation macros:

class Packet extends ovm_transaction;

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

`ovm_object_utils_begin(Packet)
`ovm_field_int(da, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(sa, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(length, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_array_int(data, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(fcs, OVM_ALL_ON|OVM_NOPACK)
`ovm_object_utils_end

endclass.


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




Each `ovm_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 ovm field automation flags:



By default, FLAG is set to OVM_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:

`ovm_field_int(da, OVM_ALL_ON|OVM_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 "ovm.svh"
import ovm_pkg::*;


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

class Packet extends ovm_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; }

constraint solve_size_length { solve data.size before length; }

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

`ovm_object_utils_begin(Packet)
`ovm_field_int(da, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(sa, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(length, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_array_int(data, OVM_ALL_ON|OVM_NOPACK)
`ovm_field_int(fcs, OVM_ALL_ON|OVM_NOPACK)
`ovm_object_utils_end

function void do_pack(ovm_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(ovm_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();
ovm_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


ovm_transaction.tar
Browse the code in ovm_transaction.tar


(S)Command to run the simulation


your_tool_simulation_command +path_to_ovm_pkg -packet.sv



(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
Ovm Testbench
Ovm Reporting
Ovm Transaction
Ovm Factory
Ovm Sequence 1
Ovm Sequence 2
Ovm Sequence 3
Ovm Sequence 4
Ovm Sequence 5
Ovm Sequence 6
Ovm Configuration

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