VHDL组件实例化
组件实例化允许您在另一个设计单元(组件)中实例化一个设计单位(组件)设计单元来创建分层结构的设计描述。
要执行组件实例化:
1.创建对要实例化的功能进行建模的设计单元(实体和架构)。
2.在父设计单元的声明性区域中声明要实例化的组件建筑学
3.在父设计单元的架构体中实例化并连接该组件。
4.将组件的正式端口映射(连接)到父设计的实际信号和端口单元
组件实例化语句的元素
Vivado合成支持组件声明中的无约束向量。主要元素组件实例化语句的是:
•标签:标识实例。
•关联列表:由保留端口映射关键字引入,并绑定的正式端口组件到父设计单元的实际信号或端口。可选的关联列表是由保留的通用map关键字引入,并将实际值提供给形式组件中定义的泛型。
组件实例化(VHDL)
文件名:instantiation_simple.vhd
这个编码示例显示了由四个nand2组成的半加法器的结构描述组件。
--
-- A simple component instantiation example
-- Involves a component declaration and the component instantiation itself
--
-- instantiation_simple.vhd
--
entity sub is
generic(
WIDTH : integer := 4
);
port(
A, B : in BIT_VECTOR(WIDTH - 1 downto 0);
O : out BIT_VECTOR(2 * WIDTH - 1 downto 0)
);
end sub;
architecture archi of sub is
begin
O <= A & B;
end ARCHI;
entity instantiation_simple is
generic(
WIDTH : integer := 2);
port(
X, Y : in BIT_VECTOR(WIDTH - 1 downto 0);
Z : out BIT_VECTOR(2 * WIDTH - 1 downto 0));
end instantiation_simple;
architecture ARCHI of instantiation_simple is
component sub -- component declaration
generic(
WIDTH : integer := 2);
port(
A, B : in BIT_VECTOR(WIDTH - 1 downto 0);
O : out BIT_VECTOR(2 * WIDTH - 1 downto 0));
end component;
begin
inst_sub : sub -- component instantiation
generic map(
WIDTH => WIDTH
)
port map(
A => X,
B => Y,
O => Z
);
end ARCHI;
递归组件实例化
Vivado综合支持递归组件实例化。
递归组件实例化示例(VHDL)
Filename: instantiation_recursive.vhd
--
-- Recursive component instantiation
--
-- instantiation_recursive.vhd
--
library ieee;
use ieee.std_logic_1164.all;
library unisim;
use unisim.vcomponents.all;
entity instantiation_recursive is
generic(
sh_st : integer := 4
);
port(
CLK : in std_logic;
DI : in std_logic;
DO : out std_logic
);
end entity instantiation_recursive;
architecture recursive of instantiation_recursive is
component instantiation_recursive
generic(
sh_st : integer);
port(
CLK : in std_logic;
DI : in std_logic;
DO : out std_logic);
end component;
signal tmp : std_logic;
begin
GEN_FD_LAST : if sh_st = 1 generate
inst_fd : FD port map(D => DI, C => CLK, Q => DO);
end generate;
GEN_FD_INTERM : if sh_st /= 1 generate
inst_fd : FD port map(D => DI, C => CLK, Q => tmp);
inst_sstage : instantiation_recursive
generic map(sh_st => sh_st - 1)
port map(DI => tmp, CLK => CLK, DO => DO);
end generate;
end recursive;
VHDL组件配置
组件配置显式地将组件与适当的模型链接起来。
•模型是一对实体和体系结构。
•Vivado综合支持体系结构声明部分的组件配置。
以下是一个示例:
for instantiation_list : component_name use
LibName.entity_Name(Architecture_Name);
以下声明表明:
•所有NAND2组件都使用由实体NAND2和体系结构组成的设计单元ARCHI。
•设计单元在工作库中编译。
For all : NAND2 use entity work.NAND2(ARCHI);
synth_design命令中的顶部模块名称(-top)选项的值为配置名称,而不是顶级实体名称。
VHDL泛型
VHDL GENERIC具有以下属性:
•等效于Verilog参数。
•帮助您创建可扩展的设计模型。
•让您可以编写紧凑、因子分解的VHDL代码。
•允许您参数化功能,如总线大小和中重复元素的数量设计单位。
对于必须多次实例化但具有不同总线大小的相同功能,您只需要用泛型描述一个设计单元。请参见GENERIC参数示例。
声明泛型
您可以在实体声明部分中声明泛型参数。支持的泛型类型有:integer、boolean、string和real。
GENERIC参数示例
Filename: generics_1.vhd
-- VHDL generic parameters example
--
-- generics_1.vhd
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity addern is
generic(
width : integer := 8
);
port(
A, B : in std_logic_vector(width - 1 downto 0);
Y : out std_logic_vector(width - 1 downto 0)
);
end addern;
architecture bhv of addern is
begin
Y <= A + B;
end bhv;
Library IEEE;
use IEEE.std_logic_1164.all;
entity generics_1 is
port(
X, Y, Z : in std_logic_vector(12 downto 0);
A, B : in std_logic_vector(4 downto 0);
S : out std_logic_vector(17 downto 0));
end generics_1;
architecture bhv of generics_1 is
component addern
generic(width : integer := 8);
port(
A, B : in std_logic_vector(width - 1 downto 0);
Y : out std_logic_vector(width - 1 downto 0));
end component;
for all : addern use entity work.addern(bhv);
signal C1 : std_logic_vector(12 downto 0);
signal C2, C3 : std_logic_vector(17 downto 0);
begin
U1 : addern generic map(width => 13) port map(X, Y, C1);
C2 <= C1 & A;
C3 <= Z & B;
U2 : addern generic map(width => 18) port map(C2, C3, S);
end bhv;
笔记
在实例化期间重写泛型值时,不支持拆分不同的数组元素。
例如,如果有一个通用my_gen定义为数组,如下所示,则它不起作用:
my_gen(1) => x,
my_gen(0) => y
相反,它应该设置如下: