Dual Port Ram Using Uvm
Dual Port Ram Using Uvm
Output waveforms
logic[7:0]mem[0:15];
always@(posedge clk)
begin
if(rst==0)
begin
//dataout<=8'b0;
dataout1<=8'b0;
dataout2<=8'b0;
end
begin
mem[addr1]<=datain1;
mem[addr2]<=datain2;
end
else if(ps==2'b01)
begin
if(wr_en1==0)
mem[addr1]<=datain1;
dataout1<=mem[addr1];
end
else if(ps==2'b11)
begin
if(wr_en2==0)
mem[addr2]<=datain2;
dataout1<=mem[addr1];
end
end
endmodule
dual_SRAM vcode(.clk(vif.clk),.rst(vif.rst),.wr_en1(vif.wr_en1),.wr_en2(vif.wr_en2),.ps(vif.ps),
.datain1(vif.datain1), .datain2(vif.datain2),.addr1(vif.addr1),.addr2(vif.addr2),
.dataout1(vif.dataout1),.dataout2(vif.dataout2));
endmodule
INTERFACE
`include "uvm_macros.svh"
import uvm_pkg::*;
logic wr_en1;
logic wr_en2;
logic[1:0] ps;
endinterface
`uvm_object_utils(seq_item)
bit wr_en1,wr_en2;
bit[1:0] ps;
super.new(name);
endfunction
/*
`uvm_object_utils_begin(seq_item)
`uvm_field_int(addr1,UVM_ALL_ON)
`uvm_field_int(addr2,UVM_ALL_ON)
`uvm_field_int(wr_en1,UVM_ALL_ON)
`uvm_field_int(wr_en2,UVM_ALL_ON)
`uvm_field_int(ps,UVM_ALL_ON)
`uvm_field_int(dataout1,UVM_ALL_ON)
`uvm_field_int(dataout2,UVM_ALL_ON)
`uvm_field_int(datain1,UVM_ALL_ON)
`uvm_field_int(datain2,UVM_ALL_ON)
`uvm_object_utils_end
*/
Endclass
`uvm_object_utils(base_seq)
super.new(name);
endfunction
endclass
`uvm_object_utils(mode_1)
seq_item pkt;
super.new(name);
endfunction
task body();
begin
repeat(7) begin
pkt = seq_item::type_id::create("pkt");
start_item(pkt);
assert(pkt.randomize());
pkt.ps=2'b00 ;
pkt.wr_en1 = 0;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
start_item(pkt);
pkt.ps=2'b00;
pkt.wr_en2 = 1;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
end
end
endtask
endclass
seq_item pkt;
super.new(name);
endfunction
task body();
begin
repeat(7) begin
pkt = seq_item::type_id::create("pkt");
start_item(pkt);
assert(pkt.randomize());
pkt.ps=2'b01;
pkt.wr_en1 = 0;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
start_item(pkt);
pkt.ps=2'b01;
pkt.wr_en1 = 1;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
end
end
endtask
endclass
`uvm_object_utils(mode_3)
seq_item pkt;
super.new(name);
endfunction
task body();
begin
repeat(7) begin
pkt = seq_item::type_id::create("pkt");
start_item(pkt);
assert(pkt.randomize());
pkt.ps=2'b10;
pkt.wr_en2 = 0;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
start_item(pkt);
pkt.ps=2'b10;
pkt.wr_en2 = 1;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
end
end
endtask
endclass
`uvm_object_utils(mode_4)
seq_item pkt;
super.new(name);
endfunction
task body();
begin
repeat(7) begin
pkt = seq_item::type_id::create("pkt");
start_item(pkt);
assert(pkt.randomize());
pkt.ps = 2'b11;
pkt.wr_en1 = 1;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
start_item(pkt);
pkt.ps = 2'b11;
pkt.wr_en2 = 0;
//pkt.print(uvm_default_line_printer);
finish_item(pkt);
end
end
endtask
endclass
SEQUENCE
`uvm_object_utils(base_seq)
super.new(name);
endfunction
endclass
SEQUENCER
`uvm_component_utils(sequencer)
function new(string name = "sequencer", uvm_component parent);
super.new(name,parent);
endfunction
endclass
DRIVER
`uvm_component_utils(driver)
seq_item pkt;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
pkt = seq_item::type_id::create("pkt");
forever
begin
seq_item_port.get_next_item(pkt);
@(posedge vif.clk);
if(pkt.ps == 2'b00)
begin
if(pkt.wr_en1==0)
begin
vif.wr_en1 = pkt.wr_en1;
vif.addr1 = pkt.addr1;
vif.datain1 = pkt.datain1;
end
else if(pkt.wr_en2==1)
begin
vif.wr_en2= pkt.wr_en2;
vif.addr2 = pkt.addr2;
end
end
if(pkt.ps== 2'b01)
begin
if(pkt.wr_en1==0)
begin
vif.wr_en1 = pkt.wr_en1;
vif.addr1 = pkt.addr1;
vif.datain1 = pkt.datain1;
//vif.addr1 = pkt.addr1;
$display($time," Packet driven with addr1 = %d,datain1=%d",pkt.addr1,pkt.datain1);
end
begin
vif.wr_en = pkt.wr_en;
vif.read_port = pkt.read_port;
if(pkt.write_port ==0)
vif.addr2 = pkt.addr1;
vif.addr2 = pkt.addr2;
end*/
else if(pkt.wr_en1==1)
begin
vif.addr2 = pkt.addr2;
end
end
if(pkt.ps== 2'b10)
begin
if(pkt.wr_en2==0)
begin
vif.wr_en2 = pkt.wr_en2;
vif.addr2= pkt.addr2;
vif.datain2 = pkt.datain2;
//vif.addr1 = pkt.addr1;
end
else if(pkt.wr_en2==1)
begin
vif.addr2 = pkt.addr2;
end
end
if(pkt.ps== 2'b11)
begin
if(pkt.wr_en1==1)
begin
vif.wr_en1 = pkt.wr_en1;
// vif.addr2= pkt.addr2;
vif.datain1 = pkt.datain1;
//vif.addr1 = pkt.addr1;
end
else if(pkt.wr_en2==0)
begin
vif.wr_en2 = pkt.wr_en2;
vif.addr2 = pkt.addr2;
vif.datain2 = pkt.datain2;
$display($time,"Packet driven with addr2 = %d, datain2 = %d",pkt.addr2, pkt.datain2);
end
end
seq_item_port.item_done();
end
endtask
endclass
MONITOR1
`uvm_component_utils(monitor1)
seq_item pkt;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
forever
begin
@(posedge vif.clk);
pkt.wr_en1= vif.wr_en1;
pkt.wr_en2= vif.wr_en2;
pkt.ps = vif.ps;
if(pkt.ps==2'b00)
begin
if(pkt.wr_en1 ==0)
begin
pkt.addr1 = vif.addr1;
pkt.datain1 = vif.datain1;
analysis_port1.write(pkt);
end
begin
pkt.addr2 = vif.addr2;
pkt.datain2 = vif.datain2;
analysis_port1.write(pkt);
end
end
if(pkt.ps==2'b01)
begin
if(pkt.wr_en1 ==0)
begin
pkt.addr1 = vif.addr1;
pkt.datain1 = vif.datain1;
analysis_port1.write(pkt);
end
begin
pkt.addr2 = vif.addr2;
//pkt.datain2 = vif.datain2;
analysis_port1.write(pkt);
end
end
if(pkt.ps==2'b10)
begin
if(pkt.wr_en2 ==0)
begin
pkt.addr2 = vif.addr2;
pkt.datain2 = vif.datain2;
analysis_port1.write(pkt);
end
begin
pkt.addr2 = vif.addr2;
//pkt.datain2 = vif.datain2;
analysis_port1.write(pkt);
end
end
if(pkt.ps==2'b11)
begin
if(pkt.wr_en1 ==1)
begin
pkt.addr1 = vif.addr1;
//pkt.datain1 = vif.datain1;
analysis_port1.write(pkt);
end
begin
pkt.addr2 = vif.addr2;
pkt.datain2 = vif.datain2;
analysis_port1.write(pkt);
end
end
end
endtask
endclass
MONITOR2
`uvm_component_utils(monitor2)
seq_item pkt1;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
pkt1 = seq_item::type_id::create("pkt1");
forever
begin
@(posedge vif.clk);
pkt1.wr_en1 = vif.wr_en1;
pkt1.wr_en2 = vif.wr_en2;
pkt1.ps = vif.ps;
if(pkt1.wr_en1 ==1)
begin
begin
pkt1.addr1 = vif.addr1;
pkt1.dataout1 = vif.dataout1;
analysis_port2.write(pkt1);
end
begin
pkt.addr2 = vif.addr2;
pkt.dataout = vif.dataout;
analysis_port2.write(pkt);
end*/
end
else if(pkt1.wr_en2==1)
begin
begin
pkt1.addr2 = vif.addr2;
pkt1.dataout2 = vif.dataout2;
analysis_port2.write(pkt1);
end
end
end
endtask
endclass
AGENT1
`uvm_component_utils(agent1)
driver drv;
sequencer seqr;
monitor1 mon1;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
super.connect_phase(phase);
drv.seq_item_port.connect(seqr.seq_item_export);
endfunction
endclass
AGENT2
`uvm_component_utils(agent2)
monitor2 mon2;
function new(string name = "agent2", uvm_component parent);
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
endclass
SCOREBOARD
`uvm_component_utils(scoreboard)
int datain1_queue[$];
int datain2_queue[$];
uvm_tlm_analysis_fifo#(seq_item) ip_fifo;
uvm_tlm_analysis_fifo#(seq_item) op_fifo;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
super.run_phase(phase);
pkt = seq_item::type_id::create("pkt1");
pkt1= seq_item::type_id::create("pkt2");
forever
begin
fork
ip_fifo.get(pkt);
op_fifo.get(pkt1);
join
datain1_queue.push_front(pkt.datain1);
datain2_queue.push_front(pkt.datain2);
$display("compare task starting");
compare();
end
endtask
task compare();
begin
@(pkt.dataout1)
$display("Packets to scr");
if(pkt.dataout1 == pkt1.dataout1)
`uvm_info(get_full_name(),$sformatf("Matched pkt.datain1=%d,pkt1.dataoout2=
%d",pkt.datain1,pkt1.dataout2),UVM_NONE)
else
@(pkt.dataout2)
$display("Packets to scr");
if(pkt.dataout2 == pkt1.dataout2)
else
`uvm_error(get_full_name(), "Mis-Matched;; data")
end
endtask
endclass
ENVIRONMENT
`uvm_component_utils(environment)
scoreboard sb;
agent1 agt1;
agent2 agt2;
super.new(name,parent);
endfunction
super.build_phase(phase);
sb=scoreboard::type_id::create("sb",this);
agt1=agent1::type_id::create("agt1",this);
agt2=agent2::type_id::create("agt2",this);
endfunction
super.connect_phase(phase);
agt1.mon1.analysis_port1.connect(sb.ip_fifo.analysis_export);
agt2.mon2.analysis_port2.connect(sb.op_fifo.analysis_export);
endfunction
endclass
TEST1
`uvm_component_utils(my_test1)
environment env;
super.new(name,parent);
endfunction
mode_1 bs;
super.build_phase(phase);
endfunction
super.end_of_elaboration_phase(phase);
this.print();
endfunction
super.run_phase(phase);
bs = mode_1::type_id::create("bs");
phase.raise_objection(this);
bs.start(env.agt1.seqr);
#20;
phase.drop_objection(this);
endtask
endclass
TEST2
`uvm_component_utils(my_test2)
environment env;
super.new(name,parent);
endfunction
mode_2 bs;
super.build_phase(phase);
endfunction
super.end_of_elaboration_phase(phase);
this.print();
endfunction
super.run_phase(phase);
bs = mode_2::type_id::create("bs");
phase.raise_objection(this);
bs.start(env.agt1.seqr);
#20;
phase.drop_objection(this);
endtask
endclass
TEST3
`uvm_component_utils(my_test3)
environment env;
super.new(name,parent);
endfunction
mode_3 bs;
super.build_phase(phase);
endfunction
super.end_of_elaboration_phase(phase);
this.print();
endfunction
super.run_phase(phase);
bs = mode_3::type_id::create("bs");
phase.raise_objection(this);
bs.start(env.agt1.seqr);
#20;
phase.drop_objection(this);
endtask
endclass
TEST4
`uvm_component_utils(my_test4)
environment env;
mode_4 bs;
super.new(name,parent);
endfunction
super.build_phase(phase);
endfunction
super.end_of_elaboration_phase(phase);
this.print();
endfunction
super.run_phase(phase);
bs = mode_4::type_id::create("bs");
phase.raise_objection(this);
bs.start(env.agt1.seqr);
#20;
phase.drop_objection(this);
endtask
endclass
`include "uvm_macros.svh"
`include "dual_intrf.sv"
`include "dual_dutuv.sv"
`include "dual_design.sv"
`include "dual_sequence_item.sv"
`include "dual_sequence.sv"
`include "sequence_mode1.sv"
`include "sequence_mode2.sv"
`include "sequence_mode3.sv"
`include "sequence_mode4.sv"
`include "sequencer.sv"
`include "dual_driver.sv"
`include "dual_monitor1.sv"
`include "dual_monitor2.sv"
`include "dual_agent1.sv"
`include "dual_agent2.sv"
`include "dual_scbd.sv"
`include "dual_envmt.sv"
`include "dual_test1.sv"
`include "dual_test2.sv"
`include "dual_test3.sv"
`include "dual_test4.sv"
TOP MODULE
module top;
bit clk,rst;
initial begin
clk = 0;
forever
#5 clk = ~clk;
end
initial
begin
rst = 0;
#4;
rst = 1;
end
DUT dut(vif);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
run_test("my_test1");
end
endmodule
My_test1:
----------------------------------------------------------------
# UVM-1.0p1
# ----------------------------------------------------------------
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# arbitration_queue array 0 -
# lock_queue array 0 -
# sb scoreboard - @477
# UVM_INFO : 21
# UVM_WARNING : 0
# UVM_ERROR : 0
# UVM_FATAL : 0
# ** Report counts by id
# [RNTST] 1
# [TEST_DONE] 1
# [mon1] 16
# [uvm_test_top.env.sb] 3
#1
My_test2:
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# arbitration_queue array 0 -
# lock_queue array 0 -
# sb scoreboard - @477
# ------------------------------------------------------------------
# UVM_INFO C:/questasim_10.0b/verilog_src/uvm-1.0p1/src/base/uvm_objection.svh(1116) @
155: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
# UVM_INFO : 21
# UVM_WARNING : 0
# UVM_ERROR : 0
# UVM_FATAL : 0
# ** Report counts by id
# [RNTST] 1
# [TEST_DONE] 1
# [mon1] 16
# [uvm_test_top.env.sb] 3
My_test3:
UVM_INFO @ 0: reporter [RNTST] Running test my_test3...
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# arbitration_queue array 0 -
# lock_queue array 0 -
# sb scoreboard - @477
# ------------------------------------------------------------------
# UVM_INFO : 21
# UVM_WARNING : 0
# UVM_ERROR : 0
# UVM_FATAL : 0
# ** Report counts by id
# [RNTST] 1
# [TEST_DONE] 1
# [mon1] 16
# [uvm_test_top.env.sb] 3