我有这种类型的模块:
module rgst(
input d,...
output reg [3:0]);
...
endmodule
而且我想为此编写一个测试平台:
module rgst_tb(
output reg d,
...
output reg [3:0]q);
rgst uut(.d(d),...,q(q));
...```
问题是我无法以这种方式在testbench中实例化模块,因为q是reg。
通常,包含测试平台代码的模块可以具有以下两种样式之一:被测试模块(DUT)在测试平台模块(TB)本身中实例化,或者DUT和TB在连接该模块的顶层模块中分别实例化。他们在一起。您只会做一个,而不是两个都做;许多新接触该语言的人倾向于将它们混合在一起。
+-----------------+ +--------------------------------+
| module tb | | module top |
| +-------------+| | +------------+ +------------+|
| | module dut || or | | module tb |==| module dut ||
| +-------------+| | +------------+ +------------+|
+-----------------+ +--------------------------------+
在第一种样式中,TB模块不需要任何输入或输出,只需要在本地声明并在本地操作/监视的DUT端口的电线/调节器:
module tb;
// Declare ports of DUT as locals inside TB
wire outval;
reg inval;
// Instantiate DUT inside TB module
dut u1(.in(inval), .out(outval));
// Stimulus and monitor here
initial begin
$monitor(outval);
inval <= ...;
end
endmodule
在第二种样式中,TB模块是单独的,并且不实例化DUT,因此需要将输入和输出端口连接到第三级更高模块中的DUT:
module tb(input outval, output reg inval); // TB has ports mirroring DUT ports
// Stimulus and monitor here
initial begin
$monitor(outval);
inval <= ...;
end
endmodule
module top;
// Declare connecting lines here
wire outval;
wire inval;
// Instantiate both TB and DUT here, connecting them together
tb t1(.outval(outval), .inval(inval));
dut u1(.in(inval), .out(outval));
endmodule
我以前见过的误解是人们认为您必须将reg连接到reg。NO。它不像您必须具有匹配类型的类型!
模块的输出端口始终连接到wire
。 (如果您有System Verilog,则为logic
)。
根据经验:
不幸的是,非常混乱:与合成后是否有寄存器无关!因此,在System Verilog中,引入了“逻辑”类型,从而消除了“ reg”混淆。
wire this_is_a_wire;
reg this_is_a_reg;
assign this_is_a_wire = ....
always (...)
this_is_a_reg ...
* 这也可以是always_comb