Adder Design
Adder Design
Adder design produces the resultant addition of two variables on the positive edge of the
clock. A reset signal is used to clear ‘out’ signal to 0.
Note: Adder can be easily developed with combinational logic. A clock and reset are
introduced to have the flavor of a clock and reset in testbench code.
module adder(input clk, reset, input [7:0] in1, in2, output reg [8:0]
out);
end
endmodule
Copy
Testbench Code
Transaction
The transaction is a packet that is driven to the DUT or monitored by the monitor as a
pin-level activity.
class transaction;
endclass
Copy
Generator
The generator creates or generates randomized transactions or stimuli and passes them
to the driver.
class generator;
int count;
mailbox gen_to_drv;
transaction tr;
this.gen_to_drv = gen_to_drv;
endfunction
task run;
repeat(count) begin
tr = new();
void'(tr.randomize());
gen_to_drv.put(tr);
end
endtask
endclass
Copy
Driver
The driver interacts with DUT. It receives randomized transactions from the generator
and drives them to the driven as a pin level activity.
class driver;
mailbox gen_to_drv;
transaction tr;
this.gen_to_drv = gen_to_drv;
this.vif = vif;
endfunction
task run;
forever begin
@(posedge vif.clk);
gen_to_drv.get(tr);
@(posedge vif.clk);
end
endtask
endclass
Copy
Monitor
The monitor observes pin-level activity on the connected interface at the input and
output of the design.
class monitor;
mailbox mon_to_sb;
this.vif = vif;
this.mon_to_sb = mon_to_sb;
endfunction
task run;
forever begin
transaction mon_tr;
wait(!vif.reset);
@(posedge vif.clk);
mon_tr = new();
mon_tr.ip1 = vif.ip1;
mon_tr.ip2 = vif.ip2;
@(posedge vif.clk);
mon_tr.out = vif.out;
mon_to_sb.put(mon_tr);
end
endtask
endclass
Copy
Agent
An agent is a container that holds the generator, driver, and monitor.
class agent;
driver drv;
monitor mon;
generator gen;
mailbox gen_to_drv;
gen_to_drv = new();
gen = new(gen_to_drv);
endfunction
task run();
fork
drv.run();
mon.run();
gen.run();
join_any
endtask
endclass
Copy
Scoreboard
The scoreboard receives the transaction packet from the monitor and compares it with
the reference model.
class scoreboard;
int compare_cnt;
mailbox mon_to_sb;
this.mon_to_sb = mon_to_sb;
endfunction
task run;
forever begin
transaction tr;
tr = new();
mon_to_sb.get(tr);
end
else begin
end
compare_cnt++;
end
endtask
endclass
Copy
Environment
An environment allows a well-mannered hierarchy and container for agents,
scoreboards.
class env;
agent agt;
scoreboard sb;
mailbox mon_to_sb;
mon_to_sb = new();
sb = new(mon_to_sb);
endfunction
task run();
fork
agt.run();
sb.run();
join_any
wait(agt.gen.count == sb.compare_cnt);
$finish;
endtask
endclass
Copy
Test
The test is at the top of the hierarchy that initiates the environment component
construction and connection between them.
program base_test(add_if vif);
env env_o;
initial begin
env_o = new(vif);
env_o.agt.gen.count = 5;
env_o.run();
end
endprogram
Copy
Testbench top
The testbench top is a top-level component that includes interface and DUT instances. It
connects design with the testbench.
module tb_top;
bit clk;
bit reset;
adder
DUT(.clk(vif.clk),.reset(vif.reset),.in1(vif.ip1),.in2(vif.ip2),.out(vi
f.out));
base_test t1(vif);
initial begin
clk = 0;
reset = 1;
#5;
reset = 0;
end
endmodule
Copy
Output:
Matched: ip1 = 44, ip2 = 30, out = 74