0

我正在基于 zynq soc 上的 artix-7 结构创建一个堆栈。为了创建我想使用 BRAM 的堆栈,我遇到了一个问题,即 BRAM 读取输出没有改变,我之前使用过很多次 BRAMS(不是 7 系列,所以我可能会遗漏一些微妙的东西)并且我完全困惑为什么要这样做。

我用值填充堆栈: 1, 2 ,3

然后当我连续调用 pop 时,它读出的唯一值是每个 pop 和读取地址的 3(即使在等待一个时钟读取延迟之后)。我也尝试过使用双端口公羊并遇到同样的问题,我坚持使用单端口,因为它更容易尝试和解决问题所在!

我已经使用具有正确行为的基于数组的 ram 验证了逻辑行为。为了验证,我还检查了以下来源的逻辑:http: //vhdlguru.blogspot.co.uk/2011/01/implementation-of-stack-in-vhdl.html

所以问题似乎出在 BRAM 上,要么它没有正确读取,要么由于某种原因它正在将值 3 写入所有先前的内存地址,这是没有意义的,因为每个数据项都与写入信号和正确的地址同步。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
use IEEE.numeric_std.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
library UNISIM;
use UNISIM.VComponents.all;

-- Stack implementation for 32 bit data items using BRAM componenets
entity stack_32_BRAM is
    generic( ADDR : integer :=32);
    Port ( clk : in  STD_LOGIC;
           rst : in  STD_LOGIC;
           en : in  STD_LOGIC;
           push_pop : in  STD_LOGIC;
           data_in : in  STD_LOGIC_VECTOR (31 downto 0);
           data_out : out  STD_LOGIC_VECTOR (31 downto 0));
end stack_32_BRAM;

architecture Behavioral of stack_32_BRAM is

COMPONENT BRAM_32_1K
  PORT (
    clka : IN STD_LOGIC;
    rsta : IN STD_LOGIC;
    wea : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addra : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dina : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    douta : OUT STD_LOGIC_VECTOR(31 DOWNTO 0);
    clkb : IN STD_LOGIC;
    rstb : IN STD_LOGIC;
    web : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addrb : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dinb : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    doutb : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
  );
END COMPONENT;

COMPONENT BRAM_32_1K_SP
  PORT (
    clka : IN STD_LOGIC;
    rsta : IN STD_LOGIC;
    wea : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
    addra : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    dina : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
    douta : OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
  );
END COMPONENT;

--The read ptr is a function of the write ptr
signal stack_ptr_read, stack_ptr_write : std_logic_vector(ADDR-1 downto 0) := (others =>'0');
signal full, empty : std_logic := '0';

 signal     WEA : std_logic_vector(3 downto 0) :=(others=>'0');                      -- 4-bit input: A port write enable
 signal         addra, addrb, dinb, doutb, dina, douta : std_logic_vector(31 downto 0) := (others => '0');
 signal         rsta, rstb :std_logic := '0' ; 

 type ram is array (4 downto -2) of std_logic_vector(31 downto 0) ;
 signal mem : ram :=(others=>(others=>'0'));

begin

 ---STACK LOGIC ---

 PUSH : process (clk, push_pop, en, full, empty)
    begin
        if(clk'event and clk='1') then
        WEA <= "0000";          
            if(en='1' and push_pop = '1' and full = '0') then
                mem(to_integer(unsigned(stack_ptr_write))) <= data_in;
                WEA <= "1111";  
                dina <= data_in ;
                ADDRA <= stack_ptr_write;
                stack_ptr_write <= stack_ptr_write + 1; 
            elsif(en='1' and push_pop = '0' and empty = '0') then   
                data_out <= douta ;--
                doutb <= mem(to_integer(unsigned(stack_ptr_write - 1)));
                ADDRA <= stack_ptr_write - 1;
                stack_ptr_write <= stack_ptr_write - 1;
            end if;
        end if;
    end process;

BRAM_SP : BRAM_32_1K_SP
  PORT MAP (
    clka => clk,
    rsta => rsta,
    wea => wea,
    addra => addra,
    dina => dina,
    douta => douta
  );






end Behavioral;

非常感谢山姆

4

1 回答 1

1

解决方案需要做几件事:

1)您必须在每个进程中使用第一个端口显式重置信号。在他们的声明中初始化它们并没有削减它。具有正确重置和敏感度列表的进程代码应如下所示:

PUSH : process (rst, clk)
begin
    if (rst = '1') then --supposing active-high async. reset
       WEA <= (others => '0');
       ADDRA <= (others => '0');
       dina <= (others => '0');
       data_out <= (others => '0');
       full <= '0';
       empty <= '0';
       stack_ptr_write <= (others => '0');
    elsif(clk'event and clk='1') then
       --your code

2)我知道你在同一个地方有几层/尝试代码。这读起来很乱。我看到您正在使用“mem”来保存您的示例(以便 WEA、ADDRA、dina 等可以忽略),但是当您返回 BRAM_32_1K_SP 时,请记住检查它是否具有 32 位地址,再加上 32 位数据,意思是你有一个 32 * 2**32 位的内存……大约是 128 Gbits,我猜是错字。

但是,要提出更清晰的问题,您应该只留下与您遇到问题的内存解决方案有关的代码。

3)您的代码确实包含一些您应该修复的拼写错误,例如在此过程中分配“doutb”,而我猜您想分配 data_out:

data_out <= mem(to_integer(unsigned(stack_ptr_write - 1)));

这就是为什么你在输出中看不到你想要的东西的原因。

于 2013-11-11T04:34:04.257 回答