2011-10-28 29 views
7

我最近开始为我的端口定义开始使用记录,特别是如果我想对属于某个接口的信号进行分组。然而,我在这里面临的问题是,我不能通过通用的方式将std_logic_vector的宽度传递给实体。所以我基本上想要做的是以下几点:将泛型传递给记录端口类型

library ieee; 
use ieee.std_logic_1164.all; 
use work.math_pkg.all; 

package fifo_pkg is 

    type fifo_in_type is record 
    data_in : std_logic_vector(DATA_WIDTH_??- 1 downto 0); 
    rd  : std_logic; 
    wr  : std_logic; 
    end record; 

    type fifo_out_type is record 
    data_out : std_logic_vector(DATA_WIDTH_?? - 1 downto 0); 
    empty : std_logic; 
    full  : std_logic; 
    end record; 

    component fifo is 
    generic 
     (
     MIN_DEPTH : integer; 
     DATA_WIDTH : integer 
     ); 
    port 
     (
     clk : in std_logic; 
     res_n : in std_logic; 
     i  : in fifo_in_type; 
     o  : out fifo_out_type 
     ); 
    end component fifo; 

end fifo_pkg; 

因此,理想的解决办法是,当我可以使用相同的通用在我的纪录,我在实体一样。 (所以DATA_WIDTH与DATA_WIDTH_ ??相同)。我知道这应该以某种方式与VHDL 2008,但我的Quartus II 11sp1不支持记录中的泛型。

是否有一种优雅的方式来实现可综合的那种“泛型传递”?我知道可以在包中存储常量,但是我不能使用相同的fifo包以不同的宽度实例化几个fifo。

万分感谢, 牛逼

回答

8

你可以使用泛型类型采用Quartus?

那么你要离开的类型完全不确定,这样就可以创建integers一个FIFO或任何其它数据类型:

package fifo_pkg is 
    generic (type element_type); 

    type fifo_in_type is record 
    data_in : element_type; 
    rd  : std_logic; 
    wr  : std_logic; 
    end record; 

    type fifo_out_type is record 
    data_out : element_type; 
    empty : std_logic; 
    full  : std_logic; 
    end record; 

    component fifo is 
    generic 
     (
     MIN_DEPTH : integer; 
     DATA_WIDTH : integer 
     ); 
    port 
     (
     clk : in std_logic; 
     res_n : in std_logic; 
     i  : in fifo_in_type; 
     o  : out fifo_out_type 
     ); 
    end component fifo; 

end fifo_pkg; 

然后,当你想使用它:

package wide_fifo_pkg is new fifo_pkg 
    generic map (type => std_logic_vector(31 downto 0)); 

和那么你可以使用fifo_in_typefifo_out_type

signal i : fifo_in_type; 

如果您有一个设计单位不止一个FIFO,您可以创建包的几个版本,并使用包前缀得到正确的类型:

package narrow_fifo_pkg is new fifo_pkg 
    generic map (type => std_logic_vector(3 downto 0)); 

signal i32 : wide_fifo_pkg.fifo_in_type; 
signal i4 : narrow_fifo_pkg.fifo_in_type; 

另一个VHDL 2008年选择:你可以有一个不受约束的记录类型:

type fifo_in_type is record 
    data_in : std_logic_vector; 
    rd  : std_logic; 
    wr  : std_logic; 
    end record; 

然后你就可以创建subtype S的为您的各种用途:

subtype fifo1_data_type is fifo_in_type(data_in(31 downto 0)); 
subtype fifo2_data_type is fifo_in_type(data_in(15 downto 0)); 

不知道Quartus是否支持这两种选择 - 请让我们知道!

+0

嗨马丁,感谢您的建议,这两个都漂亮和优雅。然而,这在Quartus 11.0 SP1中不起作用。似乎quartus目前只支持vhdl 2008非常有限的子集。任何其他想法来完成这个任务?我想知道这是否会与Synplify一起工作...谢谢,T – user1017739

+0

这是一个遗憾(关于Quartus),但并非完全没有预料之外。 Synplify帮助文件意味着它知道有无约束数组*和*类型泛型的记录。 –

+0

确实,这有点令人失望:( – user1017739