如何生成不同类型的组件

How to generate different types of component

我有 3 种不同类型的组件。例如 type0、type1 和 type2。它们都有相同的端口但功能相同。我想使用像 0、1 和 3 这样的常量将相应的组件放在我的顶层设计中。我想知道这样做的方法。

此致

您可以使用 generate 语句,例如:

G0 : if SOME_CONSTANT = 0 generate
  I0 : type0 ( ...
end generate;
G1 : if SOME_CONSTANT = 1 generate
  I1 : type1 ( ...
end generate;
G2 : if SOME_CONSTANT = 2 generate
  I2 : type2 ( ...
end generate;
-- etc

如果使用VHDL-2008,则有case-generate语句:

G : case SOME_CONSTANT generate
  when 0 =>
    I0 : type0 ( ...
  when 1 =>
    I1 : type1 ( ...
  when 2 => 2 
    I2 : type2 ( ...
  -- etc
end generate;

您可以为同一个实体使用多种架构:

entity my_component is
--(only one port declaration for all component)
end entity;

architecture type1 of my_component is
--(type1 behavior)
end architecture;

architecture type2 of my_component is
--(type2 behavior)
end architecture;

architecture type3 of my_component is
--(type3 behavior)
end architecture;

然后您可以在 top_level 文件中调用您需要的任何架构:

typ1_inst0 : entity work.my_component(type1)
--(port map ...)

typ2_inst0 : entity work.my_component(type2)
--(port map ...)

typ3_inst0 : entity work.my_component(type3)
--(port map ...)