使用 Vivado 将函数的返回值分配给 VHDL 中的多维数组失败 [英] Assigning return value of a function to multidimensional arrays in VHDL fails with Vivado

查看:24
本文介绍了使用 Vivado 将函数的返回值分配给 VHDL 中的多维数组失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下包,它定义了一个二维数组类型和一些返回初始化二维数组的随机函数.

I have the following package which defines a 2D array type and some random function which returns an initialized 2D array.

-- <matrix.vhd>
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

package matrix is     
    type matrix is array(integer range<>, integer range<>) of std_logic;
    function initmatrix(m: integer; n: integer) return matrix;
end package matrix;

package body matrix is
    
    function initmatrix(m: integer; n: integer) return matrix is
        variable a: matrix(m - 1 downto 0, n - 1 downto 0); 
    begin 
        for i in a'range(1) loop 
            for j in a'range(2) loop 
                if i = j then 
                    a(i, j) := '1';
                else 
                    a(i, j) := '0';
                end if;
            end loop;
        end loop;
        return a;
    end function initmatrix;
    
end package body matrix;

在下面的示例中,我尝试将函数 initmatrix 的返回值分配给一个信号.不过这有一些奇怪的行为.

In the following example I try to assign the return value of the function initmatrix to a signal. This has some strange behaviour though.

-- <tb_test.vhd>
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use work.matrix.all;

entity tb_test is
end tb_test;

architecture x of tb_test is
    signal m: matrix(3 downto 0, 2 downto 0);
begin

    process 
        variable t: matrix(3 downto 0, 2 downto 0);
    begin
        m <= ("000", "000", "000", "000");  
        wait for 10 ns;
        
        -- This one does not work!
        -- results in ("000", 1UU", "UUU", "UUU")
        m <= initmatrix(4, 3);
        wait for 10 ns;
        
        -- This one does work!
        -- exactly the same as the function body
        for i in t'range(1) loop 
            for j in t'range(2) loop 
                if i = j then 
                    t(i, j) := '1';
                else
                    t(i, j) := '0';
                end if;
            end loop;
        end loop;
        m <= t;
        
        wait;
    end process;

end x;

相同的构造(将函数的返回值分配给信号)似乎只对多维数组失败.我一直在为任何其他类型这样做.

The same construct (assigning the return value of a function to a signal) only seems to fail for multidimensional arrays. I do this all the time for any other type.

我是否忽略了什么?

我使用的是 Vivado 2020.2,除了 Vivado 内置的模拟器之外,没有尝试过任何其他模拟器.

I am using Vivado 2020.2, have not tried any other simulator other than the one built into Vivado.

推荐答案

看来 Vivado 模拟器不喜欢将不受约束的多维数组作为函数的返回类型,至少对于 2008 年之前的 VHDL 版本不喜欢.

It appears the Vivado simulator does not like unconstrained multidimensional arrays as a return type for functions, at least not for VHDL versions prior to 2008.

无约束的单维数组或有约束的多维数组都没有问题:

There is no issue with either unconstrained single dimensional arrays or constrained multi dimensional ones like these:

type vector is array(integer range <>) of std_logic;
type matrix4x3 is array(3 downto 0, 2 downto 0) of std_logic;

为了使用 Vivado 正确模拟问题中的示例,需要将源文件的文件类型设置为 VHDL 2008.请注意,并非所有工具都可以完全处理 VHDL 2008,仍然不建议使用此如果您希望代码可移植.

For correctly simulating the example in the question with Vivado, the file type of the source files needs to be set to VHDL 2008. Be aware that not all tools can fully handle VHDL 2008, and it is still not recommended to use this if you want your code to be portable.

在 Vivado 中将(所有)源文件设置为 VHDL 2008 是通过

Setting (all) source files to VHDL 2008 in Vivado is done with

set_property FILE_TYPE {VHDL 2008} [get_files *.vhd]

这篇关于使用 Vivado 将函数的返回值分配给 VHDL 中的多维数组失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆