task send_op(inputbyte iA, inputbyte iB, input operation_t iop, shortint result); if (iop == rst_op) begin @(posedge clk); reset_n = 1'b0; start = 1'b0; @(posedge clk); #1; reset_n = 1'b1; endelsebegin @(negedge clk); op_set = iop; A = iA; B = iB; start = 1'b1; if (iop == no_op) begin @(posedge clk); #1; start = 1'b0; endelsebegin do @(negedge clk); while (done == 0); start = 1'b0; end end// else: !if(iop == rst_op)
endtask : send_op
command_monitor command_monitor_h;
function operation_t op2enum(); case(op) 3'b000 : return no_op; 3'b001 : return add_op; 3'b010 : return and_op; 3'b011 : return xor_op; 3'b100 : return mul_op; default : $fatal("Illegal operation on op bus"); endcase// case (op) endfunction : op2enum
always @(posedge clk) begin : op_monitor staticbit in_command = 0; command_s command; if (start) begin : start_high if (!in_command) begin : new_command command.A = A; command.B = B; command.op = op2enum(); command_monitor_h.write_to_monitor(command); in_command = (command.op != no_op); end : new_command end : start_high else// start low in_command = 0; end : op_monitor
always @(negedge reset_n) begin : rst_monitor command_s command; command.op = rst_op; command_monitor_h.write_to_monitor(command); end : rst_monitor
result_monitor result_monitor_h;
initialbegin : result_monitor_thread foreverbegin @(posedge clk) ; if (done) result_monitor_h.write_to_monitor(result); end end : result_monitor_thread
initialbegin clk = 0; foreverbegin #10; clk = ~clk; end end endinterface : tinyalu_bfm
函数使用的时候通过接口对象调用就行了
1 2 3 4
virtual tinyalu_bfm inf; initialbegin inf.send_op(..); end