如何将array_type(数组)输入转换为std_logic_vector?

问题描述:

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

entity shift_unit is 
Port (clk: in std_logic; 
      a_0 : in STD_LOGIC_VECTOR(15 downto 0); 
     a_1 : in STD_LOGIC_VECTOR(15 downto 0); 
     b_0 : in STD_LOGIC_VECTOR(15 downto 0); 
     b_1 : in STD_LOGIC_VECTOR(15 downto 0); 
     a064 : out STD_LOGIC_VECTOR(15 downto 0); 
      a164 : out STD_LOGIC_VECTOR(15 downto 0); 
     c083,c036 : out STD_LOGIC_VECTOR(15 downto 0); 
      c183,c136 : out STD_LOGIC_VECTOR(15 downto 0)); 
end shift_unit; 

architecture Behavioral of shift_unit is 
type array_type is array (0 to 1) of std_logic_vector(15 downto 0); 

Component SA is 
port(clk: in std_logic;  
    bi: in std_logic_vector(15 downto 0); 
    c83: out std_logic_vector(15 downto 0); 
    c36: out std_logic_vector(15 downto 0));   
    end Component; 
signal b ,c_083,c_036: array_type; 
    begin 

     process(clk) 
     variable i: integer:=0; 
     begin 
     if(rising_edge(clk)) then 
     elsif(i=0) then 
     b(i)<=b_0; 
     i:=i+1; 
     elsif(i=1) then 
      b(i)<=b_1; 
      i:=0; 
     end if; 
    end process; 

     SA_GEN: for I in 0 to 1 generate 
     SA0 : SA port map(clk,b,c_083(I),c_036(I)); --error. Line 65 
     end generate SA_GEN; 

     end Behavioral; 

组件SA是如何将array_type(数组)输入转换为std_logic_vector?

entity SA is 
port(clk: in std_logic; 
    bi: in std_logic_vector(15 downto 0); 
    c83: out std_logic_vector(15 downto 0); 
    c36: out std_logic_vector(15 downto 0));   
end SA; 

当我检查了Syntex它给出一个错误 错误:HDLParsers:820 - “shift_unit_pk.vhdl”第65行的实际类型的端口不符合类型的端口兼容的SA。

这里b,c083和c036是array_type,SA在std_logic_vector中有i/p和o/p端口。我试图将其转换为std_logic_vector,然后映射到SA,但它给出了相同的错误。那么我怎么做这个映射/类型转换。

+0

65是哪里?请在代码中注明此行。在编辑您的代码示例时,请修正缩进。 – Paebbels 2015-01-04 16:20:14

+0

你能解释一下你的程序应该做什么吗?我相信这个过程不能被合成。此外,我认为它不会按照你的意图工作;) - 正如BlueMandora已经说过的,你应该在SA0的portmap中添加一个b之后的索引(I)。 – Paebbels 2015-01-04 16:31:39

+0

是的,我纠正它。 – Raj 2015-01-05 05:59:46

下面是一些修复和改进代码:

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

entity shift_unit is 
    Port (
    clk: in std_logic; 
    a_0 : in STD_LOGIC_VECTOR(15 downto 0); 
    a_1 : in STD_LOGIC_VECTOR(15 downto 0); 
    b_0 : in STD_LOGIC_VECTOR(15 downto 0); 
    b_1 : in STD_LOGIC_VECTOR(15 downto 0); 
    a064 : out STD_LOGIC_VECTOR(15 downto 0); 
    a164 : out STD_LOGIC_VECTOR(15 downto 0); 
    c083,c036 : out STD_LOGIC_VECTOR(15 downto 0); 
    c183,c136 : out STD_LOGIC_VECTOR(15 downto 0) 
); 
end shift_unit; 

architecture Behavioral of shift_unit is 
    type array_type is array (0 to 1) of std_logic_vector(15 downto 0); 

    Component SA is 
    port(
     clk: in std_logic;  
     bi: in std_logic_vector(15 downto 0); 
     c83: out std_logic_vector(15 downto 0); 
     c36: out std_logic_vector(15 downto 0) 
    ); 
    end Component; 

    signal b ,c_083,c_036: array_type; 
begin 

    process(clk) 
    variable i: std_logic := '0'; 
    begin 
    if(rising_edge(clk)) then 
     if(i = '0') then 
     b(0) <= b_0; 
     else 
     b(1) <= b_1; 
     end if; 
     i <= not i; 
    end if; 
    end process; 

    SA_GEN: for I in 0 to 1 generate 
    SA0 : SA 
     port map(
     clk => clk, 
     bi => b(I), 
     c83 => c_083(I), 
     c36 => c_036(I) 
    ); 
    end generate SA_GEN; 
end; 

如果你有兴趣的VHDL类型和功能先进的std_logic_vector,std_logic_vector_vector和std_logic_matrix处理,然后看看这个post:https://codereview.stackexchange.com/questions/73708/vhdl-mux-in-need-of-generics/73794#73794

+0

我们不能使用std_logic进行索引。所以“我”应该是整数。我认为明确的端口映射stlye在这里工作。我得到了o/p。 – Raj 2015-01-05 06:16:40

+0

对不起,我修正了我的指数,所以整数仍然不需要。 – Paebbels 2015-01-05 08:32:04

b是这里的一个数组SA0 : SA port map(clk,b,c083(I),c036(I));它是32位数组。

但在SA中,您需要bi: in std_logic_vector(15 downto 0);它是16位,一个矢量。

SA0 : SA port map(clk,b(I),c083(I),c036(I));可能工作。

c083是一个矢量,你的意思是c_083?

SA0 : SA port map(clk,b(I),c_083(I),c_036(I));

+0

不,我试过了,但它给出了同样的错误。因为我们正在将数组映射到std_logic_vector并从SA映射反转。 – Raj 2015-01-04 15:32:33

+0

@Raj也许你错误c083与c083 – BlueMandora 2015-01-05 03:58:52

+0

是的,我纠正它。 – Raj 2015-01-05 12:46:43