In phase 6 we will write a driver and then insatiate the driver in environment and send packet in to DUT. Driver class is defined in Driver.sv file.
In this Driver class, take the packets from the generator and then drives it to the DUT input interface and then send the packet to a channel for scoreboard purpose.
In this class, we also add 2 callback methods.
1) Extend vmm_xactor_callbacks to define Driver_callbacks. In this class, declare 2 methods pre_trans() and post_trans(). pre_trans() method is called before driving the packet transaction and post_trans() method will be called after driving the packet transaction.
class Driver_callbacks extends vmm_xactor_callbacks;
// Called before a transaction is executed
virtualtask pre_trans(Packet tr);
endtask: pre_trans
// Called after a transaction has been executed
virtualtask post_trans(Packet tr);
endtask: post_trans
endclass:Driver_callbacks
1) Extend vmm_xactor to define Driver class.
class Driver extends vmm_xactor;
2) Declare a virtual input_interface of the switch. We will connect this to the Physical interface of the top module same as what we did in environment class.
virtual input_interface.IP input_intf;
3) Define a channel "gen2drv_chan" which is used to get packets from generator.
Packet_channel gen2drv_chan;
4) Define a channel "drv2sb_chan" which is used to send the packets to the score board.
Packet_channel drv2sb_chan;
4) Define new constructor with arguments, virtual input interface and channels "gen2drv_chan" and "drv2sb_chan".
In the constructor, call the parent constructor and pass the instance name and stream_id.
Connect the channel and virtual interfaces which are passed as constructor arguments to the class members.
function new(string inst,
int stream_id = -1,
virtual input_interface.IP input_intf_new,
Packet_channel gen2drv_chan = null,
Packet_channel drv2sb_chan = null);
super.new("driver",inst,stream_id);
this.input_intf = input_intf_new;
if(gen2drv_chan == null)
`vmm_fatal(log,"gen2drv_channel is null");
else this.gen2drv_chan = gen2drv_chan;
if(drv2sb_chan == null)
`vmm_fatal(log,"drvr2sb_channel is null");
else this.drv2sb_chan = drv2sb_chan;
`vmm_note(log,"Driver created ");
endfunction
4)Define drive() method. This method drives the packet to the dut.
task drive(Packet pkt);
logic [7:0] pack[];
int pkt_len;
4) Define the main() method. First call the super.main() method.
super.main();
`vmm_note(this.log," started main task ");
5) In main() method, start a forever thread, which gets the packets from the 'gen2drv_chan' . The thread iteration has to be block if the channel is empty or stopped.
6) Call the drive() method, which drives the packet to DUT. Call the pre_tans() call back method using `vmm_callback macro before calling the drive method and post_trans() callback method after driving the packet.
`vmm_callback(Driver_callbacks,pre_trans(pkt));
drive(pkt);
`vmm_callback(Driver_callbacks,post_trans(pkt));
Driver Class Source Code:
`ifndef GUARD_DRIVER
`define GUARD_DRIVER
class Driver_callbacks extends vmm_xactor_callbacks;
// Called before a transaction is executed
virtualtask pre_trans(Packet tr);
endtask: pre_trans
// Called after a transaction has been executed
virtualtask post_trans(Packet tr);
endtask: post_trans
(S)Run the command: vcs -sverilog -f filelist -R -ntb_opts rvm
(S)Log file report.
******************* Start of testcase **************** Normal[NOTE] on Environemnt() at 0: Created env object Normal[NOTE] on Environemnt() at 0: Start of gen_cfg() method Normal[NOTE] on Environemnt() at 0: End of gen_cfg() method Normal[NOTE] on Environemnt() at 0: Start of build() method Normal[NOTE] on driver(Drvr) at 0: Driver created Normal[NOTE] on Environemnt() at 0: End of build() method Normal[NOTE] on Environemnt() at 0: Start of reset_dut() method Normal[NOTE] on Environemnt() at 60: End of reset_dut() method Normal[NOTE] on Environemnt() at 60: Start of cfg_dut() method Normal[NOTE] on Environemnt() at 90: Port 0 Address 00 Normal[NOTE] on Environemnt() at 110: Port 1 Address 11 Normal[NOTE] on Environemnt() at 130: Port 2 Address 22 Normal[NOTE] on Environemnt() at 150: Port 3 Address 33 Normal[NOTE] on Environemnt() at 170: End of cfg_dut() method Normal[NOTE] on Environemnt() at 170: Start of start() method Normal[NOTE] on Environemnt() at 170: End of start() method Normal[NOTE] on Environemnt() at 170: Start of wait_for_end() method Normal[NOTE] on driver(Drvr) at 170: started main task Normal[NOTE] on Environemnt() at 10170: End of wait_for_end() method Normal[NOTE] on Environemnt() at 10170: Start of stop() method Normal[NOTE] on Environemnt() at 10170: End of stop() method Normal[NOTE] on Environemnt() at 10170: Start of cleanup() method Normal[NOTE] on Environemnt() at 10170: End of cleanup() method Normal[NOTE] on Environemnt() at 10170: Start of report() method --------------------------------------------------------------------- Simulation PASSED on /./ (/./) at 10170 (0 warnings, 0 demoted errors & 0 demoted warnings) ---------------------------------------------------------------------
Normal[NOTE] on Environemnt() at 10170: End of report() method ******************** End of testcase *****************