在tb中需要dump_wave
例:
// dump_wave
`ifndef NC_VERILOG
initial begin
$fsdbDumpfile("wave.fsdb");
$fsdbDumpMDA();
$fsdbDumpvars;
end
`else
initial begin
$shm_open("wave.shm");
$shm_probe(test_tb,"ACM");
end
`endif
在tb中若需要读取文件,则调用$fopen、$fgets()、$fclose等系统函数
例:
integer file_descriptor;
string line;
initial begin
//open the file
file_descriptor = $fopen("test.txt", "r");
// check the file open successfully
if(file_descriptor == 0) begin
$display("Error:Could not open file.");
$finish;
end
else begin
$display("Successfully open the file.");
// read the file until ending
while(!feof(file_descriptor)) begin
$fgets(line, file_descriptor);
// print the read line
$display("%s", line);
end
// close the file
$fclose(file_descriptor);
end
end
注:网上很多资料$fgets()系统函数是先file_descriptor后line的,ai搜索的很多资料也是,这里留个疑问!
当写好RTL和TEST_BENCH后,写flist.f文件让仿真软件吃进去
例:
RTL:test.v
TESTBENCH:test_tb.sv
需要在flist.f文件中将其包起来(所有需要编译的文件)
./../rtl/test.v
./../tb/test_tb.sv
在rtl、tb中无需声明`timescale,在命令行统一写入+nctimescale+1ns/1ps
敲命令行:
ncverilog -sv +define+NC_VERILOG +define+ARMUD_MODEL +access+wrc +nctimescale+1ns/1ps -f flist.f
使用了一系列的编译选项和文件:-sv
(使用SystemVerilog语法),+define+NC_VERILOG
和+define+ARMUD_MODEL
(定义宏),+access+wrc
(设置访问权限),-f flist.f
(指定编译文件列表),以及两个文件./../rtl/test.v
和./../tb/test_tb.sv
。