VHDL 记录未完全受限
VHDL record is not fully constrained
我有一个通过函数创建的接口记录,但是当我尝试编译时,我收到关于接口不受约束的错误。
记录:
type t_my_if is record
wdata : std_logic_vector;
wen : std_logic;
end record;
函数声明:
function init_my_if_signals(data_width : natural) return t_my_if;
函数体:
function init_my_if_signals(data_width : natural) return t_my_if is
variable init_if : t_my_if(wdata(data_width - 1 downto 0));
begin
init_if.wdata := (others => '0');
init_if.wen := '0';
return init_if;
end function;
请注意,虽然其中一个记录参数是 std_logic_vector
,但它的大小是在通过初始化函数创建时定义的。所以我不确定为什么会出现以下错误:
(vcom-1361) Subtype of "my_if" is not fully constrained.
该接口位于实体的 inout
端口上,因此它看起来像:
my_if : inout t_my_if := init_my_if_signals(8)
编辑:
下面的代码有效,但我希望能够动态定义数据宽度,所以这个解决方案对我来说不是最优的。
新记录:
type t_my_if is record
wdata : std_logic_vector(7 downto 0;
wen : std_logic;
end record;
新功能:
function init_my_if_signals(data_width : natural) return t_my_if is
variable init_if : t_my_if;
begin
--same as above
记录实例化的时候可以不定义吗?
在接口中使用它们之前,如何在包中声明所有常量和宽度并使用正确的宽度定义所需的类型。
package my_if_pkg is
constant c_data_width : natural := 8;
type t_my_if is record
wdata : std_logic_Vector(c_data_width-1 downto 0);
wen : std_logic;
end record;
constant z_my_if : t_my_if := ( wdata => (others => '0'),
wen => '0' );
end package;
...
然后在接口内使用包:
use my_if_pkg.all;
...
my_if : inout t_my_if := z_my_if;
所以根据 Doulos VHDL 2008 small changes,这在 VHDL-2008 中是允许的。他们的例子:
type myRecordT is
record
a : std_logic_vector;
b : std_logic_vector;
end record;
variable R : myRecordT( a(7 downto 0), b(15 downto 0) );
你编译的是VHDL-2008模式吗?
编辑:
my_if : inout t_my_if := init_my_if_signals(8)
你有问题:t_my_if
部分不受约束。尝试:
my_if : inout t_my_if(wdata(7 downto 0)) := init_my_if_signals(8)
顺便说一下:inout 端口不好,好吗? (除非你知道自己在做什么)
我有一个通过函数创建的接口记录,但是当我尝试编译时,我收到关于接口不受约束的错误。
记录:
type t_my_if is record
wdata : std_logic_vector;
wen : std_logic;
end record;
函数声明:
function init_my_if_signals(data_width : natural) return t_my_if;
函数体:
function init_my_if_signals(data_width : natural) return t_my_if is
variable init_if : t_my_if(wdata(data_width - 1 downto 0));
begin
init_if.wdata := (others => '0');
init_if.wen := '0';
return init_if;
end function;
请注意,虽然其中一个记录参数是 std_logic_vector
,但它的大小是在通过初始化函数创建时定义的。所以我不确定为什么会出现以下错误:
(vcom-1361) Subtype of "my_if" is not fully constrained.
该接口位于实体的 inout
端口上,因此它看起来像:
my_if : inout t_my_if := init_my_if_signals(8)
编辑:
下面的代码有效,但我希望能够动态定义数据宽度,所以这个解决方案对我来说不是最优的。
新记录:
type t_my_if is record
wdata : std_logic_vector(7 downto 0;
wen : std_logic;
end record;
新功能:
function init_my_if_signals(data_width : natural) return t_my_if is
variable init_if : t_my_if;
begin
--same as above
记录实例化的时候可以不定义吗?
在接口中使用它们之前,如何在包中声明所有常量和宽度并使用正确的宽度定义所需的类型。
package my_if_pkg is
constant c_data_width : natural := 8;
type t_my_if is record
wdata : std_logic_Vector(c_data_width-1 downto 0);
wen : std_logic;
end record;
constant z_my_if : t_my_if := ( wdata => (others => '0'),
wen => '0' );
end package;
...
然后在接口内使用包:
use my_if_pkg.all;
...
my_if : inout t_my_if := z_my_if;
所以根据 Doulos VHDL 2008 small changes,这在 VHDL-2008 中是允许的。他们的例子:
type myRecordT is
record
a : std_logic_vector;
b : std_logic_vector;
end record;
variable R : myRecordT( a(7 downto 0), b(15 downto 0) );
你编译的是VHDL-2008模式吗?
编辑:
my_if : inout t_my_if := init_my_if_signals(8)
你有问题:t_my_if
部分不受约束。尝试:
my_if : inout t_my_if(wdata(7 downto 0)) := init_my_if_signals(8)
顺便说一下:inout 端口不好,好吗? (除非你知道自己在做什么)