VHDL:条件信号分配的简明表述

VHDL: Concise formulation of conditional signal assignment

下面的代码是一个4:1多路复用器。如果 dis 信号为“1”,则所有输出引脚上的输出应为 0。有没有一种简洁的方式来说明如果 dis 是高电平,那么输出应该是 0,而不管 sel,没有 必须排列 sel?

的每个组合

我知道在某些情况下,如果条件分配不明确,则可能会产生意外的锁存器和其他不良副作用。

architecture dataflow of mux8_4 is
begin
    q <=d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0' else
        "00000000" when sel = "00" and dis = '1' else
        "00000000" when sel = "01" and dis = '1' else
        "00000000" when sel = "10" and dis = '1' else
        "00000000" when sel = "11" and dis = '1';
end architecture dataflow;

我的尝试(我理解遗漏所有可能的陈述是不好的 练习,但是)

architecture dataflow of mux8_4 is
begin
    q <=    "00000000" when dis = '1' else
        d0 when sel = "00" and dis = '0' else
        d1 when sel = "01" and dis = '0' else
        d2 when sel = "10" and dis = '0' else
        d3 when sel = "11" and dis = '0';
end architecture dataflow;

还有 selected 信号分配:

architecture foo of mux8_4 is
    subtype choice_type is std_logic_vector (2 downto 0);
begin
    with choice_type'(dis & sel) select
        q <= d0          when "000",
             d1          when "001",
             d2          when "010",
             d3          when "011",
             "00000000"  when others;
end architecture;

其中 case 表达式可以是具有类型标记的限定表达式,该类型标记具有局部静态子类型。

参见 IEEE Std 1076-1993 9.5.2 选定的信号分配,8.8 Case 语句或 IEEE Std 1076-2008 11.6 并发信号分配语句,10.5.4 选定的信号分配语句,10.9 Case 语句。

此(和您的)并发信号赋值语句具有包含等效顺序信号赋值语句的等效过程。在 -2008 中,条件语句和 selected 信号赋值语句都允许作为顺序语句。 selected 信号分配有一个等效的 case 语句。

仅提供 dis 和 select 的二进制值可以进行合成,其中弱值 'H' 和 'L' 映射到强值“1”和“0”分别。对于模拟,您可以使用转换函数来确保 dis 和 sel 表示二进制值(如果它们可以具有弱值)。

如果您的四个多路复用器数据输入可以表示为数组值,您可以更紧凑地描述多路复用器:

architecture fum of mux8_4 is
    type mux4 is array (0 to 3) of std_logic_vector(7 downto 0);
    use ieee.numeric_std.all;
    signal mux:      mux4;
begin
    mux <= (d0, d1, d2, d3);
    q <= mux(to_integer(unsigned(sel))) when dis = '0' else (others => '0');

end architecture;

索引名称需要一个具有局部静态名称的数组对象,因此类型声明用于声明分配了 mux4 类型聚合值的数组对象 (mux)。

之后我们可以使用从 sel 转换为自然数的索引作为条件信号赋值中 dis = '0' 时的索引,else 值全为 '0'。

这两种架构分析。如果您提供了带有实体声明和测试平台的 Minimal, Complete and Veriable example,则可以对它们进行详细说明和模拟,从而演示功能。 (他们都使用添加的实体声明进行分析)。

如果您的 sel 信号是一个受约束的整数子类型,则索引名称索引将更加紧凑和可读。包 numeric_std 中的 to_integer 转换函数将表示二进制值的弱级别映射到强级别,并在 sel 包含元值元素值(将映射到“0”)时生成警告。