使用内部 ID 初始化组件

Initialize components with an internal ID

我应该创建一个由 N 个组件(实体 "B")组成的结构(实体 "A")。每个组件都有多个输入和输出以及一个内部信号 ID(必须是静态的),用于标识从 0 到 N-1 的组件。每个组件根据 ID 执行一些操作。我的问题是如何在初始化时(在端口映射期间)为每个组件分配一个静态 ID。显然,组件在 for..generate 循环中是 "created",因为 N 可能是通用的。

为您的组件声明一个泛型,为其分配生成的循环索引,并在内部将泛型分配给信号:

entity insider is
  generic(id: natural);
  port(
    ...
  );
end entity insider;

architecture arc of insider is
  signal s: natural;
begin
  ...
  s <= id;
  ...
end architecture arc;

...

architecture arc of outsider is
  ...
begin
  ...
  g: for i in 1 to 10 generate
    i: entity work.insider
      generic map(id => i)
      port map(
        ...
      );
  end generate g;
  ...
end architecture arc;