VHDL assert testbench with for 循环

VHDL assert testbench with for loop

我有一个 VHDL 问题:作为家庭作业,我们必须为我们的 VHDL 设计电路编写一个带断言的测试平台。我们应该测试 for 位比较器的每个信号组合。我想用一个 for 循环来解决这个问题,像这样:

architecture ts of testbench is

signal a: std_logic_vector(3 downto 0) := "0000";
signal b: std_logic_vector(3 downto 0) := "1011";
signal c1, c0: std_logic := '0';

begin
TEST: entity forBitVergleicher port map(a, b, c1, c0);

  for i in 0 to 2**n loop
    k for k in 0 to 2**n loop

    a <= std_logic_vector(i); b <= std_logic_vector(k);
    assert(unsigned(a) > unsigned(b) and (c1 = '0' or c0 =
    '1') and (c1 = '0' and c0 = '0') and (c1 = '1' and c0 =
    '0')) 
    report "error";

    assert(unsigned(b) > unsigned(a) and (c1 = '1' and c0 =
    '0' or c1 = '0' and c0 = '0' or c1 = '1' and c0 = '0'))
    report "error";

    assert(a = b and ((c1 = '1' and c0 = '1') or (c1 /= c0)))
    report "error";

首先,我在 Python 中测试了这个想法(for 循环等),以检查它是否有效(确实有效)。好吧,现在我不知道为什么我的 VHDL 代码不起作用。我有很多错误报告,在我看来没有意义。 有人有想法吗?

COMP96 ERROR COMP96_0329: "Generate statement must have a label." "testbench.vhd" 18 3 COMP96 ERROR COMP96_0019: "Keyword 'generate' expected." "testbench.vhd" 18 22 COMP96 ERROR COMP96_0661: "Expression with a sequence of different logical operators is not allowed. Parenthesize subexpressions containing and, or, xor, and xnor operators." "testbench.vhd" 28 9 COMP96 ERROR COMP96_0016: "Design unit declaration expected." "testbench.vhd" 35 4

如果您需要,我有一个 link 用于整个 VHDL 代码: https://www.edaplayground.com/x/4c2n

您不能在进程外使用 for ... loop(或 function/procedure)。您应该将 for ... loop 放在进程中(或 function/procedure),或者使用 for ... generate 循环。

但是,如果您使用 for ... generate 循环(在进程外),请注意它必须有一个标签(如您的错误消息之一所述)。例如:

loop_label : for i in 0 to 2**n generate
...
end generate;

在您的具体情况下,我建议在进程中使用 for ... loop(最后使用 wait 语句)。

您的代码还有很多其他问题,但这至少会帮助您克服第一个错误。

其他一些需要注意的问题:

  • n 尚未定义。
  • k for k in ... 应该是 for k in ...
  • 0 to 2**n 将循环 2**n + 1 次。你可能想要 0 to 2**n-1.
  • std_logic_vector(i)std_logic_vector(k) 是非法的。你可能想要 std_logic_vector(to_unsigned(i, 4))
  • 您的断言语句可能应该指定 severity。例如,assert <something> report "error" severity failure;
  • 您的缩进不正确,这使您更容易出错。你的循环应该像这样缩进:

    for i in 0 to 2**n-1 loop for k in 0 to 2**n-1 loop a <= std_logic_vector(to_unsigned(i, 4)); b <= std_logic_vector(to_unsigned(k, 4)); ... end loop; end loop;

  • 你的<a> and <b> or <c>这样的逻辑表达式是没有意义的,会被编译器拒绝。你是说 (<a> and <b>) or <c> 还是 <a> and (<b> or <c>)。重要的是要了解你想要什么并适当地加上括号。
  • 在代码中混合使用多种语言通常被认为是不好的做法。选择德语或英语并坚持下去。