在本网站上提出一些建议后,我决定使用一个时钟FIFO。我在合成它之前模拟它没有错误,在合成了我的模拟代码之后我得到了这个错误:
**警告:同时读写同一地址。 RD无法预测,将RD驱动到X
时间:200877700 ps迭代次数:1实例:/ testbench / FIFO / memory_tile_I_1
但模拟效果与预期一致。在编译之后我再次模拟了代码,我没有得到这个错误,并且仿真工作得像预期的那样。
我的代码是:
library IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
entity FIFO is
Generic (
constant DATA_WIDTH : positive := 8;
constant FIFO_DEPTH : positive := 500
);
Port (
Clock : in STD_LOGIC;
WriteEn : in STD_LOGIC;
DataIn : in STD_LOGIC_VECTOR (DATA_WIDTH - 1 downto 0);
ReadEn : in STD_LOGIC;
DataOut : out STD_LOGIC_VECTOR (DATA_WIDTH - 1 downto 0);
Empty : out STD_LOGIC;
Full : out STD_LOGIC;
ModuleRESET : in STD_LOGIC
);
end FIFO;
architecture FIFO_archi of FIFO is
type FIFO_Memory is array (0 to FIFO_DEPTH - 1) of STD_LOGIC_VECTOR (DATA_WIDTH - 1 downto 0);
signal Memory : FIFO_Memory;
signal Head : natural range 0 to FIFO_DEPTH - 1;
signal Tail : natural range 0 to FIFO_DEPTH - 1;
begin
-- Memory Pointer Process
process (Clock, ModuleRESET)
variable Looped : boolean;
begin
if ModuleRESET = '0' then
Head <= 0;
Tail <= 0;
Looped := false;
Full <= '0';
Empty <= '1';
DataOut <= (others => '0');
elsif rising_edge(Clock) then
if ReadEn = '1' then
if ((Looped = true) or (Head /= Tail)) then
-- Update data output
DataOut <= Memory(Tail);
-- Update Tail pointer as needed
if (Tail = FIFO_DEPTH - 1) then
Tail <= 0;
Looped := false;
else
Tail <= Tail + 1;
end if;
end if;
elsif WriteEn = '1' then
if ((Looped = false) or (Head /= Tail)) then
-- Write Data to Memory
Memory(Head) <= DataIn;
-- Increment Head pointer as needed
if (Head = FIFO_DEPTH - 1) then
Head <= 0;
Looped := true;
else
Head <= Head + 1;
end if;
end if;
end if;
-- Update Empty and Full flags
if (Head = Tail) then
if Looped then
Full <= '1';
else
Empty <= '1';
end if;
else
Empty <= '0';
Full <= '0';
end if;
end if;
end process;
end FIFO_archi;
每次在合成后使用synplify pro在模拟中编写第一个数据时,我都会收到此错误:
当我的缓冲区为空时,我的尾部和头部位于0位置,但由于我有两个带有if-elseif的标志,我怎么可能在读取和写入相同的地址时出错?