source: PROJECT_CORE_MPI/SWITCH_GEN/BRANCHES/OLD_VERSION/FIFO_256_FWFT.vhd @ 24

Last change on this file since 24 was 24, checked in by rolagamo, 12 years ago
File size: 7.3 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
85fifo_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 => doa_signal
95        );
96               
97-- circuiterie des signaux de validation et d'etat du fifo
98wr_en_signal <= wr_en and (not full_signal); -- la donnée est ignorée si le fifo est plein
99rd_en_signal <= rd_en and (not empty_signal);-- pas de lecture si le fifo est vide
100full_signal <= '1' when fifo_counter = "11111111" else
101                                   '0';
102--empty_signal <= '1' when fifo_counter = "000000"  else
103--                                       '0';
104empty_signal <= '1' when rd_ready='0' or unsigned(fifo_counter) = 0  else
105                                         '0';
106clk_signal <= clk;
107full <= full_signal;
108empty <= empty_signal ;
109
110-- sortie du fifo fwft
111dout <= dout_signal;
112
113-- le processus des transistion
114fwft_fsm_nsl : process(clk_signal)
115 begin
116    if rising_edge(clk_signal) then
117           if srst = '1' then
118                   fwft_fsm_state  <= state0;
119                else
120                   case fwft_fsm_state  is
121                                        when state0 => if wr_en_signal = '1' then  --tampon vide seule l'écriture est possible
122                                                                                        fwft_fsm_state  <= state1;
123                                                                                end if;
124                                                                               
125                                                                               
126                                        when state1 => --if rd_en_signal = '1' and wr_en_signal='1'  then  --écriture seule dans le tampon
127                                                                                       
128                                                                                        fwft_fsm_state  <= state2;
129                                                                                --end if;
130                                                                               
131                                        when state2 => if rd_en_signal = '1' and wr_en_signal='1'  then
132                                                                                        fwft_fsm_state  <= state2;
133                                                                                elsif rd_en_signal='1' and wr_en_signal='0' and unsigned(fifo_counter) = 1 then --lecture avec écriture
134                                                                                        fwft_fsm_state  <= state0;
135                                                                                elsif unsigned(fifo_counter) = 0 then
136                                                                                        fwft_fsm_state  <= state0;
137                                                                                end if;
138                                                                               
139                                        when state3 => if rd_en_signal = '1' then  --écriture seule dans le tampon
140                                                                                        fwft_fsm_state  <= state0;
141                                                                                elsif wr_en_signal='1' then
142                                                                                        fwft_fsm_state  <= state2;
143                                                                                end if;
144
145                                        when others => fwft_fsm_state <= state0;
146                                                                               
147                                                                               
148                        end case;
149           end if;
150        end if;
151 end process;
152 -- actions associées à la fsm
153 -- mux qui oriente les sortie doa et dob vers out
154 with fwft_fsm_state select
155    dout_signal <= dob_signal when state0, 
156                        dob_signal when state1, --la sortie est la donnée en entrée
157                        dob_signal when state2, -- la sortie vient de la RAM
158                                                 dob_signal when state3,
159                                                 doa_signal when others;
160 -- counter_en
161 with fwft_fsm_state select
162    counter_en   <= '0' when state0, 
163                         '1' when state1,
164                         '1' when state2,
165                                                  '1' when state3,     
166                                                  '0' when others;
167                                                 
168with fwft_fsm_state select
169    rd_ready   <= '0' when state0, 
170                         '0' when state1,
171                         '1' when state2,
172                                                  '1' when state3,     
173                                                  '0' when others;
174doa_latch_process : process(clk_signal)
175begin
176  if rising_edge(clk_signal) then
177                if wr_en_signal ='1'  then
178                        doa_signal <= din;
179                end if;
180  end if;
181end process;
182                       
183-- processus de comptage des adresses d'empilement
184push_process : process(clk_signal)
185 begin
186 if rising_edge(clk_signal) then
187   if srst = '1' then
188         push_address_counter <= (others =>'0');
189        elsif wr_en_signal ='1'   then
190                        RAM(conv_integer(push_address_counter)) <=din;
191                push_address_counter <= push_address_counter +1;
192         end if;
193 end if;
194end process;
195 
196 -- processus de comptage des adresses depilement du fifo
197pop_process : process(clk_signal)
198 begin
199 if rising_edge(clk_signal) then
200   if srst = '1' then
201          pop_address_counter <= (others =>'0'); --pour avoir un décalage entre la valeur lue et celle qui est écrite
202        elsif rd_en_signal ='1'  then
203                pop_address_counter <= pop_address_counter+1;
204        end if;
205       
206 end if;
207 end process;
208 dob_signal<=RAM(conv_integer(pop_address_counter));
209 -- processus de comptage des octets dans le fifo
210 fifo_counter_process : process(clk_signal)
211variable count : std_logic_vector(word-1 downto 0):= (others=>'0');
212begin
213 if rising_edge(clk_signal) then
214   if srst = '1' then
215         fifo_counter <= (others =>'0');
216         count:=(others =>'0');
217        else
218         if wr_en_signal ='1'  and rd_en_signal ='0' then 
219                --fifo_counter <= fifo_counter +1;
220                count:=count+1;
221          end if;
222         if rd_en_signal ='1' and wr_en_signal ='0' and counter_en='1' then
223                --fifo_counter <= fifo_counter - 1;
224                count:=count-1;         
225         end if;
226         fifo_counter<=count;
227  end if;
228 end if;
229end process;
230
231end Behavioral;
232
Note: See TracBrowser for help on using the repository browser.