source: PROJECT_CORE_MPI/SWITCH_GEN/BRANCHES/v0.03/FIFO_256_FWFT.vhd @ 65

Last change on this file since 65 was 65, checked in by rolagamo, 11 years ago
File size: 7.4 KB
Line 
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:
21-- le signal counter_en a été supprimé
22----------------------------------------------------------------------------------
23library IEEE;
24
25use IEEE.STD_LOGIC_1164.ALL;
26use IEEE.STD_LOGIC_ARITH.ALL;
27use IEEE.STD_LOGIC_UNSIGNED.ALL;
28--Library NocLib;
29--use NocLib.CoreTypes.all;
30use work.CoreTypes.all;
31---- Uncomment the following library declaration if instantiating
32---- any Xilinx primitives in this code.
33--library UNISIM;
34--use UNISIM.VComponents.all;
35
36entity FIFO_256_FWFT is
37    Port ( clk : in  STD_LOGIC;
38           din : in  STD_LOGIC_VECTOR (Word-1 downto 0);
39           rd_en : in  STD_LOGIC;
40           srst : in  STD_LOGIC;
41           wr_en : in  STD_LOGIC;
42           dout : out  STD_LOGIC_VECTOR (Word-1 downto 0);
43           empty : out  STD_LOGIC;
44           full : out  STD_LOGIC);
45end FIFO_256_FWFT;
46
47architecture Behavioral of FIFO_256_FWFT is
48-- declaration de la ram 256 octets
49COMPONENT RAM_256
50        PORT(
51                clka : IN std_logic;
52                clkb : IN std_logic;
53                wea : IN std_logic;
54                ena : IN std_logic;
55                enb : IN std_logic;
56                addra : IN std_logic_vector(Word-1 downto 0);
57                addrb : IN std_logic_vector(Word-1 downto 0);
58                dia : IN std_logic_vector(Word-1 downto 0);         
59                dob : OUT std_logic_vector(Word-1 downto 0)
60                );
61END COMPONENT;
62type fsm_states is (state0, state1, state2, state3);-- definition du type etat pour le codage des etats des fsm
63signal fwft_fsm_state : fsm_states;
64type ram_type is array (255 downto 0) of std_logic_vector (Word-1 downto 0);
65        signal RAM: ram_type;
66-- declaration des signeaux des compteurs
67signal push_address_counter: std_logic_vector(Word-1 downto 0);
68signal pop_address_counter : std_logic_vector(Word-1 downto 0);
69signal fifo_counter : std_logic_vector(Word-1 downto 0);
70--autre signaux
71signal empty_signal: std_logic:='1';
72signal rd_ready : std_logic:='0';
73signal full_signal  : std_logic;
74signal wr_en_signal : std_logic;--_vector(0 downto 0);
75signal rd_en_signal : std_logic;
76signal clk_signal :  std_logic;
77signal dob_signal : std_logic_vector(Word-1 downto 0);
78signal dout_signal : std_logic_vector(Word-1 downto 0);
79signal doa_signal : std_logic_vector(Word-1 downto 0);
80signal counter_en : std_logic; 
81
82begin
83
84-- ram instantiation de la bloc ram 256 octets du FIFO
85--fifo_RAM_256: RAM_256 PORT MAP(
86--              clka => clk_signal,
87--              clkb => clk_signal,
88--              wea => wr_en_signal,
89--              ena => '1',
90--              enb => '1',
91--              addra => push_address_counter,
92--              addrb => pop_address_counter,
93--              dia => din,
94--              dob => dob_signal
95--              --dob => doa_signal
96--      );
97               
98-- circuiterie des signaux de validation et d'etat du fifo
99wr_en_signal <= wr_en and (not full_signal); -- la donnée est ignorée si le fifo est plein
100rd_en_signal <= rd_en and (not empty_signal);-- pas de lecture si le fifo est vide
101full_signal <= '1' when fifo_counter = "11111111" else
102                                   '0';
103--empty_signal <= '1' when fifo_counter = "000000"  else
104--                                       '0';
105empty_signal <= '1' when (rd_ready='0') else -- or (All_zeros(fifo_counter) = '0')  else
106                                         '0';
107clk_signal <= clk;
108full <= full_signal;
109empty <= empty_signal ;
110
111-- sortie du fifo fwft
112dout <= dout_signal;
113
114-- le processus des transistion
115fwft_fsm_nsl : process(clk_signal)
116 begin
117    if rising_edge(clk_signal) then
118           if srst = '1' then
119                   fwft_fsm_state  <= state0;
120                else
121                   case fwft_fsm_state  is
122                                        when state0 => if wr_en_signal = '1' then  --tampon vide seule l'écriture est possible
123                                                                                        fwft_fsm_state  <= state1;
124                                                                                end if;
125                                                                               
126                                                                               
127                                        when state1 => --if rd_en_signal = '1' and wr_en_signal='1'  then  --écriture seule dans le tampon
128                                                                                       
129                                                                                        fwft_fsm_state  <= state2;
130                                                                                --end if;
131                                                                               
132                                        when state2 => if rd_en_signal = '1' and wr_en_signal='1'  then
133                                                                                        fwft_fsm_state  <= state2;
134                                                                                elsif rd_en_signal='1' and wr_en_signal='0' and unsigned(fifo_counter) = 1 then --lecture avec écriture
135                                                                                        fwft_fsm_state  <= state0;
136                                                                                elsif unsigned(fifo_counter) = 0 then
137                                                                                        fwft_fsm_state  <= state0;
138                                                                                end if;
139                                                                               
140                                        when state3 => if rd_en_signal = '1' then  --écriture seule dans le tampon
141                                                                                        fwft_fsm_state  <= state0;
142                                                                                elsif wr_en_signal='1' then
143                                                                                        fwft_fsm_state  <= state2;
144                                                                                end if;
145
146--                                      when others => fwft_fsm_state <= state0;
147                                                                               
148                                                                               
149                        end case;
150           end if;
151        end if;
152 end process;
153 -- actions associées à la fsm
154 -- mux qui oriente les sortie doa et dob vers out
155 with fwft_fsm_state select
156    dout_signal <= dob_signal when state0, 
157                        dob_signal when state1, --la sortie est la donnée en entrée
158                        dob_signal when state2, -- la sortie vient de la RAM
159                                                 dob_signal when state3,
160                                                 doa_signal when others;
161 -- counter_en
162 with fwft_fsm_state select
163    counter_en   <= '0' when state0, 
164                         '1' when state1,
165                         '1' when state2,
166                                                  '1' when state3,     
167                                                  '0' when others;
168                                                 
169with fwft_fsm_state select
170    rd_ready   <= '0' when state0, 
171                         '0' when state1,
172                         '1' when state2,
173                                                  '1' when state3,     
174                                                  '0' when others;
175doa_latch_process : process(clk_signal)
176begin
177  if rising_edge(clk_signal) then
178                if wr_en_signal ='1'  then
179                        doa_signal <= din;
180                end if;
181  end if;
182end process;
183                       
184-- processus de comptage des adresses d'empilement
185push_process : process(clk_signal)
186 begin
187 if rising_edge(clk_signal) then
188   if srst = '1' then
189         push_address_counter <= (others =>'0');
190        elsif wr_en_signal ='1'   then
191                        RAM(conv_integer(push_address_counter)) <=din;
192                push_address_counter <= push_address_counter +1;
193         end if;
194 end if;
195end process;
196 
197 -- processus de comptage des adresses depilement du fifo
198pop_process : process(clk_signal)
199 begin
200 if rising_edge(clk_signal) then
201   if srst = '1' then
202          pop_address_counter <= (others =>'0'); --pour avoir un décalage entre la valeur lue et celle qui est écrite
203        elsif rd_en_signal ='1'  then
204                pop_address_counter <= pop_address_counter+1;
205        end if;
206       
207 end if;
208 end process;
209 dob_signal<=RAM(conv_integer(pop_address_counter));
210 -- processus de comptage des octets dans le fifo
211 fifo_counter_process : process(clk_signal)
212variable count : std_logic_vector(word-1 downto 0):= (others=>'0');
213begin
214 if rising_edge(clk_signal) then
215   if srst = '1' then
216         fifo_counter <= (others =>'0');
217         count:=(others =>'0');
218        else
219         if wr_en_signal ='1'  and rd_en_signal ='0' then 
220                --fifo_counter <= fifo_counter +1;
221                count:=count+1;
222          end if;
223         if rd_en_signal ='1' and wr_en_signal ='0' and counter_en='1' then
224                --fifo_counter <= fifo_counter - 1;
225                count:=count-1;         
226         end if;
227         fifo_counter<=count;
228  end if;
229 end if;
230end process;
231
232end Behavioral;
233
Note: See TracBrowser for help on using the repository browser.