首页 > 解决方案 > 从 vhdl 中的另一个常量初始化记录的常量数组

问题描述

我正在为刺激编写常量,并且在从其他常量中构建常量时遇到问题。

更新:在下面的示例中(由 user1155120 提供)

library ieee;
use ieee.std_logic_1164.all; 

package snippet_pkg is

type pixel is record
  x: std_logic_vector(3 downto 0);
  y: std_logic_vector(3 downto 0);     
end record;   

type array_pixel is array (natural range <>) of pixel;
constant array_1 : array_pixel(0 to 2) := 
  (0 => (x"0", x"0"),   
   1 => (x"1", x"1"),  
   2 => (x"2", x"2")  
  );
constant array_2 : array_pixel(0 to 3) := 
  (array_1'range => array_1,    
   3 => pixel'(x"3", x"3") 
);

constant element : pixel := (x => x"3", y => x"3");
constant array_3 : array_pixel(0 to 3) := array_1 & element;
constant array_4 : array_pixel(0 to 3) := array_1 & pixel'(x => x"3", y => x"3");

end package; 

library ieee; 
use ieee.std_logic_1164.all;

use work.snippet_pkg.all;

entity snippet_test is
end entity;

architecture foo of snippet_test is  
begin

PASSIVE: process  
begin  
  for i in 0 to 2 loop  
    report "array_1(" & integer'image(i) & ").x = " & to_string(array_1(i).x);
    report "array_1(" & integer'image(i) & ").y = " & to_string(array_1(i).y);
  end loop;
  for i in 0 to 3 loop  
    report "array_2(" & integer'image(i) & ").x = " & to_string(array_2(i).x);
    report "array_2(" & integer'image(i) & ").y = " & to_string(array_2(i).y);
 end loop;

wait;
end process; 
end architecture;

我有一组记录,如下所示:

type pixel is record
  x  : std_logic_vector(3 downto 0);
  y  : std_logic_vector(3 downto 0); 
end record;

type array_pixel is array (natural range <>) of pixel;

然后我像这样构建一个常量:

constant array_1 : array_pixel(0 to 2) :=
  (0 => (x"0" , x"0"),
   1 => (x"1" , x"1"),
   2 => (x"2" , x"2")
  );

现在我想使用 array_1 构建另一个索引更大的数组,如下所示:

constant array_2 : array_pixel(0 to 3) :=
  (0 to 2 => array_1,
   3 => (x"3" , x"3")
  );

但我在 ModelSim 中收到此错误:

致命:(SIGSEGV)错误的指针访问。致命:vsimk 以代码 211 退出。

我正在通过 VUnit 编译。这是 ModelSim 中的错误还是错误的 VHDL 编码?

更新: ModelSim 导师图形不会产生此错误,但会给出如下错误值:

# ** Note: array_1(0).x = 0000
# ** Note: array_1(0).y = 0000
# ** Note: array_1(1).x = 0001
# ** Note: array_1(1).y = 0001
# ** Note: array_1(2).x = 0010
# ** Note: array_1(2).y = 0010

# ** Note: array_2(0).x = ?(16) U ?(66) ?(9)
# ** Note: array_2(0).y = ?(164) U ?(76) 1
# ** Note: array_2(1).x = ?(208) ?(81) ?(147) 0
# ** Note: array_2(1).y = ?(85) ?(88) U X
# ** Note: array_2(2).x = ?(238) ?(255) ?(238) ?(255)
# ** Note: array_2(2).y = 0UUU
# ** Note: array_2(3).x = 0011
# ** Note: array_2(3).y = 0011 

只有最后一个索引是正确的,而分配的索引是0 to 2 => array_1错误的。

标签: vhdlmodelsim

解决方案


推荐阅读