首页 > 解决方案 > 如何在 VHDL 中正确使用断言?

问题描述

我在 VHDL 中有一个代码段,这让我不确定它是否正确:a 和 b 是 std_logic_vectors。c1 和 c0 是标准逻辑。这个写对了吗?尤其是“c1 = '1' and c0 = '0'”这部分让我很纠结。

if unsigned(a) > unsigned(b) then
    assert(c1 = '1' and c0 = '0')

编辑:这是一个更大的代码段:

    signal a: std_logic_vector(3 downto 0);
    signal b: std_logic_vector(3 downto 0);
    signal c1: std_logic;
    signal c0: std_logic;

    begin
    TEST: forBitComperator port map(a, b, c1, c0);
      process
      begin
        for i in 0 to 2**4-1 loop
            for k in 0 to 2**4-1 loop

                wait for 0 ns;

                a <= conv_std_logic_vector(i, 4);
                b <= conv_std_logic_vector(k, 4);

                if i > k then
                  assert c1 = '1' and c0 = '0'
                  report "error ";
               end if;
        end loop;
    end loop;
    wait;
  end process;
end;

标签: vhdlasserttest-bench

解决方案


您不确定的部分是正确的。c0, c1,'0''1'都是std_logic, 所以用这种方式比较它们是正确的。(在 VHDL=中是相等比较运算符。它不执行赋值,就像在许多软件编程语言中一样)。每次比较的结果都是一个布尔值(truefalse),因此可以与assert语句一起使用。

我认为唯一错误的部分是您必须ifend if. 通常还建议每当您使用 时assert,都会report显示错误消息并设置 a severity(例如note、或warning,具体取决于错误的严重程度)。当然,它也必须以 . 结尾。errorfailure;

所以:

if unsigned(a) > unsigned(b) then
    assert c1 = '1' and c0 = '0' report "<Error message>" severity warning;
end if;

推荐阅读