emacs在小型模块仿真中的使用技巧
相信很多人都有这种经历——想对某一个模块进行一些简单的仿真测试,但是这个模块端口很多,写一个tb文件的话工作量很大,这时候就可以使用emacs来快速生成仿真环境。
我们的需求如下:
- • 为待测试的模块的所有INPUT生成reg类型的变量;
- • 为待测试的模块的所有OUTPUT生成wire类型的变量;
DUT
我们依然使用model1
作为DUT,其端口如下:
module model1 (
input clk,
input rst,
input [7:0] in_data1,
output reg [7:0] out_data1,
output reg to_model2
);
endmodule //model1
新建一个tb.v
文件,代码如下:
module tb ();
/*AUTOREGINPUT*/
/*AUTOWIRE*/
/* model1 AUTO_TEMPLATE (
);
*/
model1 u_model1 (/*autoinst*/
);
endmodule //tb
// Local Variables:
// verilog-auto-inst-param-value:t
// verilog-library-directories:(“.” “../src2/” )
// End:
- •
/*AUTOREGINPUT*/
为模块的所有INPUT生成reg类型的变量; - •
/*AUTOWIRE*/
,同上一章,为模块的所有OUTPUT生成wire类型的变量;
执行:
emacs --batch ./src/tb.v -f verilog-auto -f save-buffer
生成的tb.v文件如下:
module tb ();
/*AUTOREGINPUT*/
// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)
reg clk; // To u_model1 of model1.v
reg [7:0] in_data1; // To u_model1 of model1.v
reg rst; // To u_model1 of model1.v
// End of automatics
/*AUTOWIRE*/
// Beginning of automatic wires (for undeclared instantiated-module outputs)
wire [7:0] out_data1; // From u_model1 of model1.v
wire to_model2; // From u_model1 of model1.v
// End of automatics
/* model1 AUTO_TEMPLATE (
);
*/
model1 u_model1 (/*autoinst*/
// Outputs
.out_data1 (out_data1[7:0]),
.to_model2 (to_model2),
// Inputs
.clk (clk),
.rst (rst),
.in_data1 (in_data1[7:0]));
endmodule //tb
// Local Variables:
// verilog-auto-inst-param-value:t
// verilog-library-directories:(“.” “../src2/” )
// End:
可以看到,自动为我们生成了待测试模块的输入端口的reg变量和输出端口的wire变量,然后我们只需要操作这些变量即可,无需手动生成这些信号。