diff options
Diffstat (limited to 'midterm/SRC/bfm.sv')
| -rw-r--r-- | midterm/SRC/bfm.sv | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/midterm/SRC/bfm.sv b/midterm/SRC/bfm.sv new file mode 100644 index 0000000..2d81ad6 --- /dev/null +++ b/midterm/SRC/bfm.sv @@ -0,0 +1,53 @@ +import typedef_pkg::*; + +class bfm; + localparam int TOTAL_TESTS = 4 * 256 * 256; + + virtual intf alu_if; + transaction tr; + + function new(virtual intf alu_if_in, transaction tr_in); + alu_if = alu_if_in; + tr = tr_in; + endfunction + + task drive(); + for (int op_i = 0; op_i < 4; op_i++) begin + for (int a_i = 0; a_i < 256; a_i++) begin + for (int b_i = 0; b_i < 256; b_i++) begin + automatic operation_t op_val = operation_t'(op_i[1:0]); + automatic operand_t a_val = operand_t'(a_i[7:0]); + automatic operand_t b_val = operand_t'(b_i[7:0]); + + `RND_CHECK(std::randomize(tr.operation, tr.operand_a, tr.operand_b) with { + tr.operation == op_val; + tr.operand_a == a_val; + tr.operand_b == b_val; + }) + drive_trxn(); + end + end + end + + $display("BFM drive complete. Total tests: %0d", TOTAL_TESTS); + endtask + + task drive_trxn(); + @(negedge alu_if.clk); + + alu_if.op_start = 1'b1; + alu_if.operation = tr.operation; + alu_if.operand_a = tr.operand_a; + alu_if.operand_b = tr.operand_b; + + @(negedge alu_if.clk); + + alu_if.op_start = 1'b0; + + @(posedge alu_if.clk); + @(posedge alu_if.clk); + @(negedge alu_if.clk); + + tr.actual_result = alu_if.result; + endtask +endclass |