1

在 VHDL 中,我有一个记录数组。我想做一个 if 语句,在其中检查该记录的某些元素在整个数组的每个索引处是否为“0”。我怎样才能做到这一点?所以如果我有

type offset_t is record
 a : std_logic;
 b : std_logic;
end record

type offset_array is (7 downto 0) of offset_t;

type blah is record
 offset2 : offset_array;
end record

如何检查offset2(7 downto 0)is的“a”元素0?if 语句是什么?我尝试了使用'range和其他方式,但无法使其正常工作。

4

3 回答 3

3

如果只想检查a元素,则必须迭代:

for i in a.offset2'range loop
   assert a.offset2(i).a = '0';
end loop;

如果您想检查所有地方的所有内容都为零,请创建一个常量:

constant all_zeros : blah := (offset2 => (others => (others => '0')));

然后你可以与之比较:

assert a = offset2;
于 2013-06-26T15:21:52.787 回答
0

这是一个建议,您可以轻松插入 if 语句(查找 aElementOfOffset2IsZero)。

architecture rtl of if_record_array_record is

    type offset_t is record 
        a : std_logic; 
        b : std_logic; 
    end record;

    type offset_array is array(7 downto 0) of offset_t;
    type blah is record 
        offset2 : offset_array; 
    end record;

    function aElementOfOffset2IsZero(
        record_array_record : blah
    ) return boolean is
    variable result : boolean := TRUE;
    begin
        for i in 0 to record_array_record.offset2'length loop
            if record_array_record.offset2(i).a = '1'  then
                result := FALSE;
            end if;

        end loop;

        return result;

    end function;

    signal ablah : blah;

begin  

    process
    begin
        --if statement you wanted
        if aElementOfOffset2IsZero( ablah ) then
            --...
        end if;
        wait;
    end process;

end architecture rtl;
于 2013-06-28T16:20:17.027 回答
0

试试a.offset2 = (7 downto 0 => (a => '0', b => '0'));。您在数据类型示例中犯了一些错误。下面的代码应该可以工作。

architecture RTL of demo is
    type offset_t is record
        a : std_logic;
        b : std_logic;
    end record;

    type offset_array is array (7 downto 0) of offset_t;
    type blah is record
        offset2 : offset_array;
    end record;
    signal a : blah;
begin
    a.offset2 <= (others => (a => '0', b => '0'));
    assert a.offset2 = (7 downto 0 => (a => '0', b => '0'));
end architecture RTL;
于 2013-06-24T18:32:14.043 回答