使用泛型参数作为端口数组长度

Jon*_*art 4 vhdl

我想做的事:

entity FIRfilter is
   generic (
      NTAPS : integer );
   port (
      -- ...
      h : in array(0 to NTAPS-1) of std_logic_vector(15 downto 0) );
end FIRfitler;
Run Code Online (Sandbox Code Playgroud)

但是行上的语法h不正确.

这个问题类似: 如何在VHDL中将整数数组指定为泛型? 但这并没有让我在实例化时获得通用的数量.这甚至可能吗?

Mor*_*mer 7

如果在包中声明无约束的数组类型,则可以基于泛型约束数组,如下面的代码所示:

library ieee; use ieee.std_logic_1164.all;

package FIRfilter_pkg is
  type x_t is array(natural range <>) of std_logic_vector(15 downto 0);
end package;


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

entity FIRfilter is
   generic (
      NTAPS : integer );
   port (
     x : in x_t(0 to NTAPS-1);
     z : out std_logic_vector(15 downto 0) );  -- For simple example below
end FIRfilter;


library ieee; use ieee.numeric_std.all;

architecture syn of FIRfilter is
begin
  z <= std_logic_vector(unsigned(x(0)) + unsigned(x(1)));  -- Usage example
end architecture;
Run Code Online (Sandbox Code Playgroud)

  • 端口声明可以包含接口信号声明,其中遵循模式(in)提供的子类型指示包括可选的解析函数声明(无),类型标记(x_t)和约束,范围或索引(显示).操作思路是接口信号声明声明命名子类型而不是类型.不能向后引用类型的实体声明性部分声明,因此类型在包中声明. (2认同)
  • 很高兴听到; 如果你可以使用一本书,那么看看[VHDL设计师指南](http://books.google.com/books?isbn=0080568858),你可能不需要其他;-) (2认同)