opp*_*rud 6 generics instantiation vhdl
我正在尝试为基于SPI的IO扩展器创建通用驱动程序.我们的想法是在实例化中传递初始化值,该初始化值与请求的IO设置相匹配.
我目前的尝试看起来像这样:
entity max7301_simple is
generic (
IO_cfg : array (1 to 7) OF integer range 0 to 255 := (16#55#, 16#55#, 16#55#, 16#55#, 16#55#, 16#55#, 16#55#)
);
port (
-- Application interface :
clk_i : in std_logic; -- input clock, xx MHz.
rst_i : in std_logic; -- sync reset.
en_i : in std_logic; -- enable, forces re-init of pins on MAX7301.
output_i : in std_logic_vector(27 downto 0); --data to write to output pins on MAX7301
irq_o : out std_logic; -- IRQ, TODO: what triggers, change on inputs ?
input_o : out std_logic_vector(27 downto 0); --data read from input pins on MAX7301
-- MAX7301 SPI interface
sclk : out std_logic; -- SPI clock
din : in std_logic; -- SPI data input
dout : out std_logic; -- SPI read data
cs : out std_logic -- SPI chip select
);
end max7301_simple;
Run Code Online (Sandbox Code Playgroud)
问题在于IO_cfg数组,我尝试了各种尝试w/wo init值等.似乎无法想象如何指定数组.
我相信你已经读过你可以传递一个数组作为通用数据,但仍然没有太多运气.Xilinx ISE只是告诉med"'数组'附近的语法错误",这对于让我前进来说还不够丰富.
任何帮助,将不胜感激
在实例化此模块时,我总是需要7个值.
您可以使用数组作为通用参数,但不允许您在那里以匿名类型的形式声明它.
您必须首先在单独的包中声明您的整数数组类型(可以在同一个文件中或单独的文件中),然后use
在实体中以及实例化它时包.
以下是如何执行此操作的示例:
-- package declaration
package mytypes_pkg is
type my_array_t is array (1 to 7) of integer range 0 to 255;
end package mytypes_pkg;
-- entity "uses" the package
use work.mytypes_pkg.all;
entity max7301_simple is
generic (
IO_cfg : my_array_t := (16#55#, 16#55#, 16#55#, 16#55#, 16#55#, 16#55#, 16#55#)
);
-- ports [...]
end max7301_simple;
Run Code Online (Sandbox Code Playgroud)
还要use
注意实例化实体的体系结构中的包.
(可选阅读)
为什么写它像你一样真的是语法错误?
查看VHDL(2002)标准中的VHDL语法,每个泛型参数的声明都是a,interface_constant_declaration
并且您具有以下语法规则:
[§ 4.3.2]
interface_constant_declaration ::=
[ constant ] identifier_list : [ in ] subtype_indication [ := static_expression ]
[§ 4.2]
subtype_indication ::=
[ resolution_function_name ] type_mark [ constraint ]
Run Code Online (Sandbox Code Playgroud)
类型引用只能是现有类型(type_mark
)的名称或现有类型的限制.
我提出了一种更通用的方法,即使用2008 VHDL标准和预定义属性 - 这允许传递任意长度的数组。在包中定义您的类型,如下所示:
package data_types is
type array_of_integers is array(natural range <>) of integer;
end package;
Run Code Online (Sandbox Code Playgroud)
现在在您的代码中传递通用数组,如下所示:
generic(
COEFFICIENTS : array_of_integers := (-1, 0, 1)
);
Run Code Online (Sandbox Code Playgroud)
现在软件将使用默认索引方案。可以将其与预定的“left属性”考虑在内 (参考可在以下位置找到:http ://www.csee.umbc.edu/portal/help/VHDL/attribute.html ):
-- First coefficient
... <= COEFFICIENTS(COEFFICIENTS'left);
-- Second coefficient
... <= COEFFICIENTS(COEFFICIENTS'left + 1);
Run Code Online (Sandbox Code Playgroud)
通常,您应该在某种循环或生成语句中使用此数组:
GENERATE_STATEMENT: for entry in 0 to COEFFICIENTS'length-1 generate
out(entry) <= std_logic_vector(to_signed(COEFFICIENTS(COEFFICIENTS'left + entry), out(entry)'length));
end generate;
Run Code Online (Sandbox Code Playgroud)
作为Quartus II用户的一个小旁注- 也可以在.bdf原理图文件中使用通用数组。将参数类型设置为Auto并以此格式重写参数值 - A(D"-1", D"0", D"1"),其中D代表十进制数据类型(有用链接:http://quartushelp.altera .com/14.0/mergedProjects/assign/asd/asd_tab_param.htm)