如何在vhdl v93或v2002中的端口映射中连接2D数组

问题描述 投票:0回答:1

这是我的组件,类型和信号:

    type t_data_bus_array is array(natural range<>, natural range<>) of std_logic;

        component credit
              generic (
                 CREDIT_WIDTH      : natural := 4   
              );
              port (

                 pi     : in  std_logic_vector(CREDIT_WIDTH-1 downto 0);
                 po     : out std_logic_vector(CREDIT_WIDTH-1 downto 0)
              );
        end component;

signal pi_credit_array         : t_data_bus_array(NUMBER_OF_INPUTS-1 downto 0, CREDIT_WIDTH-1 downto 0);
signal po_credit_array         : t_data_bus_array(NUMBER_OF_INPUTS-1 downto 0, CREDIT_WIDTH-1 downto 0);

在我的体系结构中,我会尝试将它们连接起来,但这不起作用。

Credit_X : for I in 0 to NUMBER_OF_INPUTS-1 generate
   Credit_I :
      credit
      generic map(
         CREDIT_WIDTH      => CREDIT_WIDTH   
      )
         pi  => pi_credit_array(I),        
         po  => po_credit_array(I)    
      );
   end generate;   

也可以尝试使用功能:

   -- select specifik row in 2d array 
   function sel_chunk(
      data  : t_data_bus_array;  -- matrix of std_logic
      num   : natural;           -- selected row
      width : natural            -- width of row 
   ) return std_logic_vector is
      variable data_ret_val : std_logic_vector(width-1 downto 0);
   begin
      for i in data_ret_val'range loop
         data_ret_val(i) := data (num, i);
      end loop;
      return data_ret_val;
   end sel_chunk; 

并使用如下功能:

Credit_calculator_X : for I in 0 to NUMBER_OF_INPUTS-1 generate
   Credit_calculator_I :
      credit_calculator
      generic map(
         CREDIT_WIDTH      => CREDIT_WIDTH  
      )
         pi  => sel_chunk( pi_credit_array, I, CREDIT_WIDTH ),      
         po => sel_chunk( po_credit_array, I, CREDIT_WIDTH )   
      );
   end generate;

所以,如何解决此问题并在端口图中连接2D阵列?

arrays vhdl hdl
1个回答
0
投票

这里的问题是t_data_bus_array是2D数组类型。 std_logic_vector是一维数组类型。在VHDL中,根本无法切片多维数组类型,因此您需要创建一个函数以将自定义2D数组类型转换为std_logic_vector。在VHDL '93中,您不能在端口图上使用函数,因此您需要临时信号来在端口图上执行转换功能:

signal tmp : std_logic_vector(CREDIT_WIDTH-1 downto 0);

tmp <= sel_chunk(pi_credit_array, I, CREDIT_WIDTH);

....
port map (
  pi => tmp,

或者,仅使用VHDL 2008,在端口映射上允许使用功能。

或者,创建std_logic_vector的一维数组可能更简单,因为可以对其进行切片。在VHDL 2008中,可以在不限制元素类型的情况下声明数组类型,以便在声明对象时都可以限制维度。

例如

type t_data_bus_array is array(natural range <>) of std_logic_vector;

signal pi_credit_array   : t_data_bus_array(NUMBER_OF_INPUTS-1 downto 0)(CREDIT_WIDTH-1 downto 0);

....

port map (
  pi => pi_credit_array(I),

通常,创建2d数组类型的std_logic将使您的生活变得困难。尽可能避免。

© www.soinside.com 2019 - 2024. All rights reserved.