1 | ---------------------------------------------------------------------------------- |
---|
2 | -- Company: |
---|
3 | -- Engineer: |
---|
4 | -- |
---|
5 | -- Create Date: 04:35:05 10/15/2012 |
---|
6 | -- Design Name: |
---|
7 | -- Module Name: FIfo_mem - Behavioral |
---|
8 | -- Project Name: |
---|
9 | -- Target Devices: |
---|
10 | -- Tool versions: |
---|
11 | -- Description: |
---|
12 | -- |
---|
13 | -- Dependencies: |
---|
14 | -- |
---|
15 | -- Revision: |
---|
16 | -- Revision 0.01 - File Created |
---|
17 | -- Additional Comments: |
---|
18 | -- |
---|
19 | ---------------------------------------------------------------------------------- |
---|
20 | |
---|
21 | library IEEE; |
---|
22 | use IEEE.std_logic_1164.all; |
---|
23 | use IEEE.std_logic_unsigned.all; |
---|
24 | entity FIFO_LOGIC is |
---|
25 | generic (N: integer := 3); |
---|
26 | port (CLK, PUSH, POP, INIT: in std_logic; |
---|
27 | ADD: out std_logic_vector(N-1 downto 0); |
---|
28 | FULL, EMPTY, WE, NOPUSH, NOPOP: buffer std_logic); |
---|
29 | end entity FIFO_LOGIC; |
---|
30 | architecture RTL of FIFO_LOGIC is |
---|
31 | signal WPTR, RPTR: std_logic_vector(N-1 downto 0); |
---|
32 | signal LASTOP: std_logic; |
---|
33 | begin |
---|
34 | SYNC: process (CLK) begin |
---|
35 | if (CLK'event and CLK = '1') then |
---|
36 | if (INIT = '1') then -- initialization -- |
---|
37 | WPTR <= (others => '0'); |
---|
38 | RPTR <= (others => '0'); |
---|
39 | LASTOP <= '0'; |
---|
40 | elsif (POP = '1' and EMPTY = '0') then -- pop -- |
---|
41 | RPTR <= RPTR + 1; |
---|
42 | LASTOP <= '0'; |
---|
43 | elsif (PUSH = '1' and FULL = '0') then -- push -- |
---|
44 | WPTR <= WPTR + 1; |
---|
45 | LASTOP <= '1'; |
---|
46 | end if; -- otherwise all Fs hold their value -- |
---|
47 | end if; |
---|
48 | end process SYNC; |
---|
49 | COMB: process (PUSH, POP, WPTR, RPTR, LASTOP, FULL, EMPTY) begin |
---|
50 | -- full and empty flags -- |
---|
51 | if (RPTR = WPTR) then |
---|
52 | if (LASTOP = '1') then |
---|
53 | FULL <= '1'; |
---|
54 | EMPTY <= '0'; |
---|
55 | else |
---|
56 | FULL <= '0'; |
---|
57 | EMPTY <= '1'; |
---|
58 | end if; |
---|
59 | else |
---|
60 | FULL <= '0'; |
---|
61 | EMPTY <= '0'; |
---|
62 | end if; |
---|
63 | -- address, write enable and nopush/nopop logic -- |
---|
64 | if (POP = '0' and PUSH = '0') then -- no operation -- |
---|
65 | ADD <= RPTR; |
---|
66 | WE <= '0'; |
---|
67 | NOPUSH <= '0'; |
---|
68 | NOPOP <= '0'; |
---|
69 | elsif (POP = '0' and PUSH = '1') then -- push only -- |
---|
70 | ADD <= WPTR; |
---|
71 | NOPOP <= '0'; |
---|
72 | if (FULL = '0') then -- valid write condition -- |
---|
73 | WE <= '1'; |
---|
74 | NOPUSH <= '0'; |
---|
75 | else -- no write condition -- |
---|
76 | WE <= '0'; |
---|
77 | NOPUSH <= '1'; |
---|
78 | end if; |
---|
79 | elsif (POP = '1' and PUSH = '0') then -- pop only -- |
---|
80 | ADD <= RPTR; |
---|
81 | NOPUSH <= '0'; |
---|
82 | WE <= '0'; |
---|
83 | if (EMPTY = '0') then -- valid read condition -- |
---|
84 | NOPOP <= '0'; |
---|
85 | else |
---|
86 | NOPOP <= '1'; -- no red condition -- |
---|
87 | end if; |
---|
88 | else -- push and pop at same time - |
---|
89 | if (EMPTY = '0') then -- valid pop -- |
---|
90 | ADD <= RPTR; |
---|
91 | WE <= '0'; |
---|
92 | NOPUSH <= '1'; |
---|
93 | NOPOP <= '0'; |
---|
94 | else |
---|
95 | ADD <= wptr; |
---|
96 | WE <= '1'; |
---|
97 | NOPUSH <= '0'; |
---|
98 | NOPOP <= '1'; |
---|
99 | end if; |
---|
100 | end if; |
---|
101 | end process COMB; |
---|
102 | end architecture RTL; |
---|