2013-10-20 29 views
0

我有一個輸入信號是std_logic_vector並擁有一個地址。我用它從內存中讀取,我需要讀取500位,但由於我的內存數據總線只有256位寬,所以我需要讀取兩個連續的256位塊。要做到這一點,我想第一次從存儲在信號中的地址讀取,第二次從地址存儲後的256位(32字節)地址讀取。如何將常數添加到std_logic_vector添加一個常數到std_logic_vector

ADRESS : in std_logic_vector (0 to 31); 

--code 

--read first word: 
dfmc_DDR2Interface_address <= ADRESS; 
dfmc_DDR2Interface_read <= '1'; 

-- more code 

--read second word (what I want to do) 
dfmc_DDR2Interface_address <= ADRESS+32; 
dfmc_DDR2Interface_read <= '1'; 

回答

1

最簡單的辦法是使用numeric_std_unsigned包:

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std_unsigned.all; -- if you add this... 

entity add_integer_literal_to_slv_signal is 
    port (
     address: in std_logic_vector(0 to 31); 
     dfmc_DDR2Interface_address: out std_logic_vector (0 to 31); 
     dfmc_DDR2Interface_read: out std_logic 
    ); 
end; 

architecture example of add_integer_literal_to_slv_signal is 
begin 
    --read first word: 
    dfmc_DDR2Interface_address <= address; 
    dfmc_DDR2Interface_read <= '1'; 

    -- more code 

    --read second word (what I want to do) 
    dfmc_DDR2Interface_address <= address + 256; -- ...this will work out of the box! 
    dfmc_DDR2Interface_read <= '1'; 
end; 

爲了記錄在案,你應該採取適當的面貌邁向numeric_std包。 @JimLewis對VHDL 2008算術有一個很好的綜合: http://www.gstitt.ece.ufl.edu/vhdl/refs/vhdl_math_tricks_mapld_2003.pdf

0

一個解決方案是問你的設計的上下文中的地址是什麼意思。

如果我像通常發現的那樣代表一個無符號數,最簡潔的答案是將Address聲明爲unsigned類型(來自numeric_std)庫,或者有時甚至是作爲Natural的一個範圍子類型。

然後添加整數將會很簡單,沒有大驚小怪,並且VHDL-2008對腦死亡工具的支持也沒有問題。

在您的測試平臺中,您可能必須將其轉換爲std_logic_vector才能連接到設計不佳的仿真模型,但此類轉換可能很少。