[15] | 1 | ---------------------------------------------------------------------------------- |
---|
| 2 | -- Company: |
---|
| 3 | -- Engineer: KIEGAING EMMANUEL/GAMOM |
---|
| 4 | -- |
---|
| 5 | -- Create Date: 19:51:54 04/19/2011 |
---|
| 6 | -- Design Name: |
---|
| 7 | -- Module Name: FIFO_64 - Behavioral |
---|
| 8 | -- Project Name: |
---|
| 9 | -- Target Devices: |
---|
| 10 | -- Tool versions: |
---|
| 11 | -- Description: |
---|
| 12 | --FIFO 64 Octets utisé pour les modules d'entrée |
---|
| 13 | -- ce fifo est de type fwft first word falls throught ce qui |
---|
| 14 | -- signifie que l'on a toujours la donnée au sommet de la pile en |
---|
| 15 | -- sortie du fifo. |
---|
| 16 | -- Dependencies: RAM_64.vhd |
---|
| 17 | -- |
---|
| 18 | -- Revision: 30-07-2012 |
---|
| 19 | -- Revision 0.01 - File Created |
---|
| 20 | -- Additional Comments: suppression du signal counter_en dans les expressions |
---|
| 21 | -- |
---|
| 22 | ---------------------------------------------------------------------------------- |
---|
| 23 | library IEEE; |
---|
| 24 | use IEEE.STD_LOGIC_1164.ALL; |
---|
| 25 | use IEEE.STD_LOGIC_ARITH.ALL; |
---|
| 26 | use IEEE.STD_LOGIC_UNSIGNED.ALL; |
---|
| 27 | Library NocLib; |
---|
| 28 | use NocLib.CoreTypes.all; |
---|
| 29 | ---- Uncomment the following library declaration if instantiating |
---|
| 30 | ---- any Xilinx primitives in this code. |
---|
| 31 | --library UNISIM; |
---|
| 32 | --use UNISIM.VComponents.all; |
---|
| 33 | |
---|
| 34 | entity FIFO_64_FWFT is |
---|
| 35 | Port ( clk : in STD_LOGIC; |
---|
| 36 | din : in STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
| 37 | rd_en : in STD_LOGIC; |
---|
| 38 | srst : in STD_LOGIC; |
---|
| 39 | wr_en : in STD_LOGIC; |
---|
| 40 | dout : out STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
| 41 | empty : out STD_LOGIC; |
---|
| 42 | full : out STD_LOGIC); |
---|
| 43 | end FIFO_64_FWFT; |
---|
| 44 | |
---|
| 45 | architecture Behavioral of FIFO_64_FWFT is |
---|
| 46 | -- declaration de la ram 64 octets |
---|
| 47 | COMPONENT RAM_64 |
---|
| 48 | PORT( |
---|
| 49 | clka : IN std_logic; |
---|
| 50 | clkb : IN std_logic; |
---|
| 51 | wea : IN std_logic; |
---|
| 52 | ena : IN std_logic; |
---|
| 53 | enb : IN std_logic; |
---|
| 54 | addra : IN std_logic_vector(5 downto 0); |
---|
| 55 | addrb : IN std_logic_vector(5 downto 0); |
---|
| 56 | dia : IN std_logic_vector(Word-1 downto 0); |
---|
| 57 | --doa : OUT std_logic_vector(Word-1 downto 0); |
---|
| 58 | dob : OUT std_logic_vector(Word-1 downto 0) |
---|
| 59 | ); |
---|
| 60 | END COMPONENT; |
---|
| 61 | type fsm_states is (state0, state1, state2);-- definition du type etat pour le codage des etats des fsm |
---|
| 62 | signal fwft_fsm_state : fsm_states; |
---|
| 63 | -- declaration des signeaux des compteurs |
---|
| 64 | signal push_address_counter : std_logic_vector(5 downto 0); |
---|
| 65 | signal pop_address_counter : std_logic_vector(5 downto 0); |
---|
| 66 | signal fifo_counter : std_logic_vector(5 downto 0); |
---|
| 67 | --autre signaux |
---|
| 68 | signal rd_ready : std_logic:='0'; |
---|
| 69 | signal empty_signal : std_logic; |
---|
| 70 | signal full_signal : std_logic; |
---|
| 71 | signal wr_en_signal : std_logic; |
---|
| 72 | signal rd_en_signal : std_logic; |
---|
| 73 | signal clk_signal : std_logic; |
---|
| 74 | signal dob_signal : std_logic_vector(Word-1 downto 0); |
---|
| 75 | signal dout_signal : std_logic_vector(Word-1 downto 0); |
---|
| 76 | signal doa_signal : std_logic_vector(Word-1 downto 0); |
---|
| 77 | signal counter_en : std_logic; |
---|
| 78 | |
---|
| 79 | begin |
---|
| 80 | |
---|
| 81 | -- ram instantiation de la ram 64 octets du FIFO |
---|
| 82 | fifo_RAM_64: RAM_64 PORT MAP( |
---|
| 83 | clka => clk_signal, |
---|
| 84 | clkb => clk_signal, |
---|
| 85 | wea => wr_en_signal, |
---|
| 86 | ena => wr_en_signal, |
---|
| 87 | enb => rd_en_signal, |
---|
| 88 | addra => push_address_counter, |
---|
| 89 | addrb => pop_address_counter, |
---|
| 90 | dia => din, |
---|
| 91 | --doa => doa_signal, |
---|
| 92 | dob => dob_signal |
---|
| 93 | ); |
---|
| 94 | -- circuiterie des signaux de validation et d'etat du fifo |
---|
| 95 | wr_en_signal <= wr_en and (not full_signal); -- la donnée est ignorée si le fifo est plein |
---|
| 96 | rd_en_signal <= rd_en and (not empty_signal);-- pas de lecture si le fifo est vide |
---|
| 97 | full_signal <= '1' when fifo_counter = "111111" else |
---|
| 98 | '0'; |
---|
| 99 | empty_signal <= '1' when rd_ready='0' and unsigned(fifo_counter) = 0 else |
---|
| 100 | '0'; |
---|
| 101 | clk_signal <= clk; |
---|
| 102 | full <= full_signal; |
---|
| 103 | empty <= empty_signal; |
---|
| 104 | |
---|
| 105 | -- sortie du fifo fwft |
---|
| 106 | dout <= dout_signal; |
---|
| 107 | |
---|
| 108 | -- le processus des transistion |
---|
| 109 | fwft_fsm_nsl : process(clk) |
---|
| 110 | begin |
---|
| 111 | if rising_edge(clk) then |
---|
| 112 | if srst = '1' then |
---|
| 113 | fwft_fsm_state <= state0; |
---|
| 114 | else |
---|
| 115 | case fwft_fsm_state is |
---|
| 116 | when state0 => if wr_en_signal = '1' then --tampon vide seule l'écriture est possible |
---|
| 117 | fwft_fsm_state <= state1; |
---|
| 118 | end if; |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | when state1 => --if rd_en_signal = '1' and wr_en_signal='1' then --écriture seule dans le tampon |
---|
| 122 | |
---|
| 123 | fwft_fsm_state <= state2; |
---|
| 124 | --end if; |
---|
| 125 | |
---|
| 126 | when state2 => if rd_en_signal = '1' and wr_en_signal='1' then |
---|
| 127 | fwft_fsm_state <= state2; |
---|
| 128 | elsif rd_en_signal='1' and wr_en_signal='0' and fifo_counter = "000001" then --lecture avec écriture |
---|
| 129 | fwft_fsm_state <= state0; |
---|
| 130 | elsif unsigned(fifo_counter) = 0 then |
---|
| 131 | fwft_fsm_state <= state0; |
---|
| 132 | end if; |
---|
| 133 | |
---|
| 134 | when others => fwft_fsm_state <= state0; |
---|
| 135 | end case; |
---|
| 136 | end if; |
---|
| 137 | end if; |
---|
| 138 | end process; |
---|
| 139 | -- actions associées à la fsm |
---|
| 140 | -- mux qui oriente les sortie doa et dob vers out |
---|
| 141 | with fwft_fsm_state select |
---|
| 142 | dout_signal <= dob_signal when state0, |
---|
| 143 | doa_signal when state1, |
---|
| 144 | dob_signal when state2, |
---|
| 145 | doa_signal when others; |
---|
| 146 | -- counter_en |
---|
| 147 | with fwft_fsm_state select |
---|
| 148 | counter_en <= '0' when state0, |
---|
| 149 | '1' when state1, |
---|
| 150 | '1' when state2, |
---|
| 151 | '0' when others; |
---|
| 152 | |
---|
| 153 | with fwft_fsm_state select |
---|
| 154 | rd_ready <= '0' when state0, |
---|
| 155 | '0' when state1, |
---|
| 156 | '1' when state2, |
---|
| 157 | '0' when others; |
---|
| 158 | doa_latch_process : process(clk) |
---|
| 159 | begin |
---|
| 160 | if rising_edge(clk) then |
---|
| 161 | if wr_en_signal ='1' then |
---|
| 162 | doa_signal <= din; |
---|
| 163 | end if; |
---|
| 164 | end if; |
---|
| 165 | end process; |
---|
| 166 | |
---|
| 167 | -- processus de comptage des adresses d'empilement |
---|
| 168 | push_process : process(clk) |
---|
| 169 | begin |
---|
| 170 | if rising_edge(clk) then |
---|
| 171 | if srst = '1' then |
---|
| 172 | push_address_counter <= (others =>'0'); |
---|
| 173 | elsif wr_en_signal ='1' then |
---|
| 174 | push_address_counter <= push_address_counter +1; |
---|
| 175 | end if; |
---|
| 176 | end if; |
---|
| 177 | end process; |
---|
| 178 | |
---|
| 179 | -- processus de comptage des adresses depilement du fifo |
---|
| 180 | pop_process : process(clk) |
---|
| 181 | begin |
---|
| 182 | if rising_edge(clk) then |
---|
| 183 | if srst = '1' then |
---|
| 184 | pop_address_counter <= (others =>'0'); |
---|
| 185 | elsif rd_en_signal ='1' then |
---|
| 186 | pop_address_counter <= pop_address_counter +1; |
---|
| 187 | end if; |
---|
| 188 | end if; |
---|
| 189 | end process; |
---|
| 190 | |
---|
| 191 | -- processus de comptage des octets dans le fifo |
---|
| 192 | fifo_counter_process : process(clk) |
---|
| 193 | variable count : std_logic_vector(word-1 downto 0):= (others=>'0'); |
---|
| 194 | begin |
---|
| 195 | if rising_edge(clk) then |
---|
| 196 | if srst = '1' then |
---|
| 197 | fifo_counter <= (others =>'0'); |
---|
| 198 | count:=(others =>'0'); |
---|
| 199 | else |
---|
| 200 | if wr_en_signal ='1' and rd_en_signal ='0' then |
---|
| 201 | count:=count+1; |
---|
| 202 | end if; |
---|
| 203 | if rd_en_signal ='1' and wr_en_signal ='0' and counter_en='1' then |
---|
| 204 | count:=count-1; |
---|
| 205 | end if; |
---|
| 206 | fifo_counter<=count; |
---|
| 207 | end if; |
---|
| 208 | end if; |
---|
| 209 | end process; |
---|
| 210 | |
---|
| 211 | end Behavioral; |
---|
| 212 | |
---|