source: PROJECT_CORE_MPI/SWITCH_GEN/BRANCHES/v0.03/INPUT_PORT_MODULE.vhd @ 71

Last change on this file since 71 was 71, checked in by rolagamo, 11 years ago
File size: 29.8 KB
Line 
1----------------------------------------------------------------------------------
2-- Company:
3-- Engineer: KIEGAING EMMANUEL/GAMOM Roland CHristian
4--
5-- Create Date:    03:47:50 04/24/2011
6-- Design Name:
7-- Module Name:    INPUT_PORT_MODULE - Behavioral
8-- Project Name:
9-- Target Devices:
10-- Tool versions:
11-- Description:
12-- Module de gestion des entrées des ports du switch crossbar
13-- il supose qu'une donnée est empilée à chaque cycle d'horloge
14-- Dependencies:
15-- FIFO_64_FWFT.vhd
16-- RAM_64.vhd
17-- Revision: 1
18-- remplacement du fifo ordinaire par un fifo fwft
19-- Revision 1.01 - File Created
20-- Additional Comments:
21-- modifié le 14/05/20011  pour eviter une écriture multiple dans le FIFO de sortie
22-- si le FIFO d'entrée vient a se vider pendant le transfert d'un packet
23-- le machine a état on été re modeliser et sont maintenant du type FSMD
24-- remodéliation pour plus de vitesse
25--inclusion du signal priority rotation pour eviter la perte du grant pendant une transmission
26--02-08-2012 :Prise en compte du signal Port_Granted dans un process
27----------------------------------------------------------------------------------
28library IEEE;
29use IEEE.STD_LOGIC_1164.ALL;
30--use IEEE.STD_LOGIC_ARITH.ALL;
31use IEEE.STD_LOGIC_UNSIGNED.ALL;
32USE ieee.numeric_std.ALL;
33use work.Coretypes.all;
34---- Uncomment the following library declaration if instantiating
35---- any Xilinx primitives in this code.
36--library UNISIM;
37--use UNISIM.VComponents.all;
38
39
40entity INPUT_PORT_MODULE is
41    generic(number_of_ports : positive := 4;
42         
43         Port_num: natural:=1);  -- port_num est l'id du port
44    Port ( data_in : in  STD_LOGIC_VECTOR (Word-1 downto 0);
45           data_in_en : in  STD_LOGIC; -- signaler la présence des données en entrée
46                          cmd_in_en :in STD_LOGIC;    --permet d'identifier les données qui sont dans le tampon
47           reset : in  STD_LOGIC;
48                          clk   : in  STD_LOGIC;
49                          request : out  STD_LOGIC_VECTOR (number_of_ports downto 1); --demande de canal de transmission
50           grant : in  STD_LOGIC_VECTOR (number_of_ports  downto 1);     -- autorisation de transmission                 
51           fifo_full : out  STD_LOGIC; -- signaler que les données ne peuvent plus être acceptées en entrée
52                          fifo_empty : out  STD_LOGIC; -- le tampon d'entrée est vide
53                          priority_rotation : out std_logic;  -- reserver le canal de transmission
54           data_out : out  STD_LOGIC_VECTOR (Word-1 downto 0); --données vers le réseau crossbar
55                          data_out_pulse : out std_logic); -- permet de ...
56       
57end INPUT_PORT_MODULE;
58
59architecture Behavioral of INPUT_PORT_MODULE is
60
61-- declaration du fifo 64 octet utilisé pour chaque port
62component FIFO_256_FWFT
63        port (
64        clk: IN std_logic;
65        din: IN std_logic_VECTOR(Word-1 downto 0);
66        rd_en: IN std_logic;
67        srst: IN std_logic;
68        wr_en: IN std_logic;
69        dout: OUT std_logic_VECTOR(Word-1 downto 0);
70        empty: OUT std_logic;
71        full: OUT std_logic);
72end component;
73
74--definition du type etat pour les fsm
75type fsm_states is (state0, CmdOn, WaitGrant, ReqPort, state1, state2,stpulse,stateErr, state3);-- definition du type etat pour le codage des etats des fsm
76type fsm_states2 is(cmdstart,cmdwait,cmdread,cmdSetDest,cmdSetCount,cmdSetId,cmdpulse,CmdEnd);
77signal pop_state : fsm_states;
78signal cmdstate : fsm_states2;
79signal cmd_exec : std_logic:='0';  --indique que le port est en train d'exécuter une commande
80signal dat_exec :std_logic:='0'; -- indique le port est en train de transférer des données
81signal dat_Err :std_logic:='0'; -- signal une erreur pendant l'exécution
82signal readOk,CmdReadOk : std_logic:='0'; --indique s'il est possible de lire les données
83-- signaux utilisés dans les fsm
84signal request_decoder,req_grant : STD_LOGIC_VECTOR(number_of_ports  downto 1);
85signal request_decoder_en : std_logic;
86signal request_latch : STD_LOGIC_VECTOR(4 downto 1):=(others=>'0');   -- pourquoi pas 3 downto 0 ?
87signal request_latch_en : std_logic;
88signal pipeline_latch : std_logic_vector(Word-1 downto 0);
89signal pipeline_latch_en : std_logic;
90signal request_word :  std_logic_vector(5 downto 1);
91signal port_granted : std_logic;
92signal rd_en_signal : std_logic;
93--signaux utilisés dans la MAE de gestion des commandes
94signal cmd_request_latch_en :std_logic;
95signal cmd_pipeline_latch_en :std_logic;
96signal cmd_fifo_read_signal :std_logic;
97signal cmd_request_decoder_en :std_logic;
98signal cmd_data_out_pulse :std_logic;
99signal cmd_priority_rotation :std_logic;
100--signaux utilisés dans la MAE de transfert des données
101signal dat_request_latch_en :std_logic;
102signal dat_pipeline_latch_en :std_logic;
103signal dat_fifo_read_signal :std_logic;
104signal dat_request_decoder_en :std_logic;
105signal dat_data_out_pulse :std_logic;
106signal dat_priority_rotation :std_logic;
107-- signaux utilisés pour les connections entre composants
108signal clk_signal : std_logic;
109signal reset_signal : std_logic;
110signal fifo_empty_signal : std_logic;
111signal fifo_read_signal : std_logic;
112signal fifo_out_signal,cmd_data_signal : std_logic_vector(Word-1 downto 0);
113signal push_dout : std_logic_vector(Word-1 downto 0);
114signal empty_latch : std_logic ;
115signal PORT_ID :std_logic_vector(Word-1 downto 0):=STD_LOGIC_VECTOR(to_unsigned(number_of_ports-1,4))& STD_LOGIC_VECTOR(to_unsigned(port_num-1,4));
116-- signaux du compteur de données
117signal data_counter : std_logic_vector(Word-1 downto 0);
118
119begin
120-- instantiation du FIFO_256
121 INPUT_PORT_FIFO : FIFO_256_FWFT
122                port map (
123                        clk => clk_signal,
124                        din => data_in,
125                        rd_en => fifo_read_signal,
126                        srst => reset_signal,
127                        wr_en => data_in_en,
128                        dout => fifo_out_signal,
129                        empty => fifo_empty_signal,
130                        full => fifo_full);
131-- connections avec les ports de l'entité
132
133data_out <= pipeline_latch ;--when cmd_exec='0' else cmd_data_signal;
134fifo_empty <= empty_latch;
135reset_signal <= reset;
136grant_proc:process(clk)
137begin
138if rising_edge(clk) then
139--      if unsigned(grant)> 0 then
140        if unsigned(req_grant) > 0 then
141                port_granted <= '1';            --il faut veiller à ce que ce port soit vraiment autorisé
142        else 
143                Port_granted<='0';                      --ceci présuppose que la valeur qu'il reçoit est forcément la sienne
144        end if;
145end if;         
146end process;                     
147rd_en_signal <= not(empty_latch) ;
148request <= request_decoder;
149reg_grant:process (request_decoder,grant)
150begin
151req_grant<=request_decoder and grant;
152end process reg_grant;
153request_word <=  request_latch & request_decoder_en;
154clk_signal <= clk;
155
156
157
158WITH cmd_exec SELECT
159    request_latch_en <=  dat_request_latch_en   WHEN '0',
160                                                                  cmd_request_latch_en  WHEN others;
161                                                                 
162WITH cmd_exec SELECT
163                pipeline_latch_en  <=  dat_pipeline_latch_en   WHEN '0',
164                                                                    cmd_pipeline_latch_en  WHEN others;
165                                                                     
166WITH cmd_exec SELECT   
167                fifo_read_signal <=dat_fifo_read_signal WHEN '0', 
168               
169                                                                cmd_fifo_read_signal WHEN others;
170WITH cmd_exec SELECT
171                request_decoder_en <=dat_request_decoder_en WHEN '0',
172                                                                        cmd_request_decoder_en WHEN others; 
173WITH cmd_exec SELECT
174                data_out_pulse <=dat_data_out_pulse WHEN '0',
175                                                          cmd_data_out_pulse WHEN others;
176WITH cmd_exec SELECT
177                priority_rotation<=dat_priority_rotation WHEN '0',
178                                                                 cmd_priority_rotation WHEN others;
179
180
181--processus permettant de latcher le signal empty
182-- evite une perte de données en cas d'arret au cours d'une transmission
183empty_latch_process : process(clk)
184begin
185 if rising_edge(clk) then
186        if reset_signal = '1' then
187            empty_latch <= '1';
188        else
189         empty_latch <= fifo_empty_signal;
190   end if;
191 end if;       
192
193end process;
194-- decodeur de requete en fonction de l'adresse destination
195-- le circuit genere depend du parametre generique nombre de ports
196-- switch 2 ports
197switch2x2 : if number_of_ports = 2 generate
198
199with request_word select
200      request_decoder <="01" when "00001",
201                        "10" when "00011",
202                        "00" when others;
203
204end generate switch2x2;
205
206
207-- switch 3 ports
208switch3x3 : if number_of_ports = 3 generate
209
210with request_word select
211      request_decoder <="001" when "00001",
212                        "010" when "00011",
213                        "100" when "00101",
214                        "000" when others;
215
216end generate switch3x3;
217
218
219-- switch 4 ports
220switch4x4 : if number_of_ports = 4 generate
221
222with request_word select
223      request_decoder <="0001" when "00001",
224                        "0010" when "00011",
225                        "0100" when "00101",
226                        "1000" when "00111",
227                        "0000" when others;
228
229end generate switch4x4;
230
231
232-- switch 5 ports
233switch5x5 : if number_of_ports = 5 generate
234
235with request_word select
236      request_decoder <="00001" when "00001",
237                        "00010" when "00011",
238                        "00100" when "00101",
239                        "01000" when "00111",
240                        "10000" when "01001",
241                        "00000" when others;
242
243end generate switch5x5;
244
245
246-- switch 6 ports
247switch6x6 : if number_of_ports = 6 generate
248
249with request_word select
250      request_decoder <="000001" when "00001",
251                        "000010" when "00011",
252                        "000100" when "00101",
253                        "001000" when "00111",
254                        "010000" when "01001",
255                        "100000" when "01011",
256                        "000000" when others;
257
258end generate switch6x6;
259
260
261-- switch 7 ports
262switch7x7 : if number_of_ports = 7 generate
263
264with request_word select
265      request_decoder <="0000001" when "00001",
266                        "0000010" when "00011",
267                        "0000100" when "00101",
268                        "0001000" when "00111",
269                        "0010000" when "01001",
270                        "0100000" when "01011",
271                        "1000000" when "01101",
272                        "0000000" when others;
273
274end generate switch7x7;
275
276
277-- switch 8 ports
278switch8x8 : if number_of_ports = 8 generate
279
280with request_word select
281      request_decoder <="00000001" when "00001",
282                        "00000010" when "00011",
283                        "00000100" when "00101",
284                        "00001000" when "00111",
285                        "00010000" when "01001",
286                        "00100000" when "01011",
287                        "01000000" when "01101",
288                        "10000000" when "01111",
289                        "00000000" when others;
290
291end generate switch8x8;
292
293
294-- switch 9 ports
295switch9x9 : if number_of_ports = 9 generate
296
297with request_word select
298      request_decoder <="000000001" when "00001",
299                        "000000010" when "00011",
300                        "000000100" when "00101",
301                        "000001000" when "00111",
302                        "000010000" when "01001",
303                        "000100000" when "01011",
304                        "001000000" when "01101",
305                        "010000000" when "01111",
306                        "100000000" when "10001",
307                        "000000000" when others;
308
309end generate switch9x9;
310
311
312-- switch 10 ports
313switch10x10 : if number_of_ports = 10 generate
314
315with request_word select
316      request_decoder <="0000000001" when "00001",
317                        "0000000010" when "00011",
318                        "0000000100" when "00101",
319                        "0000001000" when "00111",
320                        "0000010000" when "01001",
321                        "0000100000" when "01011",
322                        "0001000000" when "01101",
323                        "0010000000" when "01111",
324                        "0100000000" when "10001",
325                        "1000000000" when "10011",
326                        "0000000000" when others;
327
328end generate switch10x10;
329
330
331-- switch 11 ports
332switch11x11 : if number_of_ports = 11 generate
333
334with request_word select
335      request_decoder <="00000000001" when "00001",
336                        "00000000010" when "00011",
337                        "00000000100" when "00101",
338                        "00000001000" when "00111",
339                        "00000010000" when "01001",
340                        "00000100000" when "01011",
341                        "00001000000" when "01101",
342                        "00010000000" when "01111",
343                        "00100000000" when "10001",
344                        "01000000000" when "10011",
345                        "10000000000" when "10101",
346                        "00000000000" when others;
347
348end generate switch11x11;
349
350
351-- switch 12 ports
352switch12x12 : if number_of_ports = 12 generate
353
354with request_word select
355      request_decoder <="000000000001" when "00001",
356                        "000000000010" when "00011",
357                        "000000000100" when "00101",
358                        "000000001000" when "00111",
359                        "000000010000" when "01001",
360                        "000000100000" when "01011",
361                        "000001000000" when "01101",
362                        "000010000000" when "01111",
363                        "000100000000" when "10001",
364                        "001000000000" when "10011",
365                        "010000000000" when "10101",
366                        "100000000000" when "10111",
367                        "000000000000" when others;
368
369end generate switch12x12;
370
371
372-- switch 13 ports
373switch13x13 : if number_of_ports = 13 generate
374
375with request_word select
376      request_decoder <="0000000000001" when "00001",
377                        "0000000000010" when "00011",
378                        "0000000000100" when "00101",
379                        "0000000001000" when "00111",
380                        "0000000010000" when "01001",
381                        "0000000100000" when "01011",
382                        "0000001000000" when "01101",
383                        "0000010000000" when "01111",
384                        "0000100000000" when "10001",
385                        "0001000000000" when "10011",
386                        "0010000000000" when "10101",
387                        "0100000000000" when "10111",
388                        "1000000000000" when "11001",
389                        "0000000000000" when others;
390
391end generate switch13x13;
392
393
394-- switch 14 ports
395switch14x14 : if number_of_ports = 14 generate
396
397with request_word select
398      request_decoder <="00000000000001" when "00001",
399                        "00000000000010" when "00011",
400                        "00000000000100" when "00101",
401                        "00000000001000" when "00111",
402                        "00000000010000" when "01001",
403                        "00000000100000" when "01011",
404                        "00000001000000" when "01101",
405                        "00000010000000" when "01111",
406                        "00000100000000" when "10001",
407                        "00001000000000" when "10011",
408                        "00010000000000" when "10101",
409                        "00100000000000" when "10111",
410                        "01000000000000" when "11001",
411                        "10000000000000" when "11011",
412                        "00000000000000" when others;
413
414end generate switch14x14;
415
416
417-- switch 15 ports
418switch15x15 : if number_of_ports = 15 generate
419
420with request_word select
421      request_decoder <="000000000000001" when "00001",
422                        "000000000000010" when "00011",
423                        "000000000000100" when "00101",
424                        "000000000001000" when "00111",
425                        "000000000010000" when "01001",
426                        "000000000100000" when "01011",
427                        "000000001000000" when "01101",
428                        "000000010000000" when "01111",
429                        "000000100000000" when "10001",
430                        "000001000000000" when "10011",
431                        "000010000000000" when "10101",
432                        "000100000000000" when "10111",
433                        "001000000000000" when "11001",
434                        "010000000000000" when "11011",
435                        "100000000000000" when "11101",
436                        "000000000000000" when others;
437
438end generate switch15x15;
439
440
441-- switch 16 ports
442switch16x16 : if number_of_ports = 16 generate
443
444with request_word select
445      request_decoder <="0000000000000001" when "00001",
446                        "0000000000000010" when "00011",
447                        "0000000000000100" when "00101",
448                        "0000000000001000" when "00111",
449                        "0000000000010000" when "01001",
450                        "0000000000100000" when "01011",
451                        "0000000001000000" when "01101",
452                        "0000000010000000" when "01111",
453                        "0000000100000000" when "10001",
454                        "0000001000000000" when "10011",
455                        "0000010000000000" when "10101",
456                        "0000100000000000" when "10111",
457                        "0001000000000000" when "11001",
458                        "0010000000000000" when "11011",
459                        "0100000000000000" when "11101",
460                        "1000000000000000" when "11111",
461                        "0000000000000000" when others;
462
463end generate switch16x16;                                                                       
464--latch du fifo de sortie ??
465pipeline_latch_process : process(clk)
466begin
467        if rising_edge(clk) then 
468          if reset_signal = '1' then 
469           pipeline_latch <= (others => '0');
470                 elsif pipeline_latch_en = '1' and cmd_exec='0' then
471                  pipeline_latch <= push_dout;
472                  elsif pipeline_latch_en = '1' and cmd_exec='1' then
473                  pipeline_latch <= cmd_data_signal;
474          end if;
475        end if;
476end process;
477
478--latch qui memorise l'adresse de destination du packet
479
480request_latch_process : process(clk)
481begin
482        if rising_edge(clk) then
483                if reset_signal = '1' then
484                  request_latch <= (others => '0');
485                  elsif request_latch_en = '1' and cmd_in_en='0' then  --si la lecture de la destination est autorisée
486                  request_latch <=fifo_out_signal(3 downto 0); --fifo_out_signal(3) & fifo_out_signal(2) & fifo_out_signal(1) & fifo_out_signal(0);
487                  elsif cmd_in_en='1' and request_latch_en='1' then  --c'est une commande le port de dest est le même que le port d'entrée
488                   request_latch<=Port_ID(3 downto 0);  --car les ports commencent à 0
489                end if;
490        end if;
491end process;
492
493-- machine à etat de mealy qui depile les donnees dans le fifo
494--
495-- processus determinant l'etat futur
496pop_fsm_nsl : process(clk)
497begin 
498        if rising_edge(clk) then 
499         if reset_signal = '1' then
500                pop_state <= state0;
501                data_counter <= (others => '0');
502          elsif cmd_exec='0' then  --il ne faut pas exécuter cette MAE
503                                                                                -- lorsque l'autre est en cours
504         
505                  case pop_state is
506                        when state0 => if cmd_in_en='0'  then --il ne faut pas exécuter les deux MAE ...
507                                                                        if empty_latch  ='0' then -- pile pas vide on doit dépiler                                                                     
508                                                                                pop_state <= WaitGrant;
509                                                                        end if;
510                                                                else
511                                                                        pop_state <= CmdOn;
512                                                                end if;
513                        when CmdOn => if empty_latch='1' and cmd_in_en='0' then
514                                                                pop_state <= state0;
515                                                                elsif empty_latch='0' and cmd_in_en='1' then
516                                                                pop_state <= CmdOn;
517                                                                elsif empty_latch='1' and cmd_in_en='1' then
518                                                                pop_state <= state0;
519                                                                else -- empty_latch='0' and cmd_in_en='0'
520                                                                pop_state <= WaitGrant;
521                                                                end if;
522                                                               
523                        when WaitGrant => if port_granted = '1' then
524                                                                                --
525                                                                                pop_state <= ReqPort;
526                                                                end if;                                 
527                        when ReqPort => --if port_granted = '1' then
528                                                                                --
529                                                                                pop_state <= state1;
530                                                                --end if;
531               
532                        when state1 => if port_granted ='1' then --lecture de la longueur des données
533                                                                                data_counter <= fifo_out_signal;
534                                                                                if unsigned(fifo_out_signal)<=3 then 
535                                                                                                ReadOk<='1';
536                                                                                else
537                                                                                                readOk<='1';
538                                                                                end if;
539                                                                                pop_state <= state2;
540                                                              end if;
541                                                                               
542                        when state2 => if port_granted='1' then 
543                                                                                if rd_en_signal ='1' and unsigned(data_counter)<= 3 then
544                                                                                        data_counter <= data_counter - 1;
545                                                                                        pop_state <= stpulse;
546                                                                                        ReadOk<='1';
547                                                                                elsif rd_en_signal ='1' then
548                                                                                  data_counter <= data_counter - 1;
549                                                                                  pop_state <= state2;
550                                                                                  ReadOk<='1';
551                                                                                else --rd_en_signal='0' fin prématurée de la lecture
552                                                                                        ReadOk<='0';
553                                                                                        pop_state<=stateErr;
554                                                                                        --data_counter<=(others => '0');
555                                                                                end if;
556                                                                        else
557                                                                                ReadOk<='0';
558                                                                        end if;
559                       
560                        when stpulse => if port_granted='1' then 
561                                                                                        pop_state <= state3;            --pousser la dernière donnée dehors             
562                                                                                        data_counter <= data_counter - 1;
563                                                                        end if;
564                       
565                        when state3 => 
566                                                                                data_counter <= data_counter - 1;
567                                                                                pop_state <= state0;
568                        when stateErr =>         
569                                                                                data_counter <= data_counter;
570                                                                                pop_state <= stateErr;                                                                                         
571                        when others => pop_state <= state0;
572                   end case;
573         end if;
574        end if;
575end process;
576
577-- actions associées à chaque etat de la fsm de mealy
578pop_fsm_action : process(pop_state, fifo_out_signal,empty_latch, rd_en_signal,readok, port_granted )
579  begin   
580-- code fonctionnel     
581        case pop_state is
582                when state0 =>    dat_request_latch_en <= '0'; 
583                                                                dat_pipeline_latch_en <= rd_en_signal;
584                                                                dat_fifo_read_signal <='0';
585                                                                dat_request_decoder_en <= '0';
586                                                                dat_data_out_pulse <= '0';
587                                                                dat_priority_rotation <= '1';
588                                                                dat_exec<='0';
589                                                                dat_Err<='0';
590                                                                push_dout<=fifo_out_signal;
591                                                               
592                when CmdOn =>           dat_request_latch_en <= '0'; 
593                                                                dat_pipeline_latch_en <= '0';
594                                                                dat_fifo_read_signal <='0';
595                                                                dat_request_decoder_en <= '0';
596                                                                dat_data_out_pulse <= '0';
597                                                                dat_priority_rotation <= '1';
598                                                                dat_exec<='0';
599                                                                dat_Err<='0';
600                                                                push_dout<=fifo_out_signal;
601                when WaitGrant =>       
602                                                                dat_request_latch_en <='1'; --autoriser l'identification du port de destination
603                                                                dat_pipeline_latch_en <= Port_granted; --pour le transmettre à travers le réseau
604                                                                dat_fifo_read_signal <= '0';
605                                                                dat_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
606                                                                dat_data_out_pulse <= '0';     --transmettre le signal pour le dernier mot
607                                                                dat_priority_rotation <= Port_granted; --dès qu'on a la priorité on la garde
608                                                                dat_exec<='1';
609                                                                dat_Err<='0';
610                                                                push_dout<=fifo_out_signal(7 downto 4) & PORT_ID(3 downto 0);
611                when ReqPort => 
612                                                                dat_request_latch_en <='1'; --autoriser l'identification du port de destination
613                                                                dat_pipeline_latch_en <= '1'; --pour le transmettre à travers le réseau
614                                                                dat_fifo_read_signal <= '1';
615                                                                dat_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
616                                                                dat_data_out_pulse <= '0';     --transmettre le signal pour le dernier mot
617                                                                dat_priority_rotation <= '0';
618                                                                dat_exec<='1';
619                                                                dat_Err<='0';
620                                                                push_dout<=fifo_out_signal(7 downto 4) & PORT_ID(3 downto 0);
621                                                       
622                when state1 =>    dat_request_latch_en <= '0';
623                                                                dat_pipeline_latch_en <= rd_en_signal and port_granted;   
624                                                                dat_fifo_read_signal <= rd_en_signal and port_granted;
625                                                                dat_request_decoder_en <= '1';
626                                                                dat_data_out_pulse <= port_granted;
627                                                                dat_priority_rotation <= '0';
628                                                                dat_exec<='1';
629                                                                dat_Err<='0';
630                                                                push_dout<=fifo_out_signal;
631                                                               
632          when state2 =>    dat_request_latch_en <= '0';
633                                                                dat_pipeline_latch_en <= rd_en_signal;  --autoriser la lecture du fifo en sortie
634                                                                dat_fifo_read_signal <= readok;   
635                                                                dat_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
636                                                                dat_data_out_pulse <= readOk;
637                                                                dat_priority_rotation <= '0';
638                                                                dat_exec<='1';
639                                                                dat_Err<='0';
640                                                                push_dout<=fifo_out_signal;
641                                                               
642          when stpulse =>    dat_request_latch_en <= '0'; --pousser la dernière donnée
643                                                                dat_pipeline_latch_en <= '0';  --autoriser la lecture du fifo en sortie
644                                                                dat_fifo_read_signal <='0';   
645                                                                dat_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
646                                                                dat_data_out_pulse <= '1';  -- pousser le dernier mot
647                                                                dat_priority_rotation <= '0';
648                                                                dat_exec<='1';
649                                                                dat_Err<='0';
650                                                                push_dout<=fifo_out_signal;
651                                                               
652                when state3 =>    dat_request_latch_en <= '0';
653                                                                dat_pipeline_latch_en <= '0';
654                                                                dat_priority_rotation <= '1';    -- libérer la priorité
655                                                                dat_fifo_read_signal <= '0';
656                                                                dat_request_decoder_en <= '0';   --libérer le décodeur
657                                                                dat_data_out_pulse <= '0';
658                                                                dat_exec<='0';
659                                                                dat_Err<='0';
660                                                                push_dout<=fifo_out_signal;
661                when stateErr =>    dat_request_latch_en <= '0';
662                                                                dat_pipeline_latch_en <= '0';
663                                                                dat_priority_rotation <= '1';    -- libérer la priorité
664                                                                dat_fifo_read_signal <= '0';
665                                                                dat_request_decoder_en <= '0';   --libérer le décodeur
666                                                                dat_data_out_pulse <= '0';
667                                                                dat_exec<='1';
668                                                                dat_Err<='1';
669                                                                push_dout<=fifo_out_signal;
670                when others =>    dat_request_latch_en <= '0';
671                                                                dat_pipeline_latch_en <= '0';
672                                                                dat_priority_rotation <= '1';
673                                                                dat_fifo_read_signal <= '0';
674                                                                dat_request_decoder_en <= '0';
675                                                                dat_data_out_pulse <= '0';
676                                                                dat_exec<='0';
677                                                                dat_Err<='0';
678                                                                push_dout<=fifo_out_signal;
679                                                                               
680                end case;
681 end process; 
682 -- traitement des commandes reçues par le switch
683fsm_cmd:process(clk,cmd_in_en)
684variable timeout : natural:=0;
685variable cmdcode : natural range 0 to 255;
686begin
687if rising_edge(clk) then
688   if reset_signal = '1' then
689           cmdstate<=cmdstart;
690        else -- il ne faut pas traiter les cmdes et les données en même temps
691        case cmdstate is
692       
693           when cmdstart  =>
694                                if cmd_in_en='1' and dat_exec='0' and empty_latch='0' then 
695                                cmdstate<=cmdread;
696                                end if;
697                                cmdReadOk<='0';
698                when cmdwait => if port_granted='1' then  -- demande du port de sortie
699                                                               
700                                                                        cmdstate<=cmdsetdest;
701                                                        elsif cmd_in_en='1' then
702                                                                cmdstate<=cmdwait;
703                                                        else 
704                                                                cmdstate<=cmdstart;
705                                                        end if;
706                                                        cmdReadOk<='0';
707                when cmdread =>
708--                              if port_granted ='1'then -- ne pas modifier l'état des priorités si on ne l'avait pas
709                                        cmdcode:= to_integer(unsigned(fifo_out_signal));
710                                        if cmdcode=1 then --code de getportid
711                                                        cmdstate<=cmdwait;
712                                                        cmdReadOk<='1';
713                                        else
714                                                        --ne pas prendre le code inconnu en compte
715                                                        cmdstate<=cmdend; -- la commande n'a pas été reconnu
716                                               
717                                                cmdReadOk<='0';
718                                        end if;
719--                              end if;
720                when cmdsetdest =>
721                                if port_granted='1' then
722                                        cmdstate<=cmdsetcount;
723                                end if;
724                                cmdReadOk<='0';
725                when cmdsetcount =>
726                                if port_granted='1' then
727                                        cmdstate<=cmdsetID;
728                                else
729                                        cmdstate<=cmdsetdest;
730                                end if;
731                                cmdReadOk<='0';
732                when cmdsetID=>
733                        if port_granted='1' then
734                        cmdstate <=cmdpulse;
735                        end if;
736                        cmdReadOk<='0';
737                when cmdpulse =>
738                        if port_granted='1' then
739                        cmdstate <=cmdEnd;
740                        end if;
741                        cmdReadOk<='0';
742                when cmdend  =>
743                        if cmd_in_en='0' then --éviter l'exécution en boucle
744                                cmdstate<=cmdstart; 
745                        end if;
746                        cmdReadOk<='0'; 
747         
748        end case;
749        end if;         
750end if;
751end process fsm_cmd;
752
753cmdaffect:process (cmdstate,fifo_empty_signal, port_granted, PORT_ID)
754begin
755case cmdstate is
756
757        when cmdstart =>
758                                                cmd_exec<='0';
759                                                cmd_pipeline_latch_en <='0';
760                                                cmd_priority_rotation <= '1';
761                                                cmd_request_latch_en<='0';
762                                                cmd_fifo_read_signal <= '0';
763                                                cmd_request_decoder_en <= '0';
764                                                cmd_data_signal<=(others=>'0');
765                                                cmd_data_out_pulse <= '0';
766
767        when cmdread =>
768                                                cmd_exec<='1';
769                                                cmd_pipeline_latch_en <= '0';
770                                                cmd_fifo_read_signal <= '1'; -- vider le tampon d'entrée
771                                                cmd_request_latch_en<='1';    --mémoriser l'adresse de destination
772                                                cmd_request_decoder_en <= '1';                   --demande d'émission
773                                                cmd_data_out_pulse <= '0';
774                                                cmd_priority_rotation <= '1';                    --sans priorité
775                                                cmd_data_signal<=Port_ID; 
776                when cmdwait =>
777                                                cmd_exec<='1';
778                                                cmd_pipeline_latch_en <='0';
779                                                cmd_fifo_read_signal <= '0';
780                                                cmd_request_latch_en<='1';
781                                                cmd_priority_rotation <= '0';    --avec priorité
782                                                cmd_request_decoder_en <= '1';   --demande d'émission
783                                                cmd_data_signal<=Port_ID;
784                                                cmd_data_out_pulse <= '0';                                     
785        when cmdsetdest  =>
786                                                --cmd_request_decoder_en <= '1';
787                                                cmd_exec<='1';
788                                                cmd_pipeline_latch_en <='1'; --empiler dans le tampon de sortie la donnée
789                                                cmd_fifo_read_signal <='0';
790                                                cmd_request_latch_en<='0';
791                                                cmd_request_decoder_en <= '1';          --autoriser le decodeur à activer le dernier bit de request
792                                                cmd_data_out_pulse <= '0';
793                                                cmd_priority_rotation <= '0';
794                                                cmd_data_signal<=Port_ID;    -- le numéro du port et le nombre total des ports est envoyé
795        when cmdsetcount =>
796                                                                 
797                                                cmd_exec<='1';   
798                                                cmd_pipeline_latch_en <='1'; -- empiler dans le tampon de sortie les données
799                                                cmd_fifo_read_signal <='0';
800                                                cmd_request_latch_en<='0';  --enregistrer l'adresse de destination
801                                                cmd_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
802                                                cmd_data_out_pulse <= port_granted;
803                                                cmd_priority_rotation <= '0';
804                                                cmd_data_signal<=STD_LOGIC_VECTOR(to_unsigned(3,8));                                   
805        when cmdSetId =>
806                                                --cmd_request_decoder_en <= '1';
807                                                cmd_exec<='1';
808                                                cmd_pipeline_latch_en <='1';
809                                                cmd_fifo_read_signal <='0';
810                                                cmd_request_latch_en<='0';                      --enregistrer l'adresse de destination
811                                                cmd_request_decoder_en <= '1';          --autoriser le decodeur à activer le dernier bit de request
812                                                cmd_data_out_pulse <= port_granted;
813                                                cmd_priority_rotation <= '0';
814                                                cmd_data_signal<=Port_ID;    -- le numéro du port et le nombre total des ports est envoyé
815                                                                                       
816        when cmdpulse =>        cmd_exec<='1';
817                                                cmd_pipeline_latch_en <='0';
818                                                cmd_fifo_read_signal <='0';
819                                                cmd_request_latch_en<='0';
820                                                cmd_request_decoder_en <= '1';          --autoriser le decodeur activer le dernier bit de request
821                                                cmd_data_out_pulse <= port_granted;     --s'assurer que la dernière donnée est bien lue
822                                                cmd_priority_rotation <= '0';
823                                                                --cmd_data_signal<=Port_ID ;
824                                                cmd_data_signal<=Port_ID; 
825                                               
826        when cmdend =>
827                                                                cmd_exec<='0';
828                                                                cmd_request_latch_en <= '0';
829                                                                cmd_pipeline_latch_en <= '0';
830                                                                cmd_fifo_read_signal <= '0';
831                                                                cmd_request_latch_en<='0';
832                                                                cmd_request_decoder_en <= '0';
833                                                                cmd_data_out_pulse <= '0';
834                                                                cmd_priority_rotation <= '1';
835                                                                cmd_data_signal<=(others=>'0');
836                                                               
837                                                               
838end case ;
839end process cmdaffect;
840
841end Behavioral;
842
843
Note: See TracBrowser for help on using the repository browser.