verilog - 如何在 Verilog 中实例化具有 reg 端口的模块?
问题描述
我有一个这种类型的模块:
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));
...
问题是我不能以这种方式在测试台中实例化我的模块,因为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
推荐阅读
- sybase - 在其他地方单击时输入的文本消失 - Powerbuilder
- rest - 如何有效地使用 azureml.exceptions.WebserviceException 进行高效的 REST API 错误管理?
- vue.js - VueJS - 在模板中显示异步数据
- ios - 通过 BarButton 和 Firebase 保存所有单元格中的数据
- django - django rest框架中不同模型的通用字段
- ionic-framework - Ionic Android 应用程序因 OKHTTP 错误而崩溃
- c++ - 为什么 boost lib 有外部链接,而不是内部链接?(仅标题链接的最佳实践)
- c - 地址和变量如何放置在内存中
- python - opensemanticsearch 的清理索引
- sql - 在 Dremio 上声明一个默认值