vhdl - 使用记录类型在 VHDL 中模拟 systemverilog 接口(interface)?

标签 vhdl

我见过人们使用记录类型的双向总线通过在记录的每个字段上驱动输入或输出来模拟 SystemVerilog 接口(interface)语言结构....我只是好奇为什么我尝试做同样的事情事情不起作用?任何想法如何正确地做到这一点?

--Attemping to emulate SystemVerilog Interfaces using VHDL Record....

----------------------------------------------
-- DUT
----------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity dut is
    port(
        i1 : in  std_logic;
        i2 : in  std_logic;
        o1 : out std_logic;
        o2 : out std_logic
    );
end entity;

architecture beh of dut is
begin
    o1 <= '1';
    o2 <= '0';  
end architecture;   
----------------------------------------------
-- TESTBENCH
----------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use std.textio.all;
    
entity testbench is
end entity;

architecture beh of testbench is

    type sverilog_interface_t is record
        field0 : std_logic;
        field1 : std_logic;
        field2 : std_logic;
        field3 : std_logic;
    end record;
    
    signal sverilog_interface : sverilog_interface_t;
    
    procedure show_bus(
        signal sverilog_interface :inout sverilog_interface_t
    ) is
        variable m :line;
    begin
        write(m, string'("task0"));
        write(m, string'(" x0:")); write(m, sverilog_interface.field0);
        write(m, string'(" x1:")); write(m, sverilog_interface.field1);
        write(m, string'(" x2:")); write(m, sverilog_interface.field2);
        write(m, string'(" x3:")); write(m, sverilog_interface.field3);
        writeline(output, m);       
    end procedure;
    
    procedure task0(
        signal sverilog_interface :inout sverilog_interface_t
    ) is
    begin
        sverilog_interface.field0 <= '0';
        sverilog_interface.field1 <= '1';   
        wait for 1 ns;      
    end procedure;
    
    procedure task1(
        signal sverilog_interface :inout sverilog_interface_t
    ) is
    begin
        sverilog_interface.field0 <= '1';
        sverilog_interface.field1 <= '0';   
        wait for 1 ns;      
    end procedure;
    
begin

dut1: entity work.dut(beh) 
    port map(
        i1 => sverilog_interface.field0,
        i2 => sverilog_interface.field1,
        o1 => sverilog_interface.field2, -- WHy 'U'? should be '0' or '1?
        o2 => sverilog_interface.field3  -- WHy 'U'? should be '0' or '1?
    );

process begin
   wait for 1 ns;
   
   show_bus(sverilog_interface);
   
   task0(sverilog_interface); 
   show_bus(sverilog_interface);
   
   task1(sverilog_interface); 
   show_bus(sverilog_interface);
      
   report "end of testcase" severity failure;
end process;

end architecture;
F:\Xilinx\Vivado\2021.2\bin\xvhdl.bat --incr --relax --2008 -f test1.vhd
F:\Xilinx\Vivado\2021.2\bin\xelab.bat testbench -snapshot simout -incr -debug all 
F:\Xilinx\Vivado\2021.2\bin\xsim.bat simout --tclbatch simout.sim.tcl --onerror quit --onfinish quit --ieeewarnings

****** xsim v2021.2 (64-bit)
  **** SW Build 3367213 on Tue Oct 19 02:48:09 MDT 2021
  **** IP Build 3369179 on Thu Oct 21 08:25:16 MDT 2021
    ** Copyright 1986-2021 Xilinx, Inc. All Rights Reserved.

## run all

task0 x0:U x1:U x2:U x3:U
task0 x0:0 x1:1 x2:U x3:U  <-- WHy are x1 and x2 'U'?
task0 x0:1 x1:0 x2:U x3:U  <-- WHy are x1 and x2 'U'?

Failure: end of testcase
Time: 3 ns  Iteration: 0  Process: /testbench/line__88  File: test1.vhd
$finish called at time : 3 ns : File "test1.vhd" Line 99
exit 0
INFO: [Common 17-206] Exiting xsim at Tue Feb 15 16:02:17 2022...
code:(0)
ok

最佳答案

sverilog_interface 的字段有 2 个驱动程序:DUT 和测试台进程​​。

DUT 仅将最后两个字段(因为其他字段的模式在 in)驱动为 '1''0',分别。

该进程驱动所有字段,因为 sverilog_interface 信号与您的 3 个过程调用的 inout 接口(interface)声明相关联。 LRM 4.2.2.3 信号参数:

A process statement contains a driver for each actual signal associated with a formal signal parameter of mode out or inout in a subprogram call.

这四个字段首先被驱动到'U'std_logic枚举类型最左边的值,作为未初始化的std_logic的默认值 信号。前两个字段随后被驱动为 '0''1' 值。但不是仍然驱动到 'U' 的最后两个字段。

附加到std_logic类型的解决函数解决了DUT('0''1')和进程之间的冲突('U''U')作为 'U'

一个解决方案可能是在您的过程中将最后两个字段显式驱动到 'Z'(高阻抗):

process begin
   sverilog_interface.field2 <= 'Z';
   sverilog_interface.field3 <= 'Z';

   wait for 1 ns;
   ...

'Z' 与任何内容('-' 除外)发生冲突时,解析为任何内容。或者在您的程序中执行此操作。或者,像某些人所做的那样(参见 OSVVM ),定义您自己的解析函数和您自己解析的 std_ulogic 子类型,这样 'U' 和任何其他内容都可以解析为其他任何内容.

注意:您的show_bus 过程不需要模式inout,最好使用in。而你的task0task1过程不需要模式inout,最好使用out(最小权限原则)。但是仅靠这些修改并不能解决您的问题:进程仍在驱动 sverilog_interface 信号的 4 个字段。

注意:正如@user16145658所述,另一种解决方案是在声明时修改sverilog_interface的默认值:

signal sverilog_interface : sverilog_interface_t := ('U', 'U', 'Z', 'Z');

然后该过程会将最后 2 个字段驱动到 'Z'

关于vhdl - 使用记录类型在 VHDL 中模拟 systemverilog 接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71133496/

相关文章:

logic - 4 位加减法逻辑

根据 `report` 语句,VHDL 重新分配整数信号不起作用

vhdl - 初始化动态 VHDL 阵列

syntax - VHDL语法错误10500

vhdl - 敏感列表中的哪个信号触发进程

vhdl - Lex VHDL '(勾号) token

c - microblaze 和 vhdl 之间如何通信?

vhdl - VHDL 中的可选端口?

vhdl - 在 VHDL 中按名称连接端口,UCF 样式

vhdl - 简单 VHDL 电路的意外行为