查询包中的VHDL泛型

Query on VHDL generics in packages

我编写了一个简单的 VHDL 代码来添加两个包含 32 位浮点数的矩阵。矩阵维度已在包中定义。目前,我在 vhdl 代码中指定矩阵维度并使用包中的相应类型。但是,我想在设计中使用泛型来处理不同维度的矩阵。为此,我将不得不以某种方式使用包中定义的正确类型。我该怎么做呢? 我目前的VHDL代码如下。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use work.mat_pak.all;

entity newproj is
    Port ( clk : in  STD_LOGIC;
           clr : in  STD_LOGIC;
           start : in  STD_LOGIC;
           A_in : in  t2;
           B_in : in  t2;
           AplusB : out  t2;
           parallel_add_done : out  STD_LOGIC);
end newproj;

architecture Behavioral of newproj is
COMPONENT add
  PORT (
    a : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    b : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    clk : IN STD_LOGIC;
    sclr : IN STD_LOGIC;
    ce : IN STD_LOGIC;
    result : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
    rdy: OUT STD_LOGIC
  );
END COMPONENT;


signal temp_out: t2 := (others=>(others=>(others=>'0')));
signal add_over: t2bit:=(others=>(others=>'0'));
signal check_all_done,init_val: std_logic:='0';
begin
    init_val <= '1';
    g0: for k in 0 to 1 generate
                g1: for m in 0 to 1 generate
                            add_instx: add port map(A_in(k)(m), B_in(k)(m),     clk, clr, start, temp_out(k)(m), add_over(k)(m));
                end generate;   
        end generate;

        g2: for k in 0 to 1 generate
                g3: for m in 0 to 1 generate
                        check_all_done <= add_over(k)(m) and init_val;
                end generate;   
        end generate;

        p1_add:process(check_all_done,temp_out)
        begin
            AplusB <= temp_out;
            parallel_add_done <= check_all_done;            
        end process;

end Behavioral;

我的包裹如下

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.ALL;

    package mat_pak is


    subtype small_int is integer range 0 to 2;

    type t22 is array (0 to 1) of std_logic_vector(31 downto 0);
    type t2 is array (0 to 1) of t22; --2*2 matrix

    type t22bit is array (0 to 1) of std_logic;
    type t2bit is array (0 to 1) of t22bit; --2*2 matrix bit

    type t33 is array (0 to 2) of std_logic_vector(31 downto 0);
    type t3 is array (0 to 2) of t33; --3*3 matrix

end mat_pak;

欢迎提出任何建议。谢谢。

我不太确定是否完全理解,但我会尽力回答 ;)

您可以像这样使用无约束数组:

package mat_pak is
  type matrix is array(natural range <>, natural range <>) of std_logic_vector(31 downto 0);
end package mat_pack;

entity newproj is
Generic ( size : natural );
Port ( clk : in  STD_LOGIC;
       clr : in  STD_LOGIC;
       start : in  STD_LOGIC;
       A_in : in  matrix(0 to size-1, 0 to size-1);
       B_in : in  matrix(0 to size-1, 0 to size-1);
       AplusB : out  matrix(0 to size-1, 0 to size-1);
       parallel_add_done : out  STD_LOGIC);
end newproj;

您的设计存在一些逻辑问题。

首先,设计可以容忍的子层次结构有一些最大端口数,您有 192 'bits' 个矩阵输入和输出。你真的相信这个数字应该是可配置的吗?

在某些时候它只适合非常大的 FPGA 设备,不久之后也不适合那里。

想象一些操作在 addparallel_add_done 中采用可变数量的时钟表示何时 aplusb 数据可用,该数据由所有实例化 [= 提供的矩阵数组的元素组成11=] 个组件,各个 rdy 信号被“与”在一起。如果 add 都花费相同的时间,您可以从其中任何一个获取 rdy(如果您的芯片不是那么确定性,它将无法使用,[=11= 中有寄存器]).

嵌套的generate语句都是赋值add_over(k,m)与init_val1的综合常数)的AND运算结果。效果或将 add_over(k.m) 位连接在一起(这在 VHDL 中不起作用,并且在综合中也可能无法实现)。

注意我还展示了二维数组的正确索引方法。

使用 Jonathan 调整矩阵大小的方法:

library ieee;
use ieee.std_logic_1164.all;

package mat_pak is

    type matrix  is array (natural range <>, natural range <>)
               of std_logic_vector(31 downto 0);
    type bmatrix is array (natural range <>, natural range <>) 
               of std_logic;                      
end package mat_pak;

library ieee;
use ieee.std_logic_1164.all;
use work.mat_pak.all;

entity newproj is
    generic ( size:  natural := 2 );
    port ( 
        clk:                in  std_logic;
        clr:                in  std_logic;
        start:              in  std_logic;
        a_in:               in  matrix (0 to size - 1, 0 to size - 1);
        b_in:               in  matrix (0 to size - 1, 0 to size - 1);
        aplusb:             out matrix (0 to size - 1, 0 to size - 1);
        parallel_add_done:  out std_logic
    );
end entity newproj;

architecture behavioral of newproj is
    component add
        port (
            a:      in  std_logic_vector(31 downto 0);
            b:      in  std_logic_vector(31 downto 0);
            clk:    in  std_logic;
            sclr:   in  std_logic;
            ce:     in  std_logic;
            result: out std_logic_vector(31 downto 0);
            rdy:    out std_logic
        );
    end component;

    signal temp_out: matrix (0 to size - 1, 0 to size - 1) 
                :=  (others => (others => (others => '0')));
    signal add_over: bmatrix (0 to size - 1, 0 to size - 1)
                := (others => (others => '0'));
begin
g0: 
    for k in  0 to size - 1 generate 
g0x: 
        for m in 0 to size - 1 generate
            add_instx: add 
                port map (
                    a => a_in(k,m),
                    b => b_in(k,m),
                    clk => clk,
                    sclr => clr,
                    ce => start,
                    result => temp_out(k,m),
                    rdy => add_over(k,m)
                );
        end generate;   
    end generate;

    aplusb <= temp_out;

p1_add:
    process (add_over)
        variable check_all_done: std_logic;
    begin
        check_all_done := '1';
        for k in 0 to size - 1 loop
            for m in 0 to size -1 loop
                check_all_done := check_all_done and add_over(k,m);
            end loop;
        end loop;
        parallel_add_done <= check_all_done;
    end process;

end architecture behavioral;

我们发现我们确实想要将各种 rdy 输出(add_over 数组)与在一起。在 VHDL -2008 中,这可以使用一元 AND 来完成,否则您将指望综合工具来展平 AND(他们通常会这样做)。

我将 aplusb 的作业设为并发作业。

所以我伪造了一个空架构的add实体,上面再分析,阐述和模拟,这表明none的连接在任何地方都有长度不匹配。