【发布时间】:2019-10-22 15:48:28
【问题描述】:
我正在 eda playground (https://www.edaplayground.com/x/6Mpm) 中查看一个通用包示例,并且我正在尝试做类似的事情。我试图通过实体中的泛型字段从顶层获取一个整数,然后将泛型值传递给泛型包以设置记录的一部分的大小。然后,此记录类型将用于泛型来自的实体的端口。
这可能吗,还是我必须像示例中那样对包声明中的数字进行硬编码?尝试在实体中声明包给我错误,声明端口看不到记录类型。像示例中一样正常声明包意味着包看不到实体中的泛型。
我一直打算使用常量包来规避“问题”,但我想知道是否可以使用泛型和泛型包而不用硬编码数字来做到这一点。这样我在重用模块时就不必记得更改常量包了。
包装:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
-- pps_control_generic_pkg
package pps_control_generic_pkg is
generic(
-- Size of register. Max 32. Default 32
g_reg_size : integer := 32
);
type t_apb3_pif2core is record
rw_config : std_logic_vector(g_register_size-1 downto 0);
rw_config_we : std_logic;
end record;
type t_apb3_core2pif is record
rw_config : std_logic_vector(g_register_size-1 downto 0);
end record;
end package pps_control_generic_pkg;
代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
-- Trying to declare this correctly
-----------------------------------------------------------
package pps_control_pkg is new work.pps_control_generic_pkg
generic map(
g_reg_size => g_reg_size
);
use work.pps_control_pkg.all;
-----------------------------------------------------------
entity pps_control_core is
generic(
-- Size of register. Default 32
g_register_size : integer := 32;
);
port(
csi_sys_clk : in std_logic;
rsi_sys_reset : in std_logic;
-- Interface to access register
p2c : in t_apb3_pif2core;
c2p : out t_apb3_core2pif;
pps_in : in std_logic;
pps_out : out std_logic;
pps_en_n : out std_logic
);
end entity;
architecture rtl of pps_control_core is
...
begin
...
end rtl;
【问题讨论】:
-
不太确定我是否关注你。
g_reg_size在pps_control_pkg的实例化中不可见。如果您想使用实体中的泛型来设置包大小,则在实体内部创建包并在其中使用它,但它对外部的任何东西都不可见。 VHDL 2008 允许不受约束的类型,因此无论如何都不需要在包上使用泛型,因为可以在实体泛型的端口上声明大小。 -
Tricky 提到的记录类型的无约束复合元素提供了记录约束,看起来像this。还有一个通用接口元素,它是一个接口类型声明,但与不受约束的记录元素组合相比,它更不可能得到支持。请参阅 IEEE Std 1076-2008 5.3.3 记录类型、6.3 子类型声明和 6.5.3 接口类型声明。
-
这可能吗,还是我必须像示例中那样在包声明中硬编码数字? 不,这也告诉我们你正在处理一个XY Problem。您提出的解决方案无法解决,也无法成为唯一的解决方案。
-
谢谢你们的帮助。我意识到我陷入了自己的思维模式。不受约束的类型肯定会起作用。
标签: vhdl