source: PROJECT_CORE_MPI/CORE_MPI/BRANCHES/v0.03/EX4_FSM.vhd @ 64

Last change on this file since 64 was 64, checked in by rolagamo, 11 years ago
File size: 38.6 KB
Line 
1----------------------------------------------------------------------------------
2-- Company:
3-- Engineer: GAMOM
4--
5-- Create Date:    14:44:36 03/07/2012
6-- Design Name:
7-- Module Name:    EX4_FSM - Behavioral
8-- Project Name: MPI_CORE_COMPONENTS
9-- Target Devices: SPARTAN 3E xc3s1200e
10-- Tool versions:
11-- Description: Ce module renferme les fonctions permettant d'initialiser la
12-- bibliothèque matériel MPI
13-- Dependencies:
14--
15-- Revision: 25/juin/2012 au 24/Octobre/2012
16-- Revision 0.03 - File updated
17-- Additional Comments:
18--
19----------------------------------------------------------------------------------
20library IEEE;
21
22use IEEE.STD_LOGIC_1164.ALL;
23
24-- Uncomment the following library declaration if using
25-- arithmetic functions with Signed or Unsigned values
26use IEEE.NUMERIC_STD.ALL;
27Library NocLib;
28use NoCLib.CoreTypes.all;
29use work.packet_type.all;
30
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 EX4_FSM is
37    Port ( Instruction : in  STD_LOGIC_VECTOR (Word-1 downto 0);
38           Instruction_En : in  STD_LOGIC;
39           clk : in  STD_LOGIC;
40           reset : in  STD_LOGIC;
41           ResultOut : out  STD_LOGIC_VECTOR (Word-1 downto 0):=(others=>'0');
42           Result_En : out  STD_LOGIC:='0';
43           NocSize : out  STD_LOGIC_VECTOR(3 downto 0);
44                          PortId : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
45           AppRank : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
46           AppSize : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
47           IsMain : out  STD_LOGIC:='0';
48                          Initialized : out STD_LOGIC:='0';
49                          dma_wr_req : out std_logic:='0';
50                          dma_wr_grant : in std_logic;
51           AdrRam : out  STD_LOGIC_VECTOR (ADRLEN-1 downto 0):=(others=>'0'); --accès au stockage
52           WeRam : out  STD_LOGIC:='0'; --activation de l'écriture en RAM
53           DataRam : out  STD_LOGIC_VECTOR (Word-1 downto 0):=(others=>'Z');--données des ports
54           AppAck : in  STD_LOGIC;
55           AppReq : in  STD_LOGIC;
56                          port_in_cmd_en : out  STD_LOGIC:='0';
57                          port_in_wr_en : out  STD_LOGIC:='0';
58                          port_in_empty : in  STD_LOGIC;
59           port_in_full : in  STD_LOGIC;
60           port_in_data : out  STD_LOGIC_VECTOR (Word-1 downto 0):=(others=>'Z');
61                          port_out_data : in  STD_LOGIC_VECTOR (Word-1 downto 0);
62           port_out_rd_en : out  STD_LOGIC:='0';
63           port_out_data_available : in  STD_LOGIC);
64end EX4_FSM;
65
66architecture Behavioral of EX4_FSM is
67
68
69Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in;
70Type Ar_MPIPort_out is array (positive range <>) of Typ_MPIPort_out;
71
72        --MAE pour emission de init
73   --type init1_type is (init,NocSize,InitToNoc,NextPort,EndBCast);
74        --      MAE pour affectation des rangs aux différentes librairies MPI
75        type init2_type is (init,GetPortNum,DecodeData,IsPortZero,SeekMain1,SeekMain2,StoreMain,SetMainFlag,ReadNoc,GetMainReq,StoreRank,NewRank,SendRank,RegRank,SendPeerStat,GetPeerStat,SendApp,EndInit);
76   -- MAE pour réception de init depuis le réseau;
77        type init3_type is  (init,GetNocSize,ReadInitHead,StorePort,EndInit); 
78        type typ_send is (s_init,s_head,s_len,s_len2,s_data,s_end);
79        type typ_receiv is (r_wait,r_dlen,r_drop,r_glen,r_data,r_pulse,r_end);
80        type typ_cmd is (cmdstart,cmdpost,cmdpostidle,cmdread,cmdlen,cmdglen,cmddata,cmdend,cmdtimeout);
81
82                signal etsnd : typ_send;
83                signal etrec:typ_receiv;   --pour la machine à état de réception
84                signal etcmd :typ_cmd;     --pour la machine à état de commande
85--      signal stInit1, next_stInit1 : init1_type;
86        signal stInit2, next_stInit2 : init2_type; 
87        --signal stInit3, next_stInit3 : init3_type;
88        --signaux pour l'interface avec les ports
89        signal cport_in_wr_en,sport_in_wr_en:std_logic;
90        signal cport_out_rd_en,rport_out_rd_en:std_logic;
91        signal tosend,tosend4 :std_logic_vector(Word-1 downto 0);
92        signal PeerStat : std_logic_vector(15 downto 0):=(others=>'0'); --état des autres Lib initialisées
93        signal selector : std_logic_vector (2 downto 0); -- pour le MUX des signaux vers le port
94        --signaux pour les états des MAE
95        signal  NocSizeOk,PortCountFlag : std_logic;
96        signal PortNumFlag,EquFlag,MainResp,RankAsked,RankSent:std_logic;
97       
98   signal RTS_cmd,RTS_dat,CTR,BCast,Send_Ack,DS_Ack,CM_Ack:std_logic:='0';
99        signal Rcv_On,Snd_On,Cmd_On : std_logic:='0'; --status des MAE d'envoie et de réception
100        signal DS_RDY ,BCast_Rdy,Send_RDY,CM_RDY:std_logic:='0';
101        signal ExecTime_out:std_logic;
102        --signaux de gestion de la RAM
103        signal Ram_NextAdress : std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
104        signal Ram_NExtAdress_i :std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
105        --Signaux des résultats et de l'état
106   signal PortNum_i,MyPort : std_logic_vector(3 downto 0);  --
107        signal NocMax : std_logic_vector(3 downto 0); -- Nombre de ports du réseau -1 ?
108        signal MyRank : std_logic_vector(3 downto 0) ; --rang du PE
109        signal MainPort : std_logic_vector(3 downto 0) ; --Port de la lib main
110        signal NextRank,NextRank_i : std_logic_vector(3 downto 0):=(others=>'0'); --utiliser pour gérer les affectations de rangs MPI
111   signal DataToSend : Typ_PortIo(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0')); -- permet d'empiler les données à envoyer
112        signal CmdReceived,DataReceived : Typ_PortIO(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0'));
113        signal Datalen : natural range 0 to 3 :=0; --indique la longueur des données
114        --other outputs
115        signal RankAsked_i,EquFlag_i,MainResp_i,RankSent_i,IsMain_i,Result_i:std_logic;
116   --signal BCast_Rdy_i : std_logic;
117        signal cdlen,dcount,timeout,timeout_i : natural range 0 to 255:=0; --longueur du paquet reçu par le process pcmd
118        signal PortStat : std_logic_vector(3 downto 0):=(others=>'0');
119        signal PeerPort : natural range 0 to 15:=0; -- désigne le port qui emet une requête
120        signal PeerRTS,PeerCTR:std_logic:='0';
121        signal cpt,cpt_peer : natural range 0 to 15:=0; --compteur pour le nombre de HT initialisés
122        signal clk_cyl,clk_cyl_i : natural range 0 to 15:=0;
123begin
124--=======================================================================================
125--fonctions du module
126--=======================================================================================
127--=======================================================================================
128 
129 
130 
131   -- Gestion de l'initialisation du Core MPI
132  sync_Init2 : process (clk,reset)
133  begin
134        if reset='1' then
135                stinit2<=init;
136        elsif rising_edge(clk) then
137                stinit2<=next_stinit2;
138                --ajout des autres affectations ici
139                Ram_NextAdress<=Ram_NextAdress_i  ;
140               
141                RankAsked<=RankAsked_i;
142                RankSent<=RankSent_i;
143                AppRank<=MyRank;
144                timeout<=timeout_i;
145                cpt<=cpt_peer;
146                clk_cyl<=clk_cyl_i;
147                NextRank<=NextRank_i;
148        end if;
149end process;
150
151  Init2_DECODE: process (stinit2, CmdReceived, EquFlag, MyPort, DS_RDY, MainResp, DataReceived, Ram_NextAdress,PeerRTS)
152   variable nextr,nextadr : natural :=to_integer(unsigned(Ram_NextAdress));
153        variable nport : natural range 0 to 15:=0;
154        begin
155     
156      Case stInit2 is
157                When Init =>
158                        RTS_cmd<='0';
159                        RTS_dat<='0';
160                        BCast<='0';
161                        Result_En<='0';
162                        Initialized<='0';
163                        CM_Ack <='0';
164                        CTR<='0' ;
165                        DS_ACK<='0';
166                        Send_Ack<='0';
167                        WeRam<='0';
168                        ResultOut<=(others=>'0');
169                        PortNum_i<=(others=>'Z');
170                        IsMain<='0';
171                        EquFlag<='0';
172                        RankAsked_i<='0';
173                        dma_wr_req<='0';
174
175                When GetPortNum =>
176                        RTS_cmd<='1';
177                        RTS_dat<='0';
178                        Result_En<='0';
179                        Initialized<='0';
180                        BCast<='0';   --réalise un envoie non collectif
181                        CM_Ack<='0';   -- les données sont maintenant attendues
182                        CTR<='0' ;
183                        DataToSend(0)<=X"0" & GETPORTID;
184                        DS_ACK<='0';
185                        Send_Ack<='0';
186                        WeRam<='0';
187                        IsMain<='0';
188                        ResultOut<=(others=>'0');
189                        PortNum_i<=(others=>'Z');
190                        RankAsked_i<='0';
191                        dma_wr_req<='0';
192                When DecodeData =>
193                        EquFlag<=(All_zeros(Cmdreceived(2)(3 downto 0)));
194                        RTS_cmd<='0';
195                        RTS_dat<='0';
196                        BCast<='0';
197                        IsMain<='0';
198                        Result_En<='0';
199                        Initialized<='0';
200                        CM_Ack <='1'; --les données ont été reçues
201                        MyPort<=Cmdreceived(2)(3 downto 0);
202                        PortNum_i<=Cmdreceived(2)(3 downto 0); --récupère les valeurs de port
203                        PeerPort<=To_integer(unsigned(Cmdreceived(2)(3 downto 0)));
204                        NocMax<=Cmdreceived(2)(7 downto 4);  -- et la taille du réseau
205                        PortNumFlag<='1';  -- le numéro du port est maintenant connu
206                        CTR<='0' ;
207                        DS_ACK<='0';
208                        Send_Ack<='0';
209                        WeRam<='0';
210                        RankAsked_i<='0';
211                        ResultOut<=(others=>'0');
212                        dma_wr_req<='0';
213                When IsPortZero => --Ce port est-il le n° 0 du NoC ?
214                        BCast<='0';
215                        Result_En<='0';
216                        Initialized<='0';
217                        RTS_cmd<='0';
218                        RTS_dat<='0';
219                        NextRank_i<="0001"; -- le prochain rang à affecter sera le n° 1
220                        nextr:=1;
221                        IsMain<=EquFlag;
222                        MyRank<="0000";
223                        MainPort<="0000";
224                        --MainAdr<="0000";   -- le port 0 est le main Lib par défaut;
225                        CTR<='0' ;
226                        DS_ACK<='0';
227                        WeRam<='0';
228                        RankAsked_i<='0';
229                        ResultOut<=(others=>'0');
230                        dma_wr_req<='0';
231                When SeekMain1 =>    -- recherche de la lib main
232                                RTS_cmd<='0';
233                                RTS_DAT<='1';
234                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
235                                DS_ACK<='0'; --les données sont attendus
236                                Send_Ack<=BCast_rdy;
237                                DataToSend(0)<=INIT_SEEKMAIN & MyPort ;
238                                DataToSend(1)<="00000011"; -- la longueur du packet =3
239                                DataToSend(2)<="0000" & MyPort; --propose sa propre adresse
240                                DataLen<=3;
241                                BCast<='1';
242                                IsMain<='0';
243                                Result_En<='0';
244                                Initialized<='0';
245                                WeRam<='0';
246                                ResultOut<=(others=>'0');
247                                EquFlag<='0';
248                                RankAsked_i<='0';
249                                dma_wr_req<='0';
250                When SeekMain2 =>    -- recherche de la lib main
251                                RTS_cmd<='0';
252                                RTS_DAT<='0';
253                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
254                                DS_ACK<= DS_RDY; --les données sont acquittées aussitôt reçues
255                                Send_Ack<=BCast_rdy;
256--                              DataToSend(0)<=INIT_SEEKMAIN & MyPort ;
257--                              DataToSend(1)<="00000011"; -- la longueur du packet =3
258--                              DataToSend(2)<="0000" & MyPort; --propose sa propre adresse
259--                              DataLen<=3;
260                                BCast<='0';
261                                IsMain<='0';
262                                Result_En<='0';
263                                Initialized<='0';
264                                WeRam<='0';
265                                ResultOut<=(others=>'0');
266                                EquFlag<='0';
267                                RankAsked_i<='0';
268                                dma_wr_req<='0';
269                When StoreMain =>     -- la Main Lib est une autre
270                                BCAST<='0';
271                                Result_En<='0';
272                                IsMain<='0';
273                                Initialized<='0';
274                                DS_ACK<=DS_RDY;
275                                Send_Ack<='0';
276                                RTS_cmd<='0';
277                                RTS_DAT<='0';
278                                CTR<=not(MainResp);  -- essayer de recevoir tant que le main n'a pas répondu
279                                WeRam<='1';
280                                ResultOut<=(others=>'0');
281                                RankAsked_i<='0';
282                                EquFlag<='0';
283                                MainPort<=DataReceived(0)(3 downto 0);
284                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
285                                DataRam<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
286                                dma_wr_req<= '0';  ---pas très sûr
287                When SetMainFlag =>   -- Cette Lib est la Main Lib
288                                if (Datareceived(0)(7 downto 4) = INIT_SEEKMAIN) then 
289                                        RankAsked_i<='1';
290                                else 
291                                        RankAsked_i<='0';
292                                end if;
293                                RTS_cmd<='0';
294                                Initialized<='0';
295                      RTS_DAT<='0';
296                                BCast<='0';
297                                IsMain<='0';
298                                Result_En<='0';
299                                MyRank<="0000";
300                                MainPort<="0000";
301                                PeerStat(0)<='1'; --la main lib est initialisée
302                                CTR<='1';
303                                DS_ACK<='0';
304                                WeRam<='1';
305                                ResultOut<=(others=>'0');
306                                EquFlag<='1';
307                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
308                                DataRam<=(others =>'0');  -- le port vaut 0 et la mainlib est aussi à 0
309                                dma_wr_req<='1';
310                When ReadNoc =>
311                                if (Datareceived(0)(7 downto 4) = INIT_SEEKMAIN) then
312                                        RankAsked_i<='1' ;
313                                else 
314                                        RankAsked_i<='0';
315                                end if;
316                                WeRam<='0';  -- pas d'écriture en RAM
317                                BCast<='0';
318                                DS_ACK<='0';
319                                --IsMain<='0';
320                                Result_En<='0';
321                                Initialized<='0';
322                                RTS_cmd<='0';
323                                RTS_DAT<='0';
324                                CTR<='1';
325                                ResultOut<=(others=>'0');
326                                PortNum_i<=DataReceived(2)(3 downto 0); -- le port qui demande un rang;
327                                PeerPort<= To_integer(unsigned(DataReceived(2)(3 downto 0)));
328                                --EquFlag<='1';
329                                dma_wr_req<='0';
330                When GetMainReq  =>
331                                --RankAsked_i<='1';
332                                WeRam<='0';  -- pas
333                                BCast<='0';
334                                DS_ACK<='1';
335                                IsMain<='0';
336                                Result_En<='0';
337                                Initialized<='0';
338                                RTS_cmd<='0';
339                                RTS_DAT<='0';
340                                CTR<='1';
341                                ResultOut<=(others=>'0');
342                                PortNum_i<=DataReceived(0)(3 downto 0); -- le port qui demande un rang;
343                                EquFlag<='1';
344                                dma_wr_req<='0';
345                When GetPeerStat  =>
346                                --RankAsked_i<='1';
347                                WeRam<='0';  -- pas
348                                BCast<='0';
349                                DS_ACK<='1';
350                                IsMain<='0';
351                                Result_En<='0';
352                                Initialized<='0';
353                                RTS_cmd<='0';
354                                RTS_DAT<='0';
355                                CTR<='1';
356                                ResultOut<=(others=>'0');
357                                PortNum_i<=DataReceived(0)(3 downto 0); --adresse du Main Port
358                                EquFlag<='1';
359                                dma_wr_req<='0';
360                When NewRank =>
361                                nport:=to_integer(Unsigned(PortNum_i)); --port ayant sollicité le rang
362                                if PeerStat(nport)='0' then -- si le rang n'a pas encore été affecté à ce port
363                                nextrank_i<=incr_vec(nextrank,'1');
364                                NextAdr:=NextAdr+1;
365                                end if;
366                                --NextRank<=incr_vec(NextRank,'1');
367                                nextr:=to_integer(unsigned(nextrank));
368                                DataToSend(0)<=INIT_SETRANK & PortNum_i ;
369                                DataToSend(1)<="00000011";
370                                DataToSend(2)<="0000" & NextRank;  --ici c'est la valeur avant incrémentation !
371                                PeerStat(nport)<='1'; -- mise à jour du status
372                                DataLen<=3;
373                                BCast<='0';
374                                DS_ACK<='0';
375                                Result_En<='0';
376                                Initialized<='0';
377                                EquFlag<='1';
378                                RTS_cmd<='0';
379                                Rts_DAT<='1';
380                                IsMain<='0';
381                                CTR<='0' ;
382                                WeRam<='0';
383                                RankAsked_i<='1';
384                                ResultOut<=(others=>'0');
385                                dma_wr_req<='0';
386                When SendRank =>
387                                BCast<='0';
388                                Result_En<='0';
389                                EquFlag<='1';
390                                Rts_DAT<='1';
391                                RTS_cmd<='0';
392                                DS_ACK<='0';
393                                Send_Ack<='0';
394                                IsMain<='0';
395                                CTR<='0' ;
396                                WeRam<='0';
397                                Ram_NextAdress_i<= STD_logic_vector(to_unsigned(CORE_RANK_ADR+Nextr-1,16));
398                                ResultOut<=(others=>'0');
399                                RankAsked_i<='1';
400                                Initialized<='0';
401                                dma_wr_req<='0';
402                When RegRank =>
403--                              if (Datareceived(0)(7 downto 4) = INIT_SEEKMAIN) then
404--                                      RankAsked_i<='1';
405--                              else
406                                        RankAsked_i<='0';
407--                              end if;
408                                CTR<='1' ; -- continuer à recevoir les données du NoC
409                                Result_En<='0';
410                                Initialized<='0';
411                                RTS_cmd<='0';
412                                DS_ACK<='0';
413                                Send_Ack<=Send_RDY;
414                                IsMain<='0';
415                                Rts_Dat<='0';
416                                BCast<='0';
417                                EquFlag<='1';
418                                WeRam<='1';
419                               
420                                Ram_NextAdress_i<= STD_logic_vector(to_unsigned(CORE_RANK_ADR+Nextr-1,16)); --incr_vec(Ram_NextAdress,'1');
421                                AdrRam<=Ram_NextAdress;  -- le rang qui a été envoyé;
422                                -- "le motif 0001 indique juste que le port est bien activé
423                                DataRam<="0001" & PortNum_i; --enregistrer le port qui a fait la demande en RAM
424                                ResultOut<=(others=>'0');
425                                dma_wr_req<='1';
426                When SendPeerStat =>
427                                BCast<='0';
428                                Result_En<='0';
429                                EquFlag<='0';
430                                Rts_DAT<=PeerRTS;
431                                RTS_cmd<='0';
432                                DS_ACK<='0';
433                                DataToSend(0)<=INIT_REGISTER & PortStat ;
434                                DataToSend(1)<="00000011";
435                                DataToSend(2)<=PeerStat(7 downto 0);
436                                Send_Ack<=Send_Rdy;
437                                IsMain<='0';
438                                CTR<='0' ;
439                                WeRam<='0';
440                                ResultOut<=(others=>'0');
441                                RankAsked_i<='1';
442                                Initialized<='0';
443                                dma_wr_req<='0';
444                When StoreRank => --le processus qui écoute le Port et qui
445                                                                --stoke les adresses des autres bib va gérer le stockage du rang
446                                BCAST<='0';
447                                DS_ACK<='1';
448                                Send_Ack<='0';
449                                RTS_cmd<='0';
450                                EquFlag<='0';
451                                RTS_DAT<='0';
452                                CTR<='0';
453                                Result_En<='0';
454                                Initialized<='0';
455                                IsMain<='0';
456                               
457                                if ExecTime_out='1' then
458                                MainPort<="0000";
459                                MyRank<=MyPort;
460                                else
461                                MainPort<=DataReceived(0)(3 downto 0);
462                                MyRank<=DataReceived(2)(3 downto 0);
463                                 
464                                end if;
465                                WeRam<='1';
466                                --AdrRam<=DataReceived(2);  -- le rang qui a été envoyé;
467                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
468                                DataRam<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
469                                ResultOut<=(others=>'0');
470                                RankAsked_i<='0';
471                                dma_wr_req<='1';
472                When SendApp =>  --ajouter du code pour recevoir l'adr du reg status
473                                Initialized<='1';
474                                ResultOut<="00000001"; -- Init Ok
475                                Result_En<='1';
476                                IsMain<='0';
477                                PortId<=MyPort;
478                                BCAST<='0';
479                                DS_ACK<='1';
480                                Send_Ack<='0';
481                                RTS_cmd<='0';
482                                RTS_DAT<='0';
483                                CTR<='0';
484                                WeRam<='0';
485                                RankAsked_i<='0';
486                                dma_wr_req<='0';
487                When EndInit=>
488                                RTS_cmd<='0';
489                                RTS_DAT<='0';
490                                Result_En<='0';
491                                IsMain<='0';
492                                Initialized<='0';
493                                DS_ACK<='0';
494                                Send_Ack<='0';
495                                BCAST<='0';
496                                CTR<='0';
497                                WeRam<='0';
498                                RankAsked_i<='0';
499                                ResultOut<=(others=>'0');
500                                dma_wr_req<='0';
501                end case;
502   end process;
503 
504   NEXT_STInit2_DECODE: process (stInit2,AppReq, AppAck,PortNumFlag,EquFlag,MainResp,RankAsked,RankSent,CM_RDY, CmdReceived, 
505        BCast_Rdy, DS_RDY, DataReceived, Send_RDY,TimeOut,Dma_wr_grant,cpt,clk_cyl)
506   variable InitTimeOut :natural:=0;
507   variable vPortStat,nulvect : std_logic_vector(3 downto 0):="0000";   
508       
509  begin
510      --declare default state for next_state to avoid latches
511      next_stInit2 <= stInit2;  --default is to stay in current state
512      --insert statements to decode next_state
513      --below is a simple example
514      case (stInit2) is
515         
516                       
517                When Init =>If AppReq='1' then
518                                         If PortNumFlag='1' and RankAsked='1' then
519                                                Next_stInit2 <=ReadNoC;
520                                         else
521                                                Next_stInit2 <=GetPortNum;
522                                        end if;
523                                        TimeOut_i<=0;PeerRTS<='0';
524                                end if;
525                               
526                When GetPortNum =>  -- récupérer le numéro du port
527                                                                                               
528                                                if CM_RDY='1' then 
529                                                        Next_stInit2 <=DecodeData;
530                                                end if;
531                                               
532                When DecodeData =>  -- cet état permet de lire les données reçues du port
533                                                        --if CM_RDY='1' then
534                                                                if ((Cmdreceived(2)(3 downto 0) or nulvect)=nulvect) then -- teste si le n° du port est zero
535                                                                  --EquFlag<='1';
536                                                                 else
537                                                                  --EquFlag<='0';
538                                                                end if;
539                                                               
540                                                                Next_stInit2 <=IsPortZero;
541                                                        --end if;
542                When IsPortZero => 
543                                                if PortNumFlag='1' then 
544                                               
545                                                End if;
546                                                if EquFlag='0'  then  --tester le numéro de port obtenu
547                                                        Next_stInit2 <=SeekMain1; -- chercher le numéro de port sur le réseau
548                                                else 
549                                                        Next_stInit2<=SetMainFlag; -- enregistrer le numéro de port
550                                                End If;
551                                                TimeOut_i<=0;
552               
553                When SeekMain1 =>If BCast_RDY='1' then  -- si tous les envois ont été postés
554                                                                        Next_stInit2<=SeekMain2;
555                                                        End if;                         
556                When SeekMain2 => 
557                                                        If DS_RDY='1' then  -- Si un jeu de données a été reçu
558                                                                                if (Datareceived(0)(7 downto 4) = INIT_SETRANK) then 
559                                                                                                MainResp<='1';
560                                                                                                Next_stInit2 <=StoreMain; -- de la librairie pricipale
561                                                                         else
562                                                                                                MainResp<='0';
563                                                                                                Timeout_i<=0;
564                                                                         end if;       
565                                                                               
566                                                        elsif (ExecTime_Out='1') then 
567                                                                       
568                                                                                                -- le Noc ne répond pas
569                                                                                                -- affecter un numéro en raport avec le port
570                                                                                Next_stInit2 <=SeekMain2;
571                                                        elsif TimeOut=150 then
572                                                                                                --essayer de redemander l'initialisation
573                                                                        Timeout_i<=0;                   
574                                                                        Next_stInit2 <=SeekMain2;
575                                                        else
576                                                                                Timeout_i<=TimeOut+1;
577                                                        End if;
578                                                       
579                                                         
580                                                         
581                When StoreMain =>
582                                if DataReceived(0)(7 downto 4)= MPI_INIT then
583                                --ignorer le message
584                                Next_stInit2 <=StoreMain; --essayer de recevoir le rang
585                                elsif Datareceived(0)(7 downto 4) = INIT_SEEKMAIN then 
586                                -- ignorer ce message
587                                Next_stInit2 <=StoreMain; --essayer de recevoir le rang
588                                elsif Datareceived(0)(7 downto 4) = INIT_SETRANK then --ok le rang a été reçu
589                                -- enregistrer le Main Adresse et les adresses des autres processus
590                                -- dans la variable prévue à cet effet
591                                --if dma_wr_grant='1' then
592                                        Next_stInit2 <=StoreRank;
593                                --end if;
594                               
595                                end if;
596                                       
597                When StoreRank =>
598                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
599                                        -- la donnée ...
600                                        if dma_wr_grant = '1' then 
601                                                if clk_cyl=2 then --prévoir deux cycle d'horloge pour lire en RAM
602                                                        Next_stInit2 <=GetPeerStat;
603                                                        TimeOut_i<=0;
604                                                        clk_cyl_i<=0;
605                                                else 
606                                                        clk_cyl_i<=clk_cyl+1;
607                                                end if;
608                                        else
609                                                        Next_stInit2 <=StoreRank;
610                                                        TimeOut_i<=0;
611                                                        clk_cyl_i<=0;
612                                        end if;
613                                       
614                When GetPeerStat => 
615                                                        If DS_RDY='1' then  -- Si un jeu de données a été reçu
616                                                                         if (Datareceived(0) = INIT_REGISTER & MainPort ) then 
617                                                                                                MainResp<='1';
618                                                                                                Next_stInit2 <=SendApp; -- de la librairie pricipale
619                                                                         else
620                                                                                                MainResp<='0';
621                                                                                                Timeout_i<=0;
622                                                                         end if;       
623                                                                               
624                                                        elsif (ExecTime_Out='1') then 
625                                                                       
626                                                               
627                                                                                Next_stInit2 <=EndInit;
628                                                        elsif TimeOut=180 then
629                                                                                                --essayer de redemander l'initialisation
630                                                                                               
631                                                                        Next_stInit2 <=SeekMain1;
632                                                        else
633                                                                                Timeout_i<=TimeOut+1;
634                                                        End if;                 
635                When SetMainFlag =>
636                                if dma_wr_grant='1' then   
637                                                TimeOut_i<=0;
638                                                Next_stInit2 <=ReadNoc;
639                                        elsif Timeout=200 then
640                                                Next_stInit2 <=SendApp;
641                                        else
642                                                TimeOut_i<=TimeOut+1;
643--                                      end if; -- il est envisagée de terminer le programme à ce point
644                                end if;
645                when ReadNoc => if DS_RDY='1' then
646                                                                        Next_stInit2 <=GetMainReq;
647                                                                        Timeout_i<=0;
648                                                                elsif Timeout=80 then
649                                                                        Timeout_i<=0;
650                                                                        Next_stInit2 <=SendPeerStat;
651                                                                else
652                                                                        TimeOut_i<=TimeOut+1;
653                                                                end if; 
654                               
655                When GetMainReq => if RankAsked='1' and PeerStat(PeerPort)='0' then
656                                                                        Next_stInit2 <=NewRank; -- un nouveau rang est demandé
657                                                                else
658                                                                        Next_stInit2 <=ReadNoC; -- sinon essayer encore de lire un jeu de données.
659                                                                end if;
660                When NewRank =>
661                                Next_stInit2 <=SendRank;
662                When SendRank =>
663                                        if Send_RDY='1' then  --RankSent
664                                                Next_stInit2 <=RegRank;
665                                                RankSent_i<='1';  -- le rang a été envoyé
666                                                TimeOut_i<=0;   -- prépare le traitement de la prochaine requête
667                                                                                                -- d'attente des ports
668                                        end if;
669                When RegRank =>
670                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
671                                        -- la donnée ...
672                                        if dma_wr_grant = '1' then 
673--                                                      if DS_RDY='1' then
674                                                                RankSent_i<='0';
675                                                                if DS_RDY='0' then
676                                                                        Next_stInit2 <=ReadNoc;
677                                                                end if;
678                                                        elsif Timeout=150 then
679                                                                Next_stInit2 <=SendApp;
680                                                        else
681                                                                TimeOut_i<=TimeOut+1;
682--                                                      end if; -- il est envisagée
683                                        end if;
684                When SendPeerStat =>
685                                       
686                                        if cpt<=(unsigned(NoCMax)) then
687                                        if peerRts='0' then -- pas encore envoyer les données alors les préparer
688                                                PortStat<=std_logic_vector(to_unsigned(cpt,4));--Port à contacter
689                                                vPortStat:=std_logic_vector(to_unsigned(cpt,4));
690                                                if (PeerStat(cpt)='1') and not(vPortStat=MyPort) then
691                                                        PeerRts<='1';
692                                                       
693                                                end if;
694                                                        cpt_peer<=cpt+1;
695                                                        TimeOut_i<=0;
696                                        else
697                                                        if Send_RDY='1' then  --RankSent
698                                                                                --Next_stInit2 <= RegRank;
699                                                                                RankSent_i<='1';        -- les stat ont été envoyé
700                                                                                TimeOut_i<=0;           -- prépare le traitement de la prochaine requête
701                                                                                PeerRts<='0';                                                                           -- d'attente des ports
702                                                          elsif TimeOut_i=100 then
703                                                                        Next_stInit2 <=EndInit ;-- impossible d'envoyer sur le NoC
704                                                          else
705                                                                        TimeOut_i<=TimeOut_i+1; 
706                                                        end if;
707                                        end if;
708                                        elsif PeerRTS='1' then -- le dernier port est il activé ?
709                                                if Send_RDY='1' then  --RankSent
710                                                                RankSent_i<='1';        -- les stat ont été envoyé
711                                                                                TimeOut_i<=0;           -- prépare le traitement de la prochaine requête
712                                                                                PeerRts<='0';
713                                                                Next_stInit2<=SendApp;
714                                               
715                                                elsif TimeOut_i=100 then
716                                                        Next_stInit2 <=EndInit;
717                                                else 
718                                                        TimeOut_i<=TimeOut_i+1; 
719                                                end if;
720                                        else
721                                                Next_stInit2<=SendApp;
722                                        end if;
723                When SendApp =>  -- envoyer au programme un signal
724                                        -- et attendre un acquittement et l'adresse de base
725                                        If AppAck='1' then
726                                                Next_stInit2 <=EndInit;
727                                        end if;
728               
729               
730                When EndInit=>
731                 
732                       
733                        Next_stInit2<=Init;
734      end case;     
735   end process;
736       
737--================================================
738--sauvegarde du rang et du main port à l'adresse de retour de la fonction Init
739--==================================================
740
741--====================================================
742--envoie des données sur le port
743--===================================================
744selector<=(Rcv_on,Cmd_on,Snd_on);
745
746process (selector,Rport_out_rd_en,cport_out_rd_en,sPort_in_wr_en ,cPort_in_wr_en,
747                                tosend ,tosend4)
748begin
749   case selector is
750       
751      when "000" => port_in_data<=(others=>'Z');
752                                                Port_in_wr_en<='0';
753                                                Port_out_rd_en<='0';
754     
755                when "001" => port_in_data<=tosend; --envoie de données
756                                                Port_in_wr_en<=sPort_in_wr_en ;
757                                                Port_out_rd_en<='0';
758      when "101" => port_in_data<=tosend; --envoie de données
759                                                Port_in_wr_en<=sPort_in_wr_en ;
760                                                Port_out_rd_en<=Rport_out_rd_en ;
761                when "010" | "110" | "011" | "111" => 
762                                                port_in_data<=tosend4; --envoie de commande GetPort
763                                                Port_in_wr_en<=cPort_in_wr_en;
764                                                Port_out_rd_en<=cport_out_rd_en;
765     
766          when "100" => port_in_data<=(others=>'Z'); -- réception de données
767                                                Port_in_wr_en<='0';
768                                                Port_out_rd_en<=Rport_out_rd_en ;
769     
770                when others => port_in_data<=(others=>'Z');
771                                                        Port_in_wr_en<='0';                                                     
772                                                        Port_out_rd_en<='0';
773   end case;
774end process;
775 
776--==================================================   
777       
778        --===============================================================
779        --processus d'accès au réseau
780        --===============================================================
781
782
783
784
785
786        preceiv:process(clk,reset)
787       
788        variable origport,destport : natural range 0 to 15;
789        variable dcount,dlen ,rtimeout:natural range 0 to 255;
790        variable ptype : std_logic_vector(3 downto 0);
791        variable bad_paquet :std_logic:='0';
792        begin
793--                             
794        if  rising_edge(clk) then 
795        if reset='1' then
796                etrec<=r_wait;
797                destport:=1;
798                rtimeout:=0;
799                bad_paquet:='0';
800        else
801                        case  etrec is
802                        when r_wait =>
803                               
804                                rtimeout:=0;
805                                bad_paquet:='0';       
806                        if Port_out_data_available='1' and CTR='1'  then 
807                                ptype:=port_out_data(7 downto 4);
808                                origport:=to_integer(unsigned(port_out_data(3 downto 0)));
809                               
810                                if ptype=MPI_INIT or ptype=INIT_SETRANK or ptype=INIT_SEEKMAIN or ptype=INIT_REGISTER then 
811                                                etrec<=r_dlen; --identification de la signature d'en tête valide
812                                                Datareceived(0)<=Port_out_data; --stocker l'entête
813                                                bad_paquet:='0';
814                                else
815                                        --une donnée non attendue est présente sur le port
816                                        etrec<=r_dlen;
817                                        dcount:=1;
818                                        bad_paquet:='1';
819                                        Datareceived(0)<=(others=>'0');
820                                end if;
821                        --elsif Port_out_data_available='1' and CTR='0' then
822                        --              etrec<=r_drop;
823                        else
824                               
825                                etrec<=r_wait;
826                        end if;
827                        DS_RDY<='0';
828                        When r_drop => -- ignorer les messages qui arrivent à ce noeud tant que
829                                                                --l'application n'a pas été initialisée
830                                                if port_out_data_available='0' then 
831                                                        etrec<=r_end;
832                                                        dcount:=0;
833                                                       
834                                                end if;
835                                               
836                                               
837                                               
838                                                --Rport_out_rd_en<='1'; --lire les données qui sont dans le tampon de sortie           
839                                                DS_RDY<='0';
840                        when r_Dlen =>   --positionnement du mot de longueur des données
841                        if Port_out_data_available ='1' then 
842                       
843                        --Rport_out_rd_en<='1';
844                        etrec<=r_glen;
845                        rtimeout:=0;
846                        else
847                                rtimeout:=rtimeout+1;
848                                        if rtimeout>=30 then 
849                                        Exectime_out<='1';  --read Noc time out
850                                                etrec<=r_end;             -- données pas prêtes
851                                        end if;
852                       
853                       
854                        end if;
855                        DS_RDY<='0';
856                        -- 
857                        when r_glen =>   --lecture effective de la longueur des données
858                        if port_out_data_available='1' then 
859                        dlen:=to_integer(unsigned(port_out_data(Word-1 downto 0)));
860                        Datareceived(1)<=Port_out_data;
861                        --RPort_out_rd_en<='0';
862                        etrec<=r_data;
863                        dcount:=2;  -- initialisation du compteur de reception (il y a
864                                                        -- déjà deux mots reçues
865                        else
866                                rtimeout:=rtimeout+1;
867                                        if rtimeout>=30 then 
868                                        ExecTime_out<='1';
869                                                etrec<=r_end;             -- données pas prêtes
870                                        end if;
871                       
872                        end if;
873                        DS_RDY<='0';
874                        when r_data =>                                          -- lecture des données
875                        if port_out_data_available='1'  then 
876                                       
877                                        --Rport_out_rd_en<='1';   --autoriser la lecture
878                                        if bad_paquet='0' then
879                                                DataReceived(dcount)<=Port_out_data; --récupération des données
880                                        else
881                                                DataReceived(2)<=(others=>'0');
882                                          --ignorer ces données
883                                        end if;
884                                        --assert true report "Donnée lue :"; --& string(unsigned(port4_out(Word-1 downto 0)))
885                                        DS_RDY<='0';
886                                        dcount:=dcount+1;
887                                        --severity note;
888                                        if dlen <=dcount then -- ce doit être égale ici et non <= ???
889                                                etrec<=r_end;
890                                                DS_RDY<='1'; -- jeu de données disponibles
891                                        elsif dcount=255 then   --dépassement de la capacité
892                                                DS_RDY<='0';
893                                                etrec<=r_end;
894                                        end if;
895                        else
896                                        rtimeout:=rtimeout+1;
897                                        if rtimeout>=30 then 
898                                           ExecTime_out<='1';
899                                                etrec<=r_end;             -- données pas prêtes
900                                        end if;
901                                        DS_RDY<='0';
902                                       
903                        end if;
904                        when r_pulse =>
905                                        etrec<=r_end; 
906                                        DS_RDY<='1';
907                        when r_end =>
908                                               
909                        --rPort_out_rd_en <='0';
910                       
911                        if DS_ACK='1' or rtimeout> 30 or CTR='0' or bad_paquet='1' then 
912                                DS_RDY<='0';
913                                etrec<=r_wait;
914                        else
915                                DS_RDY<=DS_RDY;
916                        end if;
917                       
918                       
919                       
920                        end case;
921                 end if;--reset='1'
922                end if;   
923  end process preceiv;
924 
925 val_preceiv: process (etrec)
926  begin
927  case etrec is
928                                        when r_wait  =>
929--                                              DS_RDY<='0';
930                                               
931                                                Rport_out_rd_en <='0';
932                                        when r_dlen  =>
933--                                                      DS_RDY<='0';
934                                                        Rport_out_rd_en <='1';
935                                                        rcv_On<='1';
936                                        when r_drop  =>
937--                                                      DS_RDY<='0';
938                                                        Rport_out_rd_en <='1';
939                                                        rcv_On<='1';
940                                        when r_glen =>
941                                                        Rport_out_rd_en <='1';
942--                                                      DS_RDY<='0';
943                                                        rcv_On<='1';
944                                        when r_data =>
945                                                        Rport_out_rd_en <='1';
946--                                                      DS_RDY<='0';
947                                                        rcv_On<='1';
948                                        when r_pulse =>
949                                                                Rport_out_rd_en <='0';
950                                                                rcv_On<='1';
951--                                                              DS_RDY<='1';
952                                        when r_end =>
953                                                        Rport_out_rd_en <='0';
954--                                                      DS_RDY<='0';
955                                                        rcv_On<='0';
956                                        when others =>
957                                                        Rport_out_rd_en <='0';
958--                                                      DS_RDY<='0';
959                                                        rcv_On<='0';
960                                end case;
961        end process;
962 
963  psend:process(clk,reset)
964                --génération des paquets à partir du  port courant
965                variable pactype :natural range 0 to 15;
966                variable destport : natural range 0 to 15:=0;
967                variable realdlen, i,i_pair : natural range 0 to 255;
968                variable MaxPort : natural :=to_integer(unsigned(NOCMAX)); -- en fait ne doit pas être 0
969               
970               
971                                begin
972                                if rising_edge(clk) then 
973                                                 if reset='1' then 
974                                                                etsnd<=s_init;
975                                 
976                                   
977                                                 
978                                                else -- le process s'exécute sur chaque front
979                                                                                                                        -- montant de l'horloge
980                                                case etsnd is
981                                                when s_init => tosend<=(others=>'Z');
982                                                                                        MaxPort :=to_integer(unsigned(NOCMAX));
983                                                                sPort_in_wr_en<='0';
984                                                        if port_in_full='0' and Rts_dat='1' then   --on peut aussi tester si le port est vide
985                                                                BCast_RDY<='0';  -- pas la fin de du Broadcasting
986                                                                          Send_RDY<='0';
987                                                                          Snd_on<='1';
988                                                                          if Bcast='1' then -- envoyer à tous les ports le même message ?
989                                                                          DestPort :=0;
990                                                                          else
991                                                                                DestPort:=to_integer(unsigned(DataToSend(0)(3 downto 0)));
992                                                                          end if;
993                                                                          etsnd<=s_head;
994                                                        end if;
995                                                when s_head  =>    -- construction et envoie de l'en-tête
996                                                Send_RDY<='0'; --l'envoi commence
997                                                BCast_RDY<='0';
998                                                Snd_on<='1';
999                                                --pactype:=to_integer(MPI_INIT);--
1000                                                pactype:=to_integer(unsigned(DataToSend(0)(7 downto 4)));
1001                                                --realdlen:=to_integer(unsigned(Datalen));
1002                                                --? destport:=MAXPORT; -- le port de destination
1003                                               
1004                                                tosend <=STD_LOGIC_VECTOR(to_unsigned(pactype,4)) & STD_LOGIC_VECTOR(to_unsigned(destport,4));
1005                                                 sPort_in_wr_en<='1';   --
1006                                                 
1007                                                 i:=1;
1008                                                 etsnd<=s_len2;  -- passer à l'état suivant
1009                                                 
1010                                                when s_len => 
1011                                                        BCast_RDY<='0';
1012                                                        Send_RDY<='0';
1013                                                        Snd_on<='1';
1014                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(Realdlen,8)));
1015                                                        tosend<=DataToSend(1);
1016                                                        sPort_in_wr_en <='1';
1017                                                       
1018
1019                                                        --port1_in<=tosend1; --copie directe sur le port
1020                                                        etsnd<=s_len2;
1021                                                when s_len2 => 
1022                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(realdlen,8)));
1023                                                        sPort_in_wr_en<='1';
1024                                                        tosend<=DataToSend(1);
1025
1026                                                        --port1_in<=tosend1; --copie directe sur le port
1027                                                        etsnd<=s_data; 
1028                                                        BCast_RDY<='0';
1029                                                        Send_RDY<='0';
1030                                                        Snd_on<='1';
1031                                                        i:=i+1;
1032                                                when s_data =>
1033                                                        Snd_on<='1';
1034                                                        if Port_in_full='0'and RTS_dat='1' then
1035                                                                sPort_in_wr_en<='1';
1036                                                               
1037                                                                     --envoie des données sur le port   
1038                                                                        tosend<=DataToSend(i);
1039                                                               
1040                                                               
1041                                                                if i+1>=datalen then 
1042                                                                        etsnd<=s_end;
1043                                                                        Send_RDY<='1'; --l'envoi est terminé
1044                                                                        if BCast='1' and destport=MAXPort then
1045                                                                                BCAST_RDY<='1'; --l'envoi collectif aussi
1046                                                                        else 
1047                                                                                BCast_RDY<='0';
1048                                                       
1049                                                                        end if;
1050                                                                else
1051                                                                        BCast_RDY<='0';
1052                                                                        Send_RDY<='0';
1053                                                                        i:=i+1;
1054                                                                end if;
1055                                                        else
1056                                                                sPort_in_wr_en<='0';
1057                                                                BCast_RDY<='0';
1058                                                                Send_RDY<='0';
1059                                                        end if;
1060                                                when s_end  =>
1061                                                 tosend<=(others=>'Z');
1062                                                       
1063                                                        sPort_in_wr_en<='0';
1064                                                        Snd_on<='0';
1065                                                        if Bcast='1' then
1066                                                                DestPort:=Destport+1;
1067                                                                if DestPort<=MaxPort then
1068                                                                etsnd<=s_head;
1069                                                                else
1070                                                                BCast_RDY<='1' ; -- BroadCast End=Ok
1071                                                                        if Send_ack='1' then
1072                                                                                etsnd<=s_init;
1073                                                                                Send_RDY<='0';
1074                                                                        end if;
1075                                                                end if;
1076                                                        else
1077                                                                BCast_RDY<='0';
1078                                                                if Send_ack='1' then
1079                                                                        etsnd<=s_init;
1080                                                                        Send_RDY<='0';
1081                                                                end if;
1082                                                               
1083                                                        end if;
1084                                                end case;       
1085                                               
1086                                                                               
1087                                                end if;  --reset ='1'
1088                                        end if; --rising_edge...
1089                end process psend;     
1090
1091-- envoi des commandes         
1092pcmd:process(clk,reset)
1093       
1094        variable origport,destport,pid,mport : natural range 0 to 15;
1095        variable ctimeout:natural range 0 to 255;
1096        begin
1097       
1098        if  rising_edge(clk) then
1099                if reset='1' then
1100                        etcmd<=cmdstart;
1101                        destport:=0;
1102                        ctimeout:=0;
1103                        origport:=1;
1104        --              sorigport<=origport;
1105                else
1106                                        case  etcmd is
1107                                        when cmdstart =>
1108                                                if Port_in_empty='1' and RTS_Cmd='1' then 
1109                                                                        etcmd<=cmdpost;
1110                                               
1111                                                end if;
1112                                 when cmdpost =>
1113                                        if Port_in_empty='1' then 
1114                                                etcmd<=cmdread;
1115                                        end if;
1116                                       
1117                                when cmdpostidle  =>   --permet juste la prise en compte de la commande
1118                                                etcmd<=cmdread;
1119                                                dcount<=0;-- initialisation du compteur de reception
1120                                 when cmdread =>
1121                                               
1122                                               
1123                                                ctimeout:=0;
1124                                               
1125                                        if Port_out_data_available='1' then 
1126                                                mport:=to_integer(unsigned(port_out_data(7 downto 4)));
1127                                                pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
1128                                                CmdReceived(dcount)<=port_out_data;
1129                                                --cdata_out_en(origport)<='1';
1130--                                              if pid=origport then --le port a été bien identifié
1131                                                                etcmd<=cmdglen; --
1132                                                                dcount<=dcount+1;
1133--                                                      else
1134--                                                      etcmd<=cmdtimeout;
1135--                                              end if;
1136                                        else
1137
1138                                                etcmd<=cmdread;
1139                                        end if;
1140                                       
1141                                       
1142                                        when cmdlen =>   --positionnement du mot de longueur des données
1143                                        if Port_out_data_available='1' then 
1144                                       
1145                                        etcmd<=cmdglen;
1146                                        ctimeout:=0;
1147                                        else
1148                                                ctimeout:=ctimeout+1;
1149                                                        if ctimeout>=30 then 
1150                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1151                                                        end if;
1152                                       
1153                                       
1154                                        end if;
1155                                        when cmdglen =>   --lecture effective de la longueur des données
1156                                        if Port_out_data_available='1' then 
1157                                                cdlen<=to_integer(unsigned(port_out_data(Word-1 downto 0)));
1158                                                CmdReceived(dcount)<=port_out_data;
1159                                                etcmd<=cmddata;
1160                                          dcount<=dcount+1;
1161                                        else
1162                                                ctimeout:=ctimeout+1;
1163                                                        if ctimeout>=30 then 
1164                                                        --time_out(destport)<='1';
1165                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1166                                                        end if;
1167                                       
1168                                        end if;
1169                                       
1170                                        when cmddata =>
1171                                        if (port_out_data_available='1' and ctimeout<30) then 
1172                                                       
1173                                                        --cdata_out_en(origport)<='1';
1174                                                        mport:=to_integer(unsigned(port_out_data(7 downto 4)));
1175                                                        --attention les ports sont numérotés à partir de 0
1176                                                        pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
1177                                                        CmdReceived(dcount)<=port_out_data;
1178                                                        if (dcount>=cdlen-1 ) then--attention le compteur de données commence à 0
1179                                                                etcmd<=cmdend;
1180                                                                --CM_RDY<='1';
1181                                                        else
1182                                                                dcount<=dcount+1;
1183                                                        end if;                 
1184                                        Else
1185                                                       
1186                                                        if ctimeout>=30 then 
1187                                                                --time_out(destport)<='1';
1188                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1189                                                        else
1190                                                        ctimeout:=ctimeout+1;
1191                                                        etcmd<=cmdend;
1192                                                        end if;
1193                                        end if;
1194                                        when cmdend =>
1195                               
1196                                                        etcmd<=cmdstart;
1197
1198                                        when cmdtimeout =>
1199
1200                                          etcmd<=cmdstart;
1201                                        end case;
1202                --sorigport<=origport; 
1203                end if;   --reset='1'
1204        end if;
1205  end process pcmd;     
1206
1207majetcmd: process (etcmd,DataToSend, port_out_data_available, dcount,port_out_data)
1208variable origport : natural;
1209variable i:natural:=0;
1210        begin
1211                        case  etcmd is
1212                when cmdstart =>
1213                                i:=0;
1214                                Port_in_cmd_en<='0';
1215                                tosend4<=(others=>'Z');
1216                                cport_out_rd_en<='0';
1217                                cport_in_wr_en<='0';
1218                                CM_RDY<='0';
1219                                Cmd_on<='0';
1220                 when cmdpost | cmdpostidle =>
1221                                cport_in_wr_en<='1';
1222                                tosend4<=DataToSend(0); ---code pour getportid
1223                                Port_in_cmd_en<='1';
1224                                cport_out_rd_en<='0';
1225                                CM_RDY<='0';
1226                                Cmd_on<='1';
1227                 when cmdread =>
1228                                tosend4<=(others=>'Z');
1229                                cPort_in_wr_en<='0';
1230                                cport_out_rd_en<=port_out_data_available;
1231                                --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1232                                Port_in_cmd_en<='1';
1233                                CM_RDY<='0';
1234                                Cmd_on<='1';
1235                when cmdlen |cmdglen =>   --positionnement du mot de longueur des données
1236                                        tosend4<=(others=>'Z');
1237                                        cport_in_wr_en<='0';
1238                                        cport_out_rd_en<=port_out_data_available;
1239                                        Port_in_cmd_en<='1';
1240                                        --CmdReceived(dcount)<= port_out_data;
1241                                        CM_RDY<='0';
1242                                        Cmd_on<='1';
1243                when cmddata =>
1244                                        tosend4<=(others=>'Z');
1245                                        cport_in_wr_en<='0';
1246                                        cport_out_rd_en<=Port_out_data_available;
1247                                        Port_in_cmd_en<='1';
1248                                        --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1249                                        i:=i+1;
1250                                        CM_RDY<='0';
1251                                        Cmd_on<='1';
1252                        when cmdend =>
1253                                        tosend4<=(others=>'Z');
1254                                cport_in_wr_en<='0';
1255                                cport_out_rd_en<='0';
1256                                --CmdReceived(dcount)<=port_out_data;
1257                                Port_in_cmd_en<='0';
1258                            CM_RDY<='1';
1259                                 Cmd_on<='0';
1260                        when cmdtimeout =>
1261                                        tosend4<=(others=>'Z');
1262                                  cport_in_wr_en<='0';
1263                                  cport_out_rd_en<='0';
1264                                  Port_in_cmd_en<='0';
1265                                        Cmd_on<='1';                             
1266                        end case;
1267               
1268end process majetcmd ; 
1269end Behavioral;
1270
Note: See TracBrowser for help on using the repository browser.