Sie sind auf Seite 1von 4

module and_gate(input a, input b, output reg c);

always @(a,b)
begin
c= a&b;
end
endmodule
/////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
class packet;
rand bit a;
rand bit b;
bit c;
endclass

/////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
class generator;
packet pkt;
mailbox #(packet)gen_drv;
function new(mailbox #(packet)gen_drv);
this.gen_drv=gen_drv;
endfunction
task run;
pkt=new();
if(pkt.randomize())
begin
gen_drv.put(pkt);
end
else $display("randomization failed");
endtask
endclass

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
class driver;
packet pkt;
mailbox #(packet) gen_drv;
mailbox #(packet) drv_scb;

virtual intf i;
function new(mailbox #(packet) gen_drv, mailbox #(packet) drv_scb,
virtual intf i);

this.gen_drv = gen_drv;
this.drv_scb = drv_scb;
this.i = i;
endfunction

task run();

gen_drv.get(pkt);
drv_scb.put(pkt);
i.a = pkt.a;
i.b = pkt.b;
i.c = pkt.c;

endtask
endclass
/////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

interface intf;
bit a,b,c;

endinterface
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

class monitor;

packet pkt;
mailbox #(packet) mon_scb;
virtual intf i;

function new(mailbox #(packet) mon_scb, virtual intf i);


this.mon_scb = mon_scb;
this.i = i;
endfunction

task run;
pkt = new();
pkt.a = i.a;
pkt.b = i.b;
pkt.c = i.c;
mon_scb.put(pkt);
endtask
endclass
/////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

class scoreboard;

packet pkt1, pkt2;


mailbox #(packet) drv_scb;
mailbox #(packet) mon_scb;

function new(mailbox #(packet) drv_scb, mailbox #(packet) mon_scb);


this.drv_scb = drv_scb;
this.mon_scb = mon_scb;

endfunction

task run;
drv_scb.get(pkt1);
mon_scb.get(pkt2); //comming from DUT
pkt1.c = pkt1.a & pkt1.b;
if(pkt1.c == pkt2.c) begin
$display("PASS\n");
$display("Actual Output is c = %b, a= %b, b= %b\n", pkt2.c,
pkt2.a,pkt2.b);
$display("Expected Output is c = %b, a=%b, b=%b", pkt1.c,
pkt1.a,pkt1.b);
end
else begin
$display("FAIL");
end
endtask
endclass
/////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

class environment;

mailbox #(packet) gen_drv;


mailbox #(packet) drv_scb;
mailbox #(packet) mon_scb;
virtual intf i;

generator g_and;
driver d_and;
monitor m_and;
scoreboard s_and;

function new(virtual intf i);


this.i =i;
endfunction

function build();
gen_drv =new();
drv_scb = new();
mon_scb = new();

g_and = new(gen_drv);
d_and = new(gen_drv, drv_scb, i);
m_and = new(mon_scb,i);
s_and = new(drv_scb, mon_scb);
endfunction

task run();
g_and.run();
d_and.run();
m_and.run();
s_and.run();
endtask
endclass
/////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

program test(intf i);


environment e_and;
initial
begin
e_and = new(i);
e_and.build();

repeat(5)
begin
e_and.run();
end
end
endprogram
/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

module top();
intf i();
and_gate a1(.a(i.a), .b(i.b), .c(i.c));
test t1(i);

endmodule
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

Das könnte Ihnen auch gefallen