aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/issue2053/generic_fifo_fwft.vhdl
blob: c226aade0367af32a6be1e958400d591c97c428f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;

entity generic_fifo_fwft is 
  generic (
    type stream_t;
    size : integer := 256;
    async_reset : boolean := false
  );
  port (
         clk     : in  std_logic;
         rst     : in  std_logic;
         datain  : in  stream_t;
         dataout : out stream_t;
         empty   : out std_logic;
         full    : out std_logic;
         wr      : in  std_logic;
         rd      : in  std_logic
       );
end;
architecture a_generic_fifo_fwft of generic_fifo_fwft is 
  type memory_t is array(size-1 downto 0) of stream_t;
  signal wrptr : integer range 0 to size - 1;
  signal rdptr : integer range 0 to size - 1;
  signal mem : memory_t;
  signal inverted : boolean;
begin

  empty <= '1' when (rdptr = wrptr) and not inverted else '0';
  full  <= '1' when (rdptr = wrptr) and     inverted else '0';

  dataout <= mem(rdptr);

  process (all) is
  begin
    if rising_edge(clk) then
      if wr and not full then
        mem(wrptr) <= datain;
        wrptr <= wrptr + 1;
      end if;
      if rd and not empty then
        rdptr <= rdptr + 1;
      end if;
      if wr and rd then
        null;
      elsif wr and not full then
        inverted <= not inverted when wrptr + 1 mod size < wrptr;
      elsif rd and not empty then
        inverted <= not inverted when rdptr + 1 mod size < rdptr;
      end if;
      if not async_reset then
        if rst then
          inverted <= false;
          rdptr <= 0;
          wrptr <= 0;
        end if;
      end if;
    end if;
    if async_reset then
      if rst then
        inverted <= false;
        rdptr <= 0;
        wrptr <= 0;
      end if;
    end if;
  end process;
end;