SV Lab Manual
SV Lab Manual
Lab Manual
CONTENTS
LAB1: DATATYPES
LAB2: INTERFACE
Objective: Understand the usage of Class, Basics of OOP such as handle assignment
Objective: Understand deep copy, inheritance and the usage of virtual functions
(polymorphism)
LAB5: RANDOMIZATION
LAB7: TRANSACTION
LAB8: TRANSACTORS
Objective: Understand the usage of transactors like generator, driver, monitor and
reference model
LAB9: SCOREBOARD
LAB10: ENVIRONMENT
LAB2 : INTERFACES
o Define the module and pass the driver interface instance argument
o Include the read and write tasks provided within the driver module
o Define the module and pass the monitor interface instance argument
o Declare an associative array(mem) of bit type(64 bits) indexed by int
o In always block
if write operation
Update the associative array based on interface write
address and data
For eg :
mem[mon_if.mon_cb.wr_address]=mon_if.mon_cb.data_in
If read operation call the check task provided and pass the read
address and data_out from the interface
Understand and include the check task that compares the actual
data from the DUT and expected data(saved in associative array)
o Within initial
Perform 10 write operations by calling the driver write task to the
first 10 address locations (incremental)
o Perform 10 read operations by calling the driver read task
Expectation : Run the Simulation in the GUI mode. Observe 10 write transactions
followed by 10 read transactions w.r.t RAM DUT signals on the
waveform.
In Handle_Object.sv
Expectation : Assigning Class handles. Assigning one class handle to another does
not perform copy, instead both the handles point to the same object.
o In class parity_calc_c
Declare parity (bit type, size 8)
Write copy method that returns parity_calc_c class type
Create copy instance
Copy all the current properties into copy object
o In class packet_c
Declare header (bit type , size 8), initialize it with some default
value
Declare data (bit type , size 8), initialize it with some default value
Create parity_calc_c instance
Write copy method that returns packet_c class type
Create copy instance
Copy all the current properties into copy object
o Within initial
Create pkt_h1 object
Use shallow copy method to copy pkt_h1 to pkt_h2
Display the parent class and subclass properties of pkt_h1 and
pkt_h2
Use %p to display class contents
Assign random value to the header of pkt_h2
Display the parent class and subclass properties of pkt_h1 and
pkt_h2
Observe pkt_h1.header does not change (Shallow Copy)
Change parity of pkt_h2 using the subclass handle from the class
packet_c
Ex : pkt_h2.sub_par_h.parity=19;
o In class account_c
Declare balance as int type and initialize it with value 20
In the function summary_deposit ,return balance
In the task deposit,
Pass an input argument pay(int type)
Add pay with previous balance
Extend class account_c1 from account_c
Override balance as int type and initialize it with value 30
In function summary,
o The new balance returned should be a summation
of the base class balance and derived class
balance
o Hint : Use super to access balance from base class
Within initial
Construct extended class object
Pass the amount for the method deposit and call method
summary_deposit to display balance
Call method summary to display balance
o Observe that the super.balance returns the base
class balance
Expectation : Inheritance and accessing the base class members from the extended
class, when the members are overridden.
o In class packet_c
In task send
Display message “Sending base class packet”
o Within initial
Create instances for badpacket_c and packet_c
Call send tasks using base and extended handles
Assign extended class handle to base class handle
Call send task using base class handle
Observe that the base class send task is called instead of
the extended class send task even though the base class
handle is pointing to the extended class handle
Expectation : Behaviour of base class methods when they are overridden in the
extended class. Assigning an extended class method to the base class
method does not invoke the extended class overrriden method using
the base class handle.
Working directory : ../labs/lab04
Expectation : By making the base class methods virtual, the overridden methods in
the extended class can be accessed using the base class handle.
LAB 5 - RANDOMIZATION
o Within initial
Create an instance of alu_trans_c
Generate 10 set of random values for the instance alu_trans_c
Randomize using 'assert' or 'if' construct
Execute the file using : qverilog Constraints.sv
Expectation : Observe that 10 different random values have been generated which is
based on the written constraints.
In class generator
o Declare an handle of packet class
o Declare the mailbox parameterized by type class packet
o In constructor
Pass the mailbox parameterized by packet as an argument
Assign the mailbox handle to the argument
o In task start
Generate 10 random packets
Randomize using assert
Put the generated random packets into the mailbox
In class driver
o Declare an handle of packet class
o Declare a mailbox parameterized by type class packet
o In constructor
Pass the mailbox parameterized by packet as an argument
Assign the mailbox handle to the argument
o In task start
Get the 10 generated random packets from the mailbox
Use display method in the packet class to display the
received data
In class env
o Create the mailbox instance parameterized by packet
o Declare handles of generator and driver
o In build function
Create instance of generator and driver by passing mailbox as an
input argument
o In task start
Call start task of generator and driver within fork join
In class driver
o Write task send with an input argument of string type
Get the key using semaphore handle
Display the string which indicates the respective driver
information
Put the key using sem handle
Display the string which indicates the respective driver
information
Expectation : Usage of Semaphore where two drivers want to drive the same
interface. Semaphores are used to synchronise between different
components trying to access the same channel for communication.
LAB 7 – TRANSACTION
In ram_trans.sv
Declare class ram_trans and add the following
o Declare the following rand fields
data (bit/logic type , size 64)
rd_address, wr_address (bit/logic type , size 12)
read, write (bit/logic type , size 1)
o Declare a variable data_out (logic type , size 64)
o Static variable trans_id (int type), to keep the count of transactions
generated
o Declare static variables no_of_read_trans, no_of_write_trans and
no_of_RW_trans, to keep the count of transactions generated
o Add the following constraints
wr_address!=rd_address;
read,write != 2'b00;
data between 1 and 4294967295
o In display method
Display the string
Display all the properties of the transaction class
o In post_randomize method
If it is only read transaction, increment no_of_read_trans
If it is only write transaction, increment no_of_write_trans
If it is read-write transaction, increment no_of_RW_trans
call the display method and pass a string
Expectation : Implementation of Generator, Write & Read BFMs, Write and Read
Monitors. Write BFM gets the transaction data from the Generator and drives the
interface according to the Write protocol. Read BFM gets the transaction data from
the Generator and drives the interface according to the Read protocol.
Write Monitor samples the interface signals according to the write protocol and
convert interface signals into transactions required by the reference model.
Read Monitor samples the interface signals according to the read protocol and
convert interface signals into transactions required by the scoreboard to generate the
actual data and the reference model to generate the expected data.
LAB 9 - SCOREBOARD
LAB 10 – ENVIRONMENT
Objective: Understand the usage of environment
In class ram_env
o Declare virtual interfaces with Write BFM modport, Read BFM modport,
Write monitor modport, Read monitor modport
o Declare 6 mailboxes parameterized by ram_trans and construct it
o Create handle for ram_gen, ram_read_bfm, ram_write_bfm,
ram_read_mon, ram_write_mon , ram_model and ram_sb
o Declare an event
o In constructor
pass the BFM and monitor interface instances as the argument
connect the properties of ram_env
o In build task
Create instances for generator, Read BFM, Write BFM, Write
monitor, Read monitor, Reference model, Scoreboard
o In virtual task start
call the task start of generator, Read BFM, Write BFM, Read
monitor, Write Monitor, reference model, scoreboard
o In run task
Call the provided reset_dut task , start and stop tasks
Using scoreboard handle call report task
Three testcases are provided in ../lab10/test, make TC1 and make TC2 for
executing test1.sv and test2.sv
Expectation : Integration of the testbench components with the DUT and Interface. Re-using
the same testbench environment and creating different testcases TC1, TC2, TC3
etc..to drive different type of stimulus. TC1 drives base transactions, TC2 drives
short transactions, and so on..using the same testbench components and
controlling by polymorphism within the testcases.