verilog - SystemVerilog 的 Verilog 包装器
问题描述
我正在尝试为 VS 计数器创建一个 Verilog 包装器。
我为计数器编写了以下SystemVerilog代码:
//counter.sv
interface counter_if(input clk, rstn);
logic [3:0] out;
modport dut(input clk,rstn, output out);
endinterface : counter_if
module counter(counter_if.dut cnt);
always @ (posedge cnt.clk) begin
if (! cnt.rstn)
cnt.out <= 0;
else
cnt.out <= cnt.out + 1;
end
endmodule
另外,我编写了以下Verilog代码:
//wrapper file
module counter_wrapper(clk,rstn,out);
input clk;
input rstn;
output reg [3:0] out;
counter_if cnt (.clk(clk), .rstn(rstn));
counter cnt0 (
.cnt(cnt)
);
endmodule
当我编译它时,我收到 Verilog 文件的以下错误:
错误:(vlog-2110)非法引用接口“cnt”
所以我将接口调用更改为以下内容:
//wrapper file
module counter_wrapper(clk,rstn,out);
input clk;
input rstn;
output reg [3:0] out;
counter_if cnt (.clk(clk), .rstn(rstn));
counter cnt0 (
.cnt(cnt.dut)
);
endmodule
现在设计编译了,但是在模拟时出现以下错误:
- 错误:(vsim-3044)“cnt.dut”的使用与“modport”对象不一致。
任何见解将不胜感激!
解决方案
符合标准的 Verilog 代码无法实例化 SystemVerilog 接口。您需要使用 SV 包装器或删除接口并将其替换为普通模块端口。Verilog 可以通过常规模块端口很好地连接到 SV(在大多数工具中)。
//counter.sv
module counter (
input logic clk,
input logic rstn,
output logic [3:0] out
);
always @ (posedge clk) begin
if (!rstn)
out <= 0;
else
out <= out + 1;
end
endmodule
推荐阅读
- windows - 如何写入 BitLocker 加密卷的物理扇区?
- python - Django 路径不起作用,它会将我引导到错误的网站
- javascript - vue watch sublist如何变化或v-model
- javascript - 如何为我的应用获取 Shopify 商店产品的所有数据?
- c# - 当我更新现有数据时 System.Reflection.TargetException ERROR
- excel - Excel / Apache POI:如何转义 Excel 单元格的字符串?
- flutter - 如何使用 Dart::FFI 在颤振中使用 C++ 库?
- php - Foreach 2 var $_POST
- jquery - $,get 方法在 PHP 更新后不读取新数据
- c++ - 按 C++ 中的两个字段对结构的 std::vector 排序