gpt4 book ai didi

vhdl - 初始化动态 VHDL 阵列

转载 作者:行者123 更新时间:2023-12-02 09:24:15 26 4
gpt4 key购买 nike

--in the package
type t_array is array (natural range <>) of std_logic_vector (7 downto 0);
type p_array is access t_array;

--in my testbench
variable my_array : p_array := null;
begin
my_array := new t_array(0 to 19);
my_array := ( X"00",X"00",X"00",X"00",X"FF",
X"FF",X"FF",X"FF",X"00",X"00",
X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF" );

Error: Target type util_lib.tb_pkg.p_array in variable assignment is different from expression type util_lib.tb_pkg.t_array.

如何紧凑地分配数组的所有元素?

最佳答案

(1)。取消引用您的 pointcough 访问类型。

my_array.all := (...);

(2) 从函数初始化

begin
my_array := new_array(20);

初始化它的血腥细节可以隐藏在函数中,它可以通过算法计算值,从常量数组​​中复制它们,甚至从文件中读取内容。

constant initialiser : t_array := (...);

function new_array(length : natural range initialiser'range) return t_array is
variable temp : p_array := new t_array(0 to length - 1);
begin
-- either this
for i in temp'range loop
temp(i) := initialiser(i);
end loop;
-- or simply this
temp.all := initialiser(temp'range);
return temp;
end new_array;

(注意对 new_array 参数的约束:确保它不会创建大于初始化程序的数组。)

关于vhdl - 初始化动态 VHDL 阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39140745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com