不是类型 bit_vector 的有效解析函数

Not a valid resolution function for type bit_vector

我需要为 bit_vector 编写一个解析函数。我知道 bitbit_vector 是 VHDL 中未解析的类型,因此只要您有多个驱动程序用于这些信号之一,就需要解析函数。

我已经成功地实现了 bit 的解析函数,但是我很难实现 bit_vector。这是我在执行语法检查时收到的错误:Line 44: resolve_result is not a valid resolution function for type bit_vector.

这里是解析函数:

function resolve_result(d: bit_vector) return bit_vector is
    variable combined: bit_vector(15 downto 0) := "0000000000000000";   
    begin 
        combined(7 downto 0) := d(7 downto 0);
        combined(15 downto 8) := d(15 downto 8);
        return combined;
end function resolve_result;

subtype resolve_result_bit_vector is resolve_result bit_vector;
signal rResult: resolve_result_bit_vector;

错误,第 44 行,在 subtype 声明中。这在测试平台的架构定义中。

我了解 std_ulogic_vector 类型会自动解析;是否只需要更改此信号的类型?我不需要 std_ulogic_vector 的功能,因此我只使用 bit_vector.

谢谢。

由于您已经为类型 bit 编写了解析函数,因此您可能知道解析函数是什么样的,它们采用什么参数以及它们 return 的值。你可能明白你的函数不能是无约束 bit_vector 类型的解析函数。例如,它总是 return 是 16 位 bit_vector,因此不能用于,比方说,8 位 bit_vector。这不是唯一的原因:对于这样的函数,参数应该是 bit_vector 的无约束数组,即数组的数组。

不管怎样,你真的不需要这些。如果您已经有类型 bit 的解析函数 foobar 只需声明:

subtype resolved_bit_vector is (foobar) bit_vector;

如果你真的想为 16 位 bit_vector 定义一个分辨率函数,比方说一个 or-like,你可以尝试像这样的方法:

subtype b16 is bit_vector(15 downto 0);
type b16_array is array(natural range <>) of b16;

function foobar(v: b16_array) return b16 is
  constant n: natural := v'length;
  constant c: b16_array(0 to n - 1) := v;
begin
  if n = 0 then
    return (15 downto 0 => '0');
  elsif n = 1 then
    return c(0);
  else
    return foobar(c(0 to n - 2)) or c(n - 1);
  end if;
end function foobar;

subtype resolved_b16 is foobar b16;