![](/img/trans.png)
[英]verilog wrapper around systemverilog intefaces with inout ports
[英]Verilog wrapper for SystemVerilog
我正在尝试为 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”object 不一致。
任何见解将不胜感激!
符合标准的 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.