VHDL record type in SV

VHDL中提供了丰富的数据结构,设计人员为了设计的扩展性和复用性,经常使用其中的record类型,因此不可避免的在定义一些entity端口时使用自定义的record类型,而一般情况下record中具有多个不同变量,这种将多个不同信号集束在一起的端口定义方式,对于具有相同端口定义方式的VHDL模块之间的连接是很方便的,但是这样定义的entity例化在SystemVerilog中时因为SystemVerilog中没有对应的record,在编译仿真时会出现找不到对应record端口类型的问题,同样的在SystemVerilog中也存在一些数据类型在例化时不为VHDL识别,例如struct等,为此,本文以Mentor公司的QuestaSim作为仿真工具进行示例说明如何解决这种自定义数据类型在VHDL和SystemVerilog的匹配问题。

1 VHDL中定义的record端口在SystemVerilog中例化

【示例】
VHDL-type_pkg:
library ieee;
use ieee.std_logic_1164.all;
package type_pkg is 
    type type_grp is record
        s1 : std_logic;
        s2 : std_logic_vector(1 downto 0);
        s3 : std_logic_vector(2 downto 0);
        s4 : std_logic_vector(3 downto 0);
    end record;
end type_pkg;

package body type_pkg is
-- empty
end type_pkg;
VHDL-test:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
library work;
use work.type_pkg.all;
entity test is 
port (
    d : in type_grp
);
end test;

architecture behav of test is
signal tmp : type_grp;
begin
    tmp <= d;
end behav;
SystemVerilog-PART:
`timescale 1 ns / 1 ps
module top_tb;
import type_pkg::*;
type_grp d_set;
initial begin
       d_set.s1 = 1'b0;
       d_set.s2 = 2'b10;
       d_set.s3 = 3'b110;
       d_set.s4 = 4'b1110;
    #2 d_set.s1 = 1'b1;
       d_set.s2 = 2'b01;
       d_set.s3 = 3'b001;
       d_set.s4 = 4'b0001;
    #2 $stop;
end

test u_dut(d_set);
endmodule // top_tb

【编译仿真命令】

a 编译

% vcom -mixedsvvh type_pkg.vhd

% vcom test.vhd

% vlog -sv top_tv.v

b 析构

% vsim -novopt top_tb

c 仿真

% run

【仿真结果】 

对于VHDL record接口类型在SystemVerilog中例化的问题,虽然通过一些EDA厂商提供的EDA工具通过增加特定的编译选项可以解决,但是并不是所有的EDA工具都像Mentor的QuestaSim这样提供有解决措施(编译选项”-mixedsvvh”),所以在具体的VHDL record接口例化时建议对具有record接口的VHDL代码外包一层,该包装层实现对record接口的拆分。

SystemVerilog中借鉴了VHDL的package结构,在其中可以定义一些共用的数据结构,定义的数据类型常用于端口声明,而这些具有这些自定义类型的端口在例化于VHDL设计中时也存在编译时数据类型不被识别的问题,遇到这种问题应该如何解决呢?下例以SystemVerilog中package定义的struct为例进行示例说明。

2 SystemVerilog中定义的struct在VHDL中例化

【示例】

SystemVerilog - type_pkg:
package type_pkg;
    typedef struct {
        logic       s1;
        logic [1:0] s2;
        logic [2:0] s3;
        logic [3:0] s4;
    }type_grp;
endpackage // type_pkg;
SystemVerilog - test:
import type_pkg::*;
module sv_mod(input type_grp sv_port);
// blank
endmodule // sv_mode
VHDL - PART:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
-- 对于type_pkg库的引用不能忽略掉
library work;
use work.type_pkg.all;

entity top_tb is
end top_tb;

architecture behav of top_tb is

component sv_mod
port (
    sv_port : in type_grp
);
end component;

signal sig : type_grp;

begin
process begin
    sig.s1 <= '1';
    sig.s2 <= "10";
    sig.s3 <= "100";
    sig.s4 <= "1000";
    wait for 10 ns;
    sig.s1 <= '0';
    sig.s2 <= "01";
    sig.s3 <= "001";
    sig.s4 <= "0001";
    wait for 10 ns;
    wait;    
end process;

u_dut : sv_mod
port map(
    sv_port => sig
);
end behav;

【编译仿真命令】

a 编译

% vlog -mixedsvvh -sv type_pkg.sv

% vlog -sv sv_mod.sv

% vcom top_tb.vhd

b 析构

% vsim -novopt top_tb

c 仿真

% run

【仿真结果】 

示例中type_pkg.sv中定义的struct如果直接在top_tb.vhd中引用将会导致编译错误,为此在对type_pkg.sv进行编译时需要加上“-mixedsvvh”选项,尽管这样还需要在top_tb.vhd中指明type_pkg.sv编译的逻辑库,否则还是会存在找不到struct数据结构的问题。

通过上述示例(仅以record和struct为例),导致上述问题的主要原因时两种语言中都存在package结构,而package结构主要用于存放一些共用的数据结构或者方法,而这些数据结构或者方法与其他语言的描述也存在差异,在未进行特殊处理的情况下对于其他语言描述的代码也不可见,为此一般情况下需要借助特殊的第三方工具处理才能实现VHDL和SystemVerilog描述的package特定数据接结构或者方法的可见和互相转换,但是这都是借助于第三方的EDA工具,然而并不是所有的EDA工具都会提供对应的功能,为此建议对于特殊的数据结构定义的端口,在其他语言描述的设计中例化之前对其进行外包封装,将自定义的数据类型端口拆分为都可以识别的数据类型。

下面是“-mixedsvvh”在QuestaSim中的详细说明,大家可以根据自己的设计需要求进行使用。

【针对VHDL设计的vcom编译使用的mixedsvvh

· -mixedsvvh [b | l | r ][i]

(optional) Facilitates using VHDL packages at the SystemVerilog-VHDL boundary of a mixed-language design. When you compile a VHDL package with -mixedsvvh, the package can be included in a SystemVerilog design as if it were defined in SystemVerilog itself.

Executing -mixedsvvh without arguments compiles VHDL vectors in the following ways:

· VHDL bit_vectors are treated as SystemVerilog bit vectors.

· VHDL std_logic_vectors, std_ulogic_vectors, and vl_logic_vectors are treated as SystemVerilog logic vectors.

b — treats all scalars and vectors in the package as SystemVerilog bit type

l — treats all scalars and vectors in the package as SystemVerilog logic type

r — treats all scalars and vectors in the package as SystemVerilog reg type

i — ignores the range specified with VHDL integer types. Can be specified together with b, l, or r, spaces are not allowed between arguments.

 【针对SystemVerilog设计的vlog编译使用的mixedsvvh

· -mixedsvvh [b | s | v]

(optional) Facilitates using SystemVerilog packages at the SystemVerilog-VHDL boundary of a mixed-language design. When you compile a SystemVerilog package with -mixedsvvh, the package can be included in a VHDL design as if it were defined in VHDL itself.

b — treats all scalars/vectors in the package as VHDL bit/bit_vector

s — treats all scalars/vectors in the package as VHDL std_logic/std_logic_vector

v — treats all scalars/vectors in the package as VHDL vl_logic/vl_logic_vector


全部评论
感谢大佬分享的新知识
点赞 回复 分享
发布于 2022-09-29 17:38 河南

相关推荐

你背过凌晨4点的八股文么:简历挂了的话会是流程终止,像我一样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务