lpp_FIFO.vhd
188 lines
| 5.5 KiB
| text/x-vhdl
|
VhdlLexer
|
r356 | ------------------------------------------------------------------------------ | ||
-- This file is a part of the LPP VHDL IP LIBRARY | ||||
-- Copyright (C) 2009 - 2012, Laboratory of Plasmas Physic - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------ | ||||
-- Author : Martin Morlot | ||||
-- Mail : martin.morlot@lpp.polytechnique.fr | ||||
------------------------------------------------------------------------------ | ||||
LIBRARY IEEE; | ||||
USE IEEE.std_logic_1164.ALL; | ||||
USE IEEE.numeric_std.ALL; | ||||
LIBRARY lpp; | ||||
USE lpp.lpp_memory.ALL; | ||||
USE lpp.iir_filter.ALL; | ||||
LIBRARY techmap; | ||||
USE techmap.gencomp.ALL; | ||||
ENTITY lpp_fifo IS | ||||
GENERIC( | ||||
tech : INTEGER := 0; | ||||
Mem_use : INTEGER := use_RAM; | ||||
DataSz : INTEGER RANGE 1 TO 32 := 8; | ||||
AddrSz : INTEGER RANGE 2 TO 12 := 8 | ||||
); | ||||
PORT( | ||||
|
r357 | clk : IN STD_LOGIC; | ||
|
r356 | rstn : IN STD_LOGIC; | ||
|
r357 | -- | ||
reUse : IN STD_LOGIC; | ||||
--IN | ||||
|
r356 | ren : IN STD_LOGIC; | ||
rdata : OUT STD_LOGIC_VECTOR(DataSz-1 DOWNTO 0); | ||||
|
r357 | |||
--OUT | ||||
|
r356 | wen : IN STD_LOGIC; | ||
wdata : IN STD_LOGIC_VECTOR(DataSz-1 DOWNTO 0); | ||||
|
r357 | |||
empty : OUT STD_LOGIC; | ||||
|
r356 | full : OUT STD_LOGIC; | ||
|
r357 | almost_full : OUT STD_LOGIC | ||
|
r356 | ); | ||
END ENTITY; | ||||
ARCHITECTURE ar_lpp_fifo OF lpp_fifo IS | ||||
SIGNAL sFull : STD_LOGIC; | ||||
SIGNAL sFull_s : STD_LOGIC; | ||||
SIGNAL sEmpty_s : STD_LOGIC; | ||||
SIGNAL sEmpty : STD_LOGIC; | ||||
SIGNAL sREN : STD_LOGIC; | ||||
SIGNAL sWEN : STD_LOGIC; | ||||
SIGNAL sRE : STD_LOGIC; | ||||
SIGNAL sWE : STD_LOGIC; | ||||
SIGNAL Waddr_vect : STD_LOGIC_VECTOR(AddrSz-1 DOWNTO 0) := (OTHERS => '0'); | ||||
SIGNAL Raddr_vect : STD_LOGIC_VECTOR(AddrSz-1 DOWNTO 0) := (OTHERS => '0'); | ||||
SIGNAL Waddr_vect_s : STD_LOGIC_VECTOR(AddrSz-1 DOWNTO 0) := (OTHERS => '0'); | ||||
SIGNAL Raddr_vect_s : STD_LOGIC_VECTOR(AddrSz-1 DOWNTO 0) := (OTHERS => '0'); | ||||
SIGNAL almost_full_s : STD_LOGIC; | ||||
SIGNAL almost_full_r : STD_LOGIC; | ||||
BEGIN | ||||
--================================================================================== | ||||
-- /!\ syncram_2p Write et Read actif a l'�tat haut /!\ | ||||
-- A l'inverse de RAM_CEL !!! | ||||
--================================================================================== | ||||
memRAM : IF Mem_use = use_RAM GENERATE | ||||
SRAM : syncram_2p | ||||
GENERIC MAP(tech, AddrSz, DataSz) | ||||
|
r357 | PORT MAP(CLK, sRE, Raddr_vect, rdata, CLK, sWE, Waddr_vect, wdata); | ||
|
r356 | END GENERATE; | ||
--================================================================================== | ||||
memCEL : IF Mem_use = use_CEL GENERATE | ||||
CRAM : RAM_CEL | ||||
GENERIC MAP(DataSz, AddrSz) | ||||
|
r357 | PORT MAP(wdata, rdata, sWEN, sREN, Waddr_vect, Raddr_vect, CLK, rstn); | ||
|
r356 | END GENERATE; | ||
--================================================================================== | ||||
--============================= | ||||
-- Read section | ||||
--============================= | ||||
sREN <= REN OR sEmpty; | ||||
sRE <= NOT sREN; | ||||
|
r357 | sEmpty_s <= '0' WHEN ReUse = '1' else | ||
|
r356 | '1' WHEN sEmpty = '1' AND Wen = '1' ELSE | ||
'1' WHEN sEmpty = '0' AND (Wen = '1' AND Ren = '0' AND Raddr_vect_s = Waddr_vect) ELSE | ||||
'0'; | ||||
Raddr_vect_s <= STD_LOGIC_VECTOR(UNSIGNED(Raddr_vect) +1); | ||||
|
r357 | PROCESS (clk, rstn) | ||
|
r356 | BEGIN | ||
IF(rstn = '0')then | ||||
Raddr_vect <= (OTHERS => '0'); | ||||
sempty <= '1'; | ||||
|
r357 | ELSIF(clk'EVENT AND clk = '1')then | ||
|
r356 | sEmpty <= sempty_s; | ||
IF(sREN = '0' and sempty = '0')then | ||||
Raddr_vect <= Raddr_vect_s; | ||||
END IF; | ||||
END IF; | ||||
END PROCESS; | ||||
--============================= | ||||
-- Write section | ||||
--============================= | ||||
sWEN <= WEN OR sFull; | ||||
sWE <= NOT sWEN; | ||||
|
r357 | sFull_s <= '1' WHEN ReUse = '1' else | ||
|
r356 | '1' WHEN Waddr_vect_s = Raddr_vect AND REN = '1' AND WEN = '0' ELSE | ||
'1' WHEN sFull = '1' AND REN = '1' ELSE | ||||
'0'; | ||||
almost_full_s <= '1' WHEN STD_LOGIC_VECTOR(UNSIGNED(Waddr_vect) +2) = Raddr_vect AND REN = '1' AND WEN = '0' ELSE | ||||
'1' WHEN almost_full_r = '1' AND WEN = REN ELSE | ||||
'0'; | ||||
Waddr_vect_s <= STD_LOGIC_VECTOR(UNSIGNED(Waddr_vect) +1); | ||||
|
r357 | PROCESS (clk, rstn) | ||
|
r356 | BEGIN | ||
IF(rstn = '0')then | ||||
Waddr_vect <= (OTHERS => '0'); | ||||
sfull <= '0'; | ||||
almost_full_r <= '0'; | ||||
|
r357 | ELSIF(clk'EVENT AND clk = '1')then | ||
|
r356 | sfull <= sfull_s; | ||
almost_full_r <= almost_full_s; | ||||
IF(sWEN = '0' and sfull = '0')THEN | ||||
Waddr_vect <= Waddr_vect_s; | ||||
END IF; | ||||
END IF; | ||||
END PROCESS; | ||||
almost_full <= almost_full_s; | ||||
full <= sFull_s; | ||||
empty <= sEmpty_s; | ||||
END ARCHITECTURE; | ||||