]> rtime.felk.cvut.cz Git - fpga/uart.git/blobdiff - fifo.vhd
RX modul synchronization changed to falling edges.
[fpga/uart.git] / fifo.vhd
index 99abce7a8b9431b74304904556058300fcd07acd..ae3ca9e0b390ec336d5c30783bc37044a69b1334 100644 (file)
--- a/fifo.vhd
+++ b/fifo.vhd
@@ -3,6 +3,21 @@ use ieee.std_logic_1164.all;
 use ieee.std_logic_arith.all;
 use ieee.std_logic_unsigned.all;
 
+--------------------------------------------------------------------------------
+-- This is a behavioral model of FIFO (Fisrt In First Out) memory.
+--
+-- All operations (except for reset) are synchronous to 'clk' rising edges.
+-- Reset makes fifo empty but actually does not change the content of memory.
+--
+-- The generic parameter 'width' determines the width of address vector used to
+-- access memory and so the size of memory.
+--
+-- When overflow occurs, the 'overflow' flag is set to 1 and the least recent
+-- data is rewritten by new data.
+--
+-- Underflow is not handled currently and causes misfunction.
+--------------------------------------------------------------------------------
+
 entity fifo is
   generic (
     width : integer := 2
@@ -10,13 +25,14 @@ entity fifo is
   port (
     clk      : in  std_logic;
     reset    : in  std_logic;
-    we       : in  std_logic;
-    re       : in  std_logic;
+    we       : in  std_logic;  -- write enable
+    re       : in  std_logic;  -- read enable
+    clear_ow : in  std_logic;  -- clear overflow flag
     d_in     : in  std_logic_vector (7 downto 0);
     d_out    : out std_logic_vector (7 downto 0);
-    full     : out std_logic;
-    hfull    : out std_logic;
-    empty    : out std_logic;
+    full     : out std_logic;  -- fifo is full
+    hfull    : out std_logic;  -- fifo is half full
+    empty    : out std_logic;  -- fifo is empty
     overflow : out std_logic
   );
 end fifo;
@@ -41,6 +57,8 @@ architecture behavioral of fifo is
 
 begin
   
+  -- Handling of overflow output signal and internal length signal, storing
+  --   the number of occupied memory positions.
   process (clk, reset)
   begin
     if (reset = '1') then
@@ -57,10 +75,15 @@ begin
           length <= length + 1;
         end if;
       end if;
+      
+      if (clear_ow = '1') then
+        overflow <= '0';
+      end if;
     end if;
   end process;
 
 
+  -- Handling of address registers and writing to memory.
   process (clk, reset)
   begin
     if (reset = '1') then