⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fifo.vhd

📁 FIFO电路(first in
💻 VHD
字号:
-- =================================================================================================
-- File name    :   fifo.vhd
-- =================================================================================================
-- Entity       :   FIFO
-- Function     :   FIRST IN FIRST OUT
-- Type         :   RTL
-- -------------------------------------------------------------------------------------------------                                                        ------------------
-- Update History :
-- -------------------------------------------------------------------------------------------------
-- Rev.level  Date         Code by                Contents
-- 0.0.0      2006/03/15
-- =================================================================================================
-- End Revision
-- =================================================================================================

library IEEE;
       use IEEE.STD_LOGIC_1164.ALL;
       use IEEE.STD_LOGIC_ARITH.ALL;
       use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FIFO is
      port(
      -- Goble signal
          RST   :in std_logic;                               --Globe reset
          CLK   :in std_logic;                               --Globe clock 20Mhz
      -- User interface
          WEN   :in std_logic;                               -- Write enable
          REN   :in std_logic;                               -- Read  enable
          OE    :in std_logic;                               -- Output enable
          DIN   :in std_logic_vector(15 downto 0);           -- Data input
          DOUT  :out std_logic_vector(15 downto 0);          -- Data output
          EF    :out std_logic;                              -- Blockram empty
          FF    :out std_logic;                              -- Blockram full
          AEF   :out std_logic                               -- Almost empty
         );
end entity;
architecture RTL of FIFO is
       component dpram16b16w is
       	port (
               ADDRA   :   in      std_logic_vector(3 downto 0)    ;
               ADDRB   :   in      std_logic_vector(3 downto 0)    ;
               CLKA    :   in      std_logic                       ;
               CLKB    :   in      std_logic                       ;
               DINA    :   in      std_logic_vector(15 downto 0)   ;
               DOUTB   :   out     std_logic_vector(15 downto 0)   ;
               ENA     :   in      std_logic                       ;
               ENB     :   in      std_logic                       ;
               WEA     :   in      std_logic
          );
       end  component;
--==============================================================================
--                           INTERNAL SIGNAL
--==============================================================================
       signal R_ADD_W   :std_logic_vector(3 downto 0);       -- Write address
       signal R_ADD_R   :std_logic_vector(3 downto 0);       -- Read address
       signal S_DOUT    :std_logic_vector(15 downto 0);      -- Internal data output
       signal R_EF      :std_logic;                          -- Internal empty  flag
       signal R_FF      :std_logic;                          -- Internal full   flag
       signal R_AEF     :std_logic;                          -- Internal almost empty flag
       signal S_WEN     :std_logic;                          -- Write enable
       signal S_REN     :std_logic;                          -- Read enable
begin
--==============================================================================
--                           CALL THE BLOCKRAM
--==============================================================================
         u:dpram16b16w
       port map(
               ADDRA=>R_ADD_W,
               ADDRB=>R_ADD_R,
               CLKA=>CLK,
               CLKB=>CLK,
               DINA=>DIN,
               DOUTB=>S_DOUT,
               ENA=>'1',
               ENB=>S_REN,
               WEA=>S_WEN
               );
--==============================================================================
--                Write point part
--==============================================================================
-------WRITE ADDRESS COUNTER
    process(RST,CLK)begin
       if (RST='1') then
           R_ADD_W<="0000";
       elsif (CLK'Event and CLK='1') then
          if (S_WEN='1') then
              	  R_ADD_W<=R_ADD_W+1;
          end if;
       end if;
    end process;
--==============================================================================
--                read point part
--==============================================================================
-------READ ADDRESS COUNTER
   process(RST,CLK)begin
       if (RST='1') then
           R_ADD_R<="0000";
       elsif(CLK'Event and CLK='1') then
           if(S_REN='1') then
                  R_ADD_R<=R_ADD_R+1;
           end if;
       end if;
   end process;
-------REAL WRITE ENABLE AND READ ENABLE
       S_WEN<=WEN and (not R_FF );
       S_REN<=REN and (not R_EF );
--==============================================================================
--                FullFlag part
--==============================================================================
-------PRODUCE THE FULL FLAG
   process(RST,CLK)begin
       if (RST='1') then
           R_FF<='0';
       elsif (CLK'Event and CLK='1') then
          if((S_WEN='1'and S_REN='0')and(R_ADD_W+1=R_ADD_R)) then
                  R_FF<='1';
          elsif(S_REN='1') then
               	  R_FF<='0';
          end if;
       end if;
   end process;
--==============================================================================
--                EmptyFlag part
--==============================================================================
-------PRODUCE THE EMPTY FLAG
   process(RST,CLK)begin
       if (RST='1') then
           R_EF<='1';
       elsif(CLK'Event and CLK='1') then
          if((S_REN='1'and S_WEN='0')and(R_ADD_W=R_ADD_R+1)) then
                 R_EF<='1';
          elsif(S_WEN='1') then
              	 R_EF<='0';
          end if;
       end if;
   end process;
 --==============================================================================
 --                AlmostEmptyFlag part
 --==============================================================================
 -------PRODUCE THE ALMOSTEMPTY FLAG
   process(RST,CLK)begin
       if (RST='1') then
           R_AEF<='0';
       elsif(CLK'Event and CLK='1') then
           if(S_REN='1' and S_WEN='0') then
              if( R_ADD_R+"0010"=R_ADD_W ) then
                 R_AEF <= '1' ;
              else
              	 R_AEF <= '0' ;
              end if;
           elsif ( S_WEN='1' AND S_REN='0' ) then
              if( R_ADD_R=R_ADD_W )then
                 R_AEF<='1';
              else
              	R_AEF<='0';
              end if;
           end if;
       end if;
   end process;
--==============================================================================
--                Output part
--==============================================================================
	   FF<=R_FF;
	   EF<=R_EF;
	   AEF<=R_AEF;
	   DOUT<=S_DOUT when OE='1' else
           (others=>'Z');
end  RTL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -