这里参考特权同学的模块化思想,将常用的print等任务模块化,便于直接调用,提高代码的效率和易读性。现转载之,以供日后的学习和工作参考。
print模块参考代码如下:
//=================================//
//useful print_task show
//include error,warning,fatal,terminate,etc
module print_task();
//Show Warning Report
task warning;
input [80*8:1] msg;
begin
$write("WARNING at %t : %s",$time,msg);
end
endtask
//Show Error Report
task error;
input [80*8:1] msg;
begin
$write("-ERROR- at %t : %s",$time,msg);
end
endtask
//Show Fatal Report
task fatal;
input [80*8:1] msg;
begin
$write("*FATAL* at %t : %s",$time,msg);
$write("Simulation false\n");
$stop;
end
endtask
task terminate;
begin
$write("Simulate completed\n");
$stop;
end
endtask
endmodule
调用print模块参考:
//test print_task.v
module testcase();
.....
print_task print(); //instance
.....
initial
begin
print.error("Unexpected response\n");
print.terminate;
end
endmodule
//================================//
对于常用的reset复位模块,也可以将其任务化:
//================================//
//reset module
module test();
.....
initial
begin
reset_task(100); //reset 100ns
end
.....
task reset_task;
input [15:0] reset_time; //Difine reset time
begin
reset = 0;
# reset_time;
reset = 1;
end
endtask
......
endmodule
//================================//