VHDL:通用地图设置
VHDL: genric map setup
为什么这个设置会起作用?
component mux2to1 is
generic (M : integer := 1); -- Number of bits in the inputs and output
port (input0 : in m32_vector(M-1 downto 0) := (others => '0');
input1 : in m32_vector(M-1 downto 0) := (others => '0');
sel : in m32_1bit;
output : out m32_vector(M-1 downto 0));
end component;
我理解 genric map 的方式是 (M: integer: 1) 将指定端口的位为 1 到 out,但是当 M-1 downto 0 将只是 0 down 0,这是没有意义的。
正如@user1155120 所说,您可以拥有一个包含 1 个元素的数组。 (0 downto 0) 将有 1 个元素。
然而,还有一个重要的观点:
在 VHDL 中,某个类型的 1 个元素的数组与元素类型不同。因此,例如,std_logic
和 std_logic_vector(0 downto 0)
是不同的类型。您不能将一个分配给另一个。 std_logic
是标量,而 std_logic_vector(0 downto 0)
是数组类型。
到"convert"这几个类型之间,需要索引数组类型。所以,有了信号
signal S : std_logic;
signal A : std_logic_vector(0 downto 0);
您不能将 A 分配给 S,反之亦然,但您可以这样做:
A(0) <= S;
或者这个:
S <= A(0);
您还可以索引阵列端口。所以,
entity HAS_ARRAY_PORT
port ( P : in std_logic_vector(0 downto 0));
end;
你可以这样做:
L: entity work.HAS_ARRAY_PORT port map (P(0) => S);
为什么这个设置会起作用?
component mux2to1 is
generic (M : integer := 1); -- Number of bits in the inputs and output
port (input0 : in m32_vector(M-1 downto 0) := (others => '0');
input1 : in m32_vector(M-1 downto 0) := (others => '0');
sel : in m32_1bit;
output : out m32_vector(M-1 downto 0));
end component;
我理解 genric map 的方式是 (M: integer: 1) 将指定端口的位为 1 到 out,但是当 M-1 downto 0 将只是 0 down 0,这是没有意义的。
正如@user1155120 所说,您可以拥有一个包含 1 个元素的数组。 (0 downto 0) 将有 1 个元素。
然而,还有一个重要的观点:
在 VHDL 中,某个类型的 1 个元素的数组与元素类型不同。因此,例如,std_logic
和 std_logic_vector(0 downto 0)
是不同的类型。您不能将一个分配给另一个。 std_logic
是标量,而 std_logic_vector(0 downto 0)
是数组类型。
到"convert"这几个类型之间,需要索引数组类型。所以,有了信号
signal S : std_logic;
signal A : std_logic_vector(0 downto 0);
您不能将 A 分配给 S,反之亦然,但您可以这样做:
A(0) <= S;
或者这个:
S <= A(0);
您还可以索引阵列端口。所以,
entity HAS_ARRAY_PORT
port ( P : in std_logic_vector(0 downto 0));
end;
你可以这样做:
L: entity work.HAS_ARRAY_PORT port map (P(0) => S);