2012-12-15 115 views
0

我正在實現一個N位桶式移位器。以不同方式連接STD_LOGIC_VECTOR(桶式移位器) - VHDL

這是我的組件:

entity barrel_shifter is 
    Generic (N : integer := 4); 
    Port (data_in : in STD_LOGIC_VECTOR (N-1 downto 0); 
      shift : in STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift 
      data_out : out STD_LOGIC_VECTOR (N-1 downto 0)); 
end barrel_shifter; 

對於我的目的,我創建了一個N位複用器過了,這是它的代碼:

entity mux is 
    Generic (N : integer := 4); 
    Port (data_in : in STD_LOGIC_VECTOR (N-1 downto 0); 
      sel : in STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift 
      data_out : out STD_LOGIC); 
end mux; 

architecture Behavioral of mux is 

begin 
    data_out <= data_in(to_integer(unsigned(sel))); 
end Behavioral; 

我們實現一個圓形桶移位器我需要以不同的方式連接這些N多路複用器。您可以找到一個示例here,第2頁,圖1.正如您所看到的,IN0只連接D0多路複用器輸入的一次。下一次IN0連接到D1多路複用器輸入,依此類推...(對於其他輸入,這是相同的邏輯)

但是我怎麼才能在VHDL中實現類似的東西呢?如果我沒有將STD_LOGIC_VECTOR作爲輸入,它很容易,但是我需要製作一個通用Barrel Shifter(帶有通用映射結構),所以我不能手動連接每根電線,因爲我不知道通用N 。

在我barrel_shifter實體我嘗試這樣做:

architecture Structural of barrel_shifter is 

    signal q : STD_LOGIC_VECTOR (N-1 downto 0); 

begin 

    connections: for i in 0 to N-1 generate 
     mux: entity work.mux(Behavioral) generic map(N) port map(std_logic_vector(unsigned(data_in) srl 1), shift, q(i)); 
    end generate connections; 

    data_out <= q; 

end Structural; 

但它根本不起作用(「運營商的實際,因此,與正規信號,信號‘DATA_IN’,關聯不是一個信號。 (LRM 2.1.1)「)。我試過使用變量和信號,像這樣:

data_tmp := data_in(i downto 0) & data_in(N-i downto 1); 

但我仍然無法弄清楚正確的方法來做這些連接。

回答

2

哪個工具正在報告?

賽靈思XST報告

barrel_shifter.vhd" Line 20: Actual for formal port data_in is neither a static 
name nor a globally static expression 

這有助於拖住問題,因爲映射到data_in上覆用器表達std_logic_vector(unsigned(data_in) srl 1)。申報臨時信號

architecture Structural of barrel_shifter is 

    signal q : STD_LOGIC_VECTOR (N-1 downto 0); 
    signal temp : STD_LOGIC_VECTOR (N-1 downto 0); 
begin 

    temp <= std_logic_vector(unsigned(data_in) srl 1); 

    connections: for i in 0 to N-1 generate 
     mux: entity work.mux(Behavioral) generic map(N) 
             port map(temp, shift, q(i)); 
    end generate connections; 
    ... 
end 

解決了這個問題。