📄 fifo.vhdl
字号:
-------------------------------------------------------------------------------Add_gen: process(clk,reset) variable q1 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state variable q2 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state variable q3 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state begin -- process ADD_gen -- activities triggered by asynchronous reset (active low) if reset = '0' then q1 := (others =>'0'); q2 := (others =>'0'); q3 := (others =>'0'); -- activities triggered by rising edge of clock elsif clk'event and clk = '1' then if WE = '1' and ( FULL = '0') then q1 := q1 + 1; q3 := q3 +1; else q1 := q1; q3 := q3; end if; if RE = '1' and ( EMPTY = '0') then q2 := q2 + 1; q3 := q3 -1; else q2 := q2; q3 := q3; end if; end if; R_ADD <= q2; W_ADD <= q1; D_ADD <= q3; end process ADD_gen;------------------------------------------------------------------------------- FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MAX_ADDR) else '0'; EMPTY <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MIN_ADDR) else '0'; HALF_FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) > HALF_ADDR) else '0';------------------------------------------------------------------------------- end FIFO_v2;---------------------------------------------------------------------------------------------------------------------------------------------------------------- Input data is _NOT_ latchedlibrary ieee;use ieee.std_logic_1164.all;use ieee.numeric_std.all;--USE ieee.std_logic_signed.ALL;--USE ieee.std_logic_arith.ALL;--------------------------------------------------------------------------------- purpose: FIFO Architecturearchitecture FIFO_v3 of FIFO is-- constant values constant MAX_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '1'); constant MIN_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '0'); constant HALF_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := '0' & (MAX_ADDR'range => '1'); signal R_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Read Address signal W_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Write Address signal D_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Diff Address signal REN_INT : std_logic; -- Internal Read Enable signal WEN_INT : std_logic; -- Internal Write Enable component dpmem generic (ADD_WIDTH : integer := 8; WIDTH : integer := 8 ); port (clk : in std_logic; reset : in std_logic; w_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); r_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); data_in : in std_logic_vector(WIDTH - 1 downto 0); data_out : out std_logic_vector(WIDTH - 1 downto 0 ); WR : in std_logic; RE : in std_logic); end component; begin -- FIFO_v3------------------------------------------------------------------------------- memcore: dpmem generic map (WIDTH => 8, ADD_WIDTH =>8) port map (clk => clk, reset => reset, w_add => w_add, r_add => r_add, Data_in => data_in, data_out => data_out, wr => wen_int, re => ren_int);-------------------------------------------------------------------------------wen_int <= '1' when (WE = '1' and ( FULL = '0')) else '0';ren_int <= '1' when RE = '1' and ( EMPTY = '0') else '0';-------------------------------------------------------------------------------Add_gen: process(clk,reset) variable q1 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state variable q2 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state variable q3 : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Counter state begin -- process ADD_gen -- activities triggered by asynchronous reset (active low) if reset = '0' then q1 := (others =>'0'); q2 := (others =>'0'); q3 := (others =>'0'); -- activities triggered by rising edge of clock elsif clk'event and clk = '1' then if WE = '1' and ( FULL = '0') then q1 := q1 + 1; q3 := q3 +1; else q1 := q1; q3 := q3; end if; if RE = '1' and ( EMPTY = '0') then q2 := q2 + 1; q3 := q3 -1; else q2 := q2; q3 := q3; end if; end if; R_ADD <= q2; W_ADD <= q1; D_ADD <= q3; end process ADD_gen;------------------------------------------------------------------------------- FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MAX_ADDR) else '0'; EMPTY <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MIN_ADDR) else '0'; HALF_FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) > HALF_ADDR) else '0';------------------------------------------------------------------------------- end FIFO_v3;---------------------------------------------------------------------------------------------------------------------------------------------------------------- This arch was synthesized by webfitter -- It is the same as fifo_v1 but-- 1. address variables was changed to signals-- 2. else statement was removed from process sync_data-- 3. address-width was changed to 3 instead of 8-- Input data _is_ latchedlibrary ieee;-- numeric package genertes compile error by webfitter compileruse ieee.std_logic_1164.all;USE ieee.std_logic_signed.ALL;USE ieee.std_logic_arith.ALL;--------------------------------------------------------------------------------- purpose: FIFO Architecturearchitecture FIFO_v4 of FIFO is-- constant values constant MAX_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '1'); constant MIN_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '0'); constant HALF_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := '0' & (MAX_ADDR'range => '1'); constant HALF_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := '0' & (MAX_ADDR'range => '1'); signal Data_in_del : std_logic_vector(WIDTH - 1 downto 0); -- delayed Data in signal R_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Read Address signal W_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Write Address signal D_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Diff Address signal REN_INT : std_logic; -- Internal Read Enable signal WEN_INT : std_logic; -- Internal Write Enable component dpmem generic (ADD_WIDTH : integer := 8; WIDTH : integer := 8 ); port (clk : in std_logic; reset : in std_logic; w_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); r_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); data_in : in std_logic_vector(WIDTH - 1 downto 0); data_out : out std_logic_vector(WIDTH - 1 downto 0 ); WR : in std_logic; RE : in std_logic); end component; begin -- FIFO_v4------------------------------------------------------------------------------- memcore: dpmem generic map (WIDTH => 8, ADD_WIDTH =>8) port map (clk => clk, reset => reset, w_add => w_add, r_add => r_add, Data_in => data_in_del, data_out => data_out, wr => wen_int, re => ren_int);-------------------------------------------------------------------------------Sync_data: process(clk,reset) begin -- process Sync_data if reset ='0' then data_in_del <= (others =>'0'); elsif clk'event and clk = '1' then data_in_del <= data_in;-- else statemnet was removed due to error (hdl -- end if; end process Sync_data;-------------------------------------------------------------------------------wen_int <= '1' when (WE = '1' and ( FULL = '0')) else '0';ren_int <= '1' when RE = '1' and ( EMPTY = '0') else '0';-------------------------------------------------------------------------------Add_gen: process(clk,reset) -- The variables was replaced by add signals begin -- process ADD_gen -- activities triggered by asynchronous reset (active low) if reset = '0' then W_ADD <= (others =>'0'); R_ADD <= (others =>'0'); D_ADD <= (others =>'0'); -- activities triggered by rising edge of clock elsif clk'event and clk = '1' then if WE = '1' and ( FULL = '0') then W_ADD <= W_ADD + 1; D_ADD <= D_ADD +1;-- else-- W_ADD <= W_ADD;-- D_ADD <= D_ADD; end if; if RE = '1' and ( EMPTY = '0') then R_ADD <= R_ADD + 1; D_ADD <= D_ADD -1;-- else-- R_ADD <= R_ADD;-- D_ADD <= D_ADD; end if; end if; end process ADD_gen;------------------------------------------------------------------------------- FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MAX_ADDR) else '0'; EMPTY <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) = MIN_ADDR) else '0'; HALF_FULL <= '1'when (D_ADD(ADD_WIDTH - 1 downto 0) > HALF_ADDR) else '0';------------------------------------------------------------------------------- end FIFO_v4;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- synthesized using webfitter-- Input data is _NOT_ latched-- The same as fifo_v3 but without the use of the variables in add_gen process-- else case in add_gen "RE and WE" was removedlibrary ieee;use ieee.std_logic_1164.all;--use ieee.numeric_std.all;USE ieee.std_logic_signed.ALL;USE ieee.std_logic_arith.ALL;--------------------------------------------------------------------------------- purpose: FIFO Architecturearchitecture FIFO_v5 of FIFO is-- constant values constant MAX_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '1'); constant MIN_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := (others => '0'); constant HALF_ADDR:std_logic_vector(ADD_WIDTH -1 downto 0) := '0' & (MAX_ADDR'range => '1'); signal R_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Read Address signal W_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Write Address signal D_ADD : std_logic_vector(ADD_WIDTH - 1 downto 0); -- Diff Address signal REN_INT : std_logic; -- Internal Read Enable signal WEN_INT : std_logic; -- Internal Write Enable component dpmem generic (ADD_WIDTH : integer := 8; WIDTH : integer := 8 ); port (clk : in std_logic; reset : in std_logic; w_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); r_add : in std_logic_vector(ADD_WIDTH -1 downto 0 ); data_in : in std_logic_vector(WIDTH - 1 downto 0); data_out : out std_logic_vector(WIDTH - 1 downto 0 ); WR : in std_logic; RE : in std_logic); end component; begin -- FIFO_v5------------------------------------------------------------------------------- memcore: dpmem generic map (WIDTH => 8, ADD_WIDTH =>8) port map (clk => clk, reset => reset, w_add => w_add, r_add => r_add, Data_in => data_in, data_out => data_out, wr => wen_int, re => ren_int);-------------------------------------------------------------------------------wen_int <= '1' when (WE = '1' and ( FULL = '0')) else '0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -