1 | |
---|
2 | ---------------------------------------------------------------------------------- |
---|
3 | -- Company: |
---|
4 | -- Engineer: |
---|
5 | -- |
---|
6 | -- Create Date: 09:29:48 04/18/2011 |
---|
7 | -- Design Name: |
---|
8 | -- Module Name: OUTPUT_PORT_MODULE - Behavioral_description |
---|
9 | -- Project Name: |
---|
10 | -- Target Devices: |
---|
11 | -- Tool versions: |
---|
12 | -- Description: |
---|
13 | -- cette version du module de sortie se limite à une instance du fifo ordinaire |
---|
14 | -- les données son emise en sortie à chaque cycle d'horloge |
---|
15 | -- Dependencies: |
---|
16 | -- |
---|
17 | -- Revision: 07-08-2013 |
---|
18 | -- Revision 0.01 - File Created |
---|
19 | -- Additional Comments: Ajout d'un délai pour ignorer les paquets qui sont là depuis |
---|
20 | -- longtemps |
---|
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 | USE ieee.numeric_std.ALL; |
---|
28 | Library NocLib; |
---|
29 | use NocLib.CoreTypes.all; |
---|
30 | ---- Uncomment the following library declaration if instantiating |
---|
31 | ---- any Xilinx primitives in this code. |
---|
32 | --library UNISIM; |
---|
33 | --use UNISIM.VComponents.all; |
---|
34 | |
---|
35 | entity OUTPUT_PORT_MODULE is |
---|
36 | Port ( data_in : in STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
37 | reset : in STD_LOGIC; |
---|
38 | clk : in STD_LOGIC; |
---|
39 | wr_en : in STD_LOGIC; |
---|
40 | data_out : out STD_LOGIC_VECTOR (Word-1 downto 0); |
---|
41 | fifo_full : out std_logic; |
---|
42 | data_avalaible : out std_logic; |
---|
43 | rd_out_en : in STD_LOGIC); |
---|
44 | end OUTPUT_PORT_MODULE; |
---|
45 | |
---|
46 | architecture Behavioral_description of OUTPUT_PORT_MODULE is |
---|
47 | -- declaration du FIFO 64 octets |
---|
48 | component FIFO_256_FWFT |
---|
49 | port ( |
---|
50 | clk: IN std_logic; |
---|
51 | din: IN std_logic_VECTOR(Word-1 downto 0); |
---|
52 | rd_en: IN std_logic; |
---|
53 | srst: IN std_logic; |
---|
54 | wr_en: IN std_logic; |
---|
55 | dout: out std_logic_VECTOR(Word-1 downto 0); |
---|
56 | empty: OUT std_logic; |
---|
57 | full: OUT std_logic); |
---|
58 | end component; |
---|
59 | --definition du type etat pour les fsm |
---|
60 | type typ_outfsm is (Idle,waiting,dropping,reading); |
---|
61 | type typ_receiv is (r_wait,r_head,r_len,r_glen,r_data,r_pulse,r_end); |
---|
62 | |
---|
63 | signal EtRec : typ_receiv; |
---|
64 | signal Et_out_fsm : typ_outfsm; |
---|
65 | signal fifo_empty : std_logic; |
---|
66 | signal sw : std_logic:='0'; -- permet de positionner le mux sur les signaux internes |
---|
67 | signal tlimit : natural:=0; --permet de compter les impulsions de temps |
---|
68 | signal n : natural:=0; --utiliser pour la mae du tampon de sortie |
---|
69 | signal rcv_start : std_logic; --début de la réception |
---|
70 | signal rcv_ack : std_logic; -- acquittement de la réception |
---|
71 | signal rcv_comp : std_logic; -- fin de la réception |
---|
72 | signal spop,pop,rd_en,dat_avail : std_logic:='0'; |
---|
73 | signal mem,fifo_out : std_logic_vector(Word-1 downto 0); --variable tampon sans intérêt réel |
---|
74 | begin |
---|
75 | -- instantiation du FIFO_64 |
---|
76 | OUTPUT_PORT_FIFO : FIFO_256_FWFT |
---|
77 | port map ( |
---|
78 | clk => clk, |
---|
79 | din => data_in, |
---|
80 | rd_en => rd_en, |
---|
81 | srst => reset, |
---|
82 | wr_en => wr_en, |
---|
83 | dout => fifo_out, |
---|
84 | empty => fifo_empty, |
---|
85 | full => fifo_full); |
---|
86 | |
---|
87 | |
---|
88 | outport_proc : process(clk,reset,fifo_empty) |
---|
89 | begin |
---|
90 | if rising_edge(clk) then |
---|
91 | if reset='1' then |
---|
92 | n<=0; |
---|
93 | Et_out_fsm<=Idle; |
---|
94 | else |
---|
95 | case(Et_out_fsm) is |
---|
96 | |
---|
97 | when Idle => --idle |
---|
98 | if fifo_empty = '0' then |
---|
99 | Et_Out_fsm<=waiting; |
---|
100 | end if; |
---|
101 | tlimit<=0; |
---|
102 | sw<='0'; |
---|
103 | when reading => |
---|
104 | if rd_out_en='0' then |
---|
105 | Et_out_fsm<=Idle; |
---|
106 | end if; |
---|
107 | sw<='0'; |
---|
108 | when waiting => --counting |
---|
109 | if rd_out_en='1' then |
---|
110 | Et_out_fsm<=reading; |
---|
111 | elsif tlimit=5000 then |
---|
112 | Et_out_fsm<=dropping; |
---|
113 | tlimit<=0; |
---|
114 | else |
---|
115 | tlimit<=tlimit+1; |
---|
116 | end if; |
---|
117 | sw<='0'; |
---|
118 | when dropping => --dropping packet |
---|
119 | if n=0 then |
---|
120 | rcv_start<='1'; |
---|
121 | n<=1; |
---|
122 | sw<='1'; |
---|
123 | elsif n=1 then |
---|
124 | if rcv_comp='1' then |
---|
125 | rcv_ack<='1'; |
---|
126 | rcv_start<='0'; |
---|
127 | n<=2; |
---|
128 | end if; |
---|
129 | sw<='1'; |
---|
130 | elsif n=2 then |
---|
131 | sw<='0'; |
---|
132 | Et_out_fsm<=Idle; |
---|
133 | report "Attention Paquet perdu !à Output_Port_Module"; |
---|
134 | n<=0; |
---|
135 | end if; |
---|
136 | |
---|
137 | end case; |
---|
138 | end if; |
---|
139 | end if; |
---|
140 | end process outport_proc; |
---|
141 | data_out<=fifo_out; |
---|
142 | mux_proc : process (sw,rd_out_en,pop,fifo_empty) |
---|
143 | begin |
---|
144 | if sw='1' then --mode drop |
---|
145 | rd_en<=pop; |
---|
146 | data_avalaible <='0'; --plus de données dans le tampon ! |
---|
147 | else |
---|
148 | rd_en<=rd_out_en; |
---|
149 | data_avalaible <= not fifo_empty; |
---|
150 | end if; |
---|
151 | end process mux_proc; |
---|
152 | proc_receiv : process (clk,reset) |
---|
153 | variable dlen,i: natural range 0 to 255 :=0; |
---|
154 | |
---|
155 | begin |
---|
156 | if reset='1' then |
---|
157 | etrec<=r_wait; |
---|
158 | |
---|
159 | else |
---|
160 | if rising_edge(clk) then -- le process s'exécute sur chaque front |
---|
161 | -- montant de l'horloge |
---|
162 | case etrec is |
---|
163 | when r_wait => |
---|
164 | |
---|
165 | i:=0; |
---|
166 | if fifo_empty='0' and rcv_start='1' then |
---|
167 | |
---|
168 | etrec<=r_head; |
---|
169 | mem<=fifo_out; |
---|
170 | |
---|
171 | end if; |
---|
172 | when r_head => |
---|
173 | mem<=fifo_out; --l'en-tête |
---|
174 | |
---|
175 | etrec<=r_len; |
---|
176 | when r_len => |
---|
177 | dlen:=to_integer(unsigned(fifo_out)); |
---|
178 | mem<=fifo_out; -- la longueur |
---|
179 | |
---|
180 | if dlen>2 then |
---|
181 | etrec<=r_data; |
---|
182 | else |
---|
183 | etrec<=r_end; |
---|
184 | end if; |
---|
185 | i:=1; |
---|
186 | |
---|
187 | when r_data => |
---|
188 | if fifo_empty='0' then |
---|
189 | if i<dlen-2 then |
---|
190 | i:=i+1; |
---|
191 | mem<=fifo_out; |
---|
192 | |
---|
193 | |
---|
194 | else |
---|
195 | etrec<=r_pulse; |
---|
196 | |
---|
197 | mem<=fifo_out; |
---|
198 | end if; |
---|
199 | -- time out à prévoir ici |
---|
200 | end if; |
---|
201 | when r_pulse => |
---|
202 | etrec<=r_end; |
---|
203 | |
---|
204 | when r_end => |
---|
205 | if rcv_ack='1' then |
---|
206 | etrec<=r_wait; |
---|
207 | end if; |
---|
208 | |
---|
209 | when others => |
---|
210 | |
---|
211 | |
---|
212 | etrec<=r_wait; |
---|
213 | end case; |
---|
214 | end if; |
---|
215 | end if; |
---|
216 | end process; |
---|
217 | |
---|
218 | pop<=spop; |
---|
219 | |
---|
220 | rec_value : process (etrec) |
---|
221 | begin |
---|
222 | case etrec is |
---|
223 | when r_wait => |
---|
224 | spop<='0'; |
---|
225 | rcv_comp<='0'; |
---|
226 | when r_head => |
---|
227 | |
---|
228 | spop<='1'; |
---|
229 | rcv_comp<='0'; |
---|
230 | |
---|
231 | when r_len => |
---|
232 | spop<='1'; |
---|
233 | when r_data => |
---|
234 | spop<='1'; |
---|
235 | when r_pulse => |
---|
236 | spop<='0'; |
---|
237 | rcv_comp<='1'; |
---|
238 | when r_end => |
---|
239 | spop<='0'; |
---|
240 | rcv_comp<='1'; |
---|
241 | when others => |
---|
242 | spop<='0'; |
---|
243 | rcv_comp<='0'; |
---|
244 | end case; |
---|
245 | end process; |
---|
246 | |
---|
247 | end Behavioral_description; |
---|
248 | |
---|