source: PROJECT_CORE_MPI/CORE_MPI/TRUNK/EX4_FSM.vhd @ 15

Last change on this file since 15 was 15, checked in by rolagamo, 12 years ago
File size: 32.8 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,GetMainReq,StoreRank,NewRank,SendRank,RegRank,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 selector : std_logic_vector (2 downto 0); -- pour le MUX des signaux vers le port
93        --signaux pour les états des MAE
94        signal  NocSizeOk,PortCountFlag : std_logic;
95        signal PortNumFlag,EquFlag,MainResp,RankAsked,RankSent:std_logic;
96       
97   signal RTS_cmd,RTS_dat,CTR,BCast,Send_Ack,DS_Ack,CM_Ack:std_logic:='0';
98        signal Rcv_On,Snd_On,Cmd_On : std_logic:='0'; --status des MAE d'envoie et de réception
99        signal DS_RDY ,BCast_Rdy,Send_RDY,CM_RDY:std_logic:='0';
100        signal ExecTime_out:std_logic;
101        --signaux de gestion de la RAM
102        signal Ram_NextAdress : std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
103        signal Ram_NExtAdress_i :std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
104        --Signaux des résultats et de l'état
105   signal PortNum_i,MyPort : std_logic_vector(3 downto 0);  --
106        signal NocMax : std_logic_vector(3 downto 0); -- Nombre de ports du réseau -1 ?
107        signal MyRank : std_logic_vector(3 downto 0) ; --rang du PE
108        signal MainPort : std_logic_vector(3 downto 0) ; --Port de la lib main
109        signal NextRank : std_logic_vector(3 downto 0):=(others=>'0'); --utiliser pour gérer les affectations de rangs MPI
110   signal DataToSend : Typ_PortIo(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0')); -- permet d'empiler les données à envoyer
111        signal CmdReceived,DataReceived : Typ_PortIO(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0'));
112        signal Datalen : natural range 0 to 3 :=0; --indique la longueur des données
113        --other outputs
114        signal RankAsked_i,EquFlag_i,MainResp_i,RankSent_i,IsMain_i,Result_i:std_logic;
115   --signal BCast_Rdy_i : std_logic;
116        signal cdlen,dcount,timeout,timeout_i : natural range 0 to 255:=0; --longueur du paquet reçu par le process pcmd
117begin
118--=======================================================================================
119--fonctions du module
120--=======================================================================================
121--=======================================================================================
122 
123 
124 
125   -- Gestion de l'initialisation du Core MPI
126  sync_Init2 : process (clk,reset)
127  begin
128        if reset='1' then
129                stinit2<=init;
130        elsif rising_edge(clk) then
131                stinit2<=next_stinit2;
132                --ajout des autres affectations ici
133                Ram_NextAdress<=Ram_NextAdress_i  ;
134                MyPort<=PortNum_i;
135                RankAsked<=RankAsked_i;
136                RankSent<=RankSent_i;
137                AppRank<=MyRank;
138                timeout<=timeout_i;
139               
140        end if;
141end process;
142
143  Init2_DECODE: process (stinit2, CmdReceived, EquFlag, MyPort, DS_RDY, MainResp, DataReceived, Ram_NextAdress)
144   variable nextr,nextadr : natural :=to_integer(unsigned(Ram_NextAdress));
145        begin
146     
147      Case stInit2 is
148                When Init =>
149                        RTS_cmd<='0';
150                        RTS_dat<='0';
151                        BCast<='0';
152                        Result_En<='0';
153                        Initialized<='0';
154                        CM_Ack <='0';
155                        CTR<='0' ;
156                        DS_ACK<='0';
157                        Send_Ack<='0';
158                        WeRam<='0';
159                        ResultOut<=(others=>'0');
160                        PortNum_i<=(others=>'Z');
161                        IsMain<='0';
162                        EquFlag<='0';
163                        RankAsked_i<='0';
164                        dma_wr_req<='0';
165                When GetPortNum =>
166                        RTS_cmd<='1';
167                        RTS_dat<='0';
168                        Result_En<='0';
169                        Initialized<='0';
170                        BCast<='0';   --réalise un envoie non collectif
171                        CM_Ack<='0';   -- les données sont maintenant attendues
172                        CTR<='0' ;
173                        DataToSend(0)<=X"0" & GETPORTID;
174                        DS_ACK<='0';
175                        Send_Ack<='0';
176                        WeRam<='0';
177                        IsMain<='0';
178                        ResultOut<=(others=>'0');
179                        PortNum_i<=(others=>'Z');
180                        RankAsked_i<='0';
181                        dma_wr_req<='0';
182                When DecodeData =>
183                        EquFlag<=(All_zeros(Cmdreceived(2)(3 downto 0)));
184                        RTS_cmd<='0';
185                        RTS_dat<='0';
186                        BCast<='0';
187                        IsMain<='0';
188                        Result_En<='0';
189                        Initialized<='0';
190                        CM_Ack <='1'; --les données ont été reçues
191                        PortNum_i<=Cmdreceived(2)(3 downto 0); --récupère les valeurs de port
192                        NocMax<=Cmdreceived(2)(7 downto 4);  -- et la taille du réseau
193                        PortNumFlag<='1';  -- le numéro du port est maintenant connu
194                        CTR<='0' ;
195                        DS_ACK<='0';
196                        Send_Ack<='0';
197                        WeRam<='0';
198                        RankAsked_i<='0';
199                        ResultOut<=(others=>'0');
200                        dma_wr_req<='0';
201                When IsPortZero => --Ce port est-il le n° 0 du NoC ?
202                        BCast<='0';
203                        Result_En<='0';
204                        Initialized<='0';
205                        RTS_cmd<='0';
206                        RTS_dat<='0';
207                        NextRank<="0001"; -- le prochain rang à affecter sera le n° 1
208                        nextr:=1;
209                        IsMain<=EquFlag;
210                        MyRank<="0000";
211                        MainPort<="0000";
212                        --MainAdr<="0000";   -- le port 0 est le main Lib par défaut;
213                        CTR<='0' ;
214                        DS_ACK<='0';
215                        WeRam<='0';
216                        RankAsked_i<='0';
217                        ResultOut<=(others=>'0');
218                        dma_wr_req<='0';
219                When SeekMain1 =>    -- recherche de la lib main
220                                RTS_cmd<='0';
221                                RTS_DAT<='1';
222                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
223                                DS_ACK<='0'; --les données sont attendus
224                                Send_Ack<=BCast_rdy;
225                                DataToSend(0)<=INIT_SEEKMAIN & MyPort ;
226                                DataToSend(1)<="00000011"; -- la longueur du packet =3
227                                DataToSend(2)<="0000" & MyPort; --propose sa propre adresse
228                                DataLen<=3;
229                                BCast<='1';
230                                IsMain<='0';
231                                Result_En<='0';
232                                Initialized<='0';
233                                WeRam<='0';
234                                ResultOut<=(others=>'0');
235                                EquFlag<='0';
236                                RankAsked_i<='0';
237                                dma_wr_req<='0';
238                When SeekMain2 =>    -- recherche de la lib main
239                                RTS_cmd<='0';
240                                RTS_DAT<='0';
241                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
242                                DS_ACK<='0'; --les données sont attendus
243                                Send_Ack<=BCast_rdy;
244--                              DataToSend(0)<=INIT_SEEKMAIN & MyPort ;
245--                              DataToSend(1)<="00000011"; -- la longueur du packet =3
246--                              DataToSend(2)<="0000" & MyPort; --propose sa propre adresse
247--                              DataLen<=3;
248                                BCast<='0';
249                                IsMain<='0';
250                                Result_En<='0';
251                                Initialized<='0';
252                                WeRam<='0';
253                                ResultOut<=(others=>'0');
254                                EquFlag<='0';
255                                RankAsked_i<='0';
256                                dma_wr_req<='0';
257                When StoreMain =>     -- la Main Lib est une autre
258                                BCAST<='0';
259                                Result_En<='0';
260                                IsMain<='0';
261                                Initialized<='0';
262                                DS_ACK<=DS_RDY;
263                                Send_Ack<='0';
264                                RTS_cmd<='0';
265                                RTS_DAT<='0';
266                                CTR<=not(MainResp);  -- essayer de recevoir tant que le main n'a pas répondu
267                                WeRam<='1';
268                                ResultOut<=(others=>'0');
269                                RankAsked_i<='0';
270                                EquFlag<='0';
271                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
272                                DataRam<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
273                                dma_wr_req<= '0';  ---pas très sûr
274                When SetMainFlag =>   -- Cette Lib est la Main Lib
275                                if (Datareceived(0)(7 downto 4) = INIT_SEEKMAIN) then 
276                                        RankAsked_i<='1';
277                                else 
278                                        RankAsked_i<='0';
279                                end if;
280                                RTS_cmd<='0';
281                                Initialized<='0';
282                      RTS_DAT<='0';
283                                BCast<='0';
284                                IsMain<='0';
285                                Result_En<='0';
286                                MyRank<="0000";
287                                MainPort<="0000";
288                                CTR<='1';
289                                DS_ACK<='0';
290                                WeRam<='1';
291                                ResultOut<=(others=>'0');
292                                EquFlag<='1';
293                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
294                                DataRam<=(others =>'0');  -- le port vaut 0 et la mainlib est aussi à 0
295                                dma_wr_req<='1';
296                When GetMainReq  =>
297                                RankAsked_i<='1';
298                                WeRam<='0';  -- pas
299                                BCast<='0';
300                                DS_ACK<='0';
301                                IsMain<='0';
302                                Result_En<='0';
303                                Initialized<='0';
304                                RTS_cmd<='0';
305                                RTS_DAT<='0';
306                                CTR<='1';
307                                ResultOut<=(others=>'0');
308                                PortNum_i<=DataReceived(0)(3 downto 0); -- le port qui demande un rang;
309                                EquFlag<='1';
310                                dma_wr_req<='0';
311                When NewRank =>
312                                nextr:=nextr+1;
313                                NextAdr:=NextAdr+1;
314                                --NextRank<=incr_vec(NextRank,'1');
315                                NextRank<=STD_logic_vector(to_unsigned(nextr,4));
316                                DataToSend(0)<=INIT_SETRANK & PortNum_i ;
317                                DataToSend(1)<="00000011";
318                                DataToSend(2)<="0000" & NextRank;  --ici c'est la valeur avant incrémentation !
319                                DataLen<=3;
320                                BCast<='0';
321                                DS_ACK<='0';
322                                Result_En<='0';
323                                Initialized<='0';
324                                EquFlag<='1';
325                                RTS_cmd<='0';
326                                Rts_DAT<='1';
327                                IsMain<='0';
328                                CTR<='0' ;
329                                WeRam<='0';
330                                RankAsked_i<='1';
331                                ResultOut<=(others=>'0');
332                                dma_wr_req<='0';
333                When SendRank =>
334                                BCast<='0';
335                                Result_En<='0';
336                                EquFlag<='1';
337                                Rts_DAT<='1';
338                                RTS_cmd<='0';
339                                DS_ACK<='0';
340                                Send_Ack<=Send_Rdy;
341                                IsMain<='0';
342                                CTR<='0' ;
343                                WeRam<='0';
344                                ResultOut<=(others=>'0');
345                                RankAsked_i<='1';
346                                Initialized<='0';
347                                dma_wr_req<='0';
348                When RegRank =>
349                                if (Datareceived(0)(7 downto 4) = INIT_SEEKMAIN) then 
350                                        RankAsked_i<='1';
351                                else 
352                                        RankAsked_i<='0';
353                                end if;
354                                CTR<='0' ;
355                                Result_En<='0';
356                                Initialized<='0';
357                                RTS_cmd<='0';
358                                DS_ACK<='0';
359                                Send_Ack<='0';
360                                IsMain<='0';
361                                Rts_Dat<='0';
362                                BCast<='0';
363                                EquFlag<='1';
364                                WeRam<='1';
365                               
366                                Ram_NextAdress_i<= STD_logic_vector(to_unsigned(NextAdr,16)); --incr_vec(Ram_NextAdress,'1');
367                                AdrRam<=Ram_NextAdress;  -- le rang qui a été envoyé;
368                                DataRam<=DataToSend(2)(3 downto 0) & MyPort;
369                                ResultOut<=(others=>'0');
370                                dma_wr_req<='1';
371                When StoreRank => --le processus qui écoute le Port et qui
372                                                                --stoke les adresses des autres bib va gérer le stockage du rang
373                                BCAST<='0';
374                                DS_ACK<='1';
375                                Send_Ack<='0';
376                                RTS_cmd<='0';
377                                EquFlag<='0';
378                                RTS_DAT<='0';
379                                CTR<='0';
380                                Result_En<='0';
381                                Initialized<='0';
382                                IsMain<='0';
383                               
384                                if ExecTime_out='1' then
385                                MainPort<="0000";
386                                MyRank<=MyPort;
387                                else
388                                MainPort<=DataReceived(0)(3 downto 0);
389                                MyRank<=DataReceived(2)(3 downto 0);
390                                 
391                                end if;
392                                WeRam<='1';
393                                --AdrRam<=DataReceived(2);  -- le rang qui a été envoyé;
394                                AdrRam<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
395                                DataRam<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
396                                ResultOut<=(others=>'0');
397                                RankAsked_i<='0';
398                                dma_wr_req<='1';
399                When SendApp =>  --ajouter du code pour recevoir l'adr du reg status
400                                Initialized<='1';
401                                ResultOut<="00000001"; -- Init Ok
402                                Result_En<='1';
403                                IsMain<='0';
404                                PortId<=MyPort;
405                                BCAST<='0';
406                                DS_ACK<='1';
407                                Send_Ack<='0';
408                                RTS_cmd<='0';
409                                RTS_DAT<='0';
410                                CTR<='0';
411                                WeRam<='0';
412                                RankAsked_i<='0';
413                                dma_wr_req<='0';
414                When EndInit=>
415                                RTS_cmd<='0';
416                                RTS_DAT<='0';
417                                Result_En<='0';
418                                IsMain<='0';
419                                Initialized<='0';
420                                DS_ACK<='0';
421                                Send_Ack<='0';
422                                BCAST<='0';
423                                CTR<='0';
424                                WeRam<='0';
425                                RankAsked_i<='0';
426                                ResultOut<=(others=>'0');
427                                dma_wr_req<='0';
428                end case;
429   end process;
430 
431   NEXT_STInit2_DECODE: process (stInit2,AppReq, AppAck,PortNumFlag,EquFlag,MainResp,RankAsked,RankSent,CM_RDY, CmdReceived, BCast_Rdy, DS_RDY, DataReceived, Send_RDY,TimeOut,Dma_wr_grant)
432   variable InitTimeOut :natural:=0;
433   variable nulvect : std_logic_vector(3 downto 0):="0000";     
434  begin
435      --declare default state for next_state to avoid latches
436      next_stInit2 <= stInit2;  --default is to stay in current state
437      --insert statements to decode next_state
438      --below is a simple example
439      case (stInit2) is
440         
441                       
442                When Init =>If AppReq='1' then
443                                         If PortNumFlag='1' and RankAsked='1' then
444                                                Next_stInit2 <=GetMainReq;
445                                         else
446                                                Next_stInit2 <=GetPortNum;
447                                        end if;
448                                        TimeOut_i<=0;
449                                end if;
450                               
451                When GetPortNum =>  -- récupérer le numéro du port
452                                                                                               
453                                                if CM_RDY='1' then 
454                                                        Next_stInit2 <=DecodeData;
455                                                end if;
456                                               
457                When DecodeData =>  -- cet état permet de lire les données reçues du port
458                                                        --if CM_RDY='1' then
459                                                                if ((Cmdreceived(2)(3 downto 0) or nulvect)=nulvect) then -- teste si le n° du port est zero
460                                                                  --EquFlag<='1';
461                                                                 else
462                                                                  --EquFlag<='0';
463                                                                end if;
464                                                               
465                                                                Next_stInit2 <=IsPortZero;
466                                                        --end if;
467                When IsPortZero => 
468                                                if PortNumFlag='1' then 
469                                               
470                                                End if;
471                                                if EquFlag='0'  then  --tester le numéro de port obtenu
472                                                        Next_stInit2 <=SeekMain1; -- chercher le numéro de port sur le réseau
473                                                else 
474                                                        Next_stInit2<=SetMainFlag; -- enregistrer le numéro de port
475                                                End If;
476                                                TimeOut_i<=0;
477               
478                When SeekMain1 =>If BCast_RDY='1' then  -- si tous les envois ont été postés
479                                                                        Next_stInit2<=SeekMain2;
480                                                        End if;                         
481                When SeekMain2 => 
482                                                                        If DS_RDY='1' then  -- Si un jeu de données a été reçu
483                                                                                Next_stInit2 <=StoreMain; -- de la librairie pricipale
484                                                                        elsif ExecTime_Out='1' then
485                                                                                                -- le Noc ne répond pas
486                                                                                                -- affecter un numéro en raport avec le port
487                                                                        Next_stInit2 <=StoreMain;
488                                                                        else
489                                                                                Timeout_i<=TimeOut+1;
490                                                                        End if;
491                                                       
492                                                         if (Datareceived(0)(7 downto 4) = INIT_SETRANK) then 
493                                                                                MainResp<='1';
494                                                         else
495                                                                                MainResp<='0';
496                                                         end if;
497                                                         
498                When StoreMain =>
499                                if DataReceived(0)(7 downto 4)= MPI_INIT then
500                                --ignorer le message
501                                Next_stInit2 <=StoreMain; --essayer de recevoir le rang
502                                elsif Datareceived(0)(7 downto 4) = INIT_SEEKMAIN then 
503                                -- ignorer ce message
504                                Next_stInit2 <=StoreMain; --essayer de recevoir le rang
505                                elsif Datareceived(0)(7 downto 4) = INIT_SETRANK then --ok le rang a été reçu
506                                -- enregistrer le Main Adresse et les adresses des autres processus
507                                -- dans la variable prévue à cet effet
508                                --if dma_wr_grant='1' then
509                                        Next_stInit2 <=StoreRank;
510                                --end if;
511                               
512                                end if;
513                                       
514                When StoreRank =>
515                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
516                                        -- la donnée ...
517                                        if dma_wr_grant = '1' then 
518                                                        Next_stInit2 <=SendApp;
519                                        else
520                                                        Next_stInit2 <=StoreRank;
521                                        end if;
522                                       
523                When SetMainFlag =>
524                                if dma_wr_grant='1' then
525                                        if DS_RDY='1' then
526                                           
527                                               
528                                                Next_stInit2 <=GetMainReq;
529                                        elsif Timeout=240 then
530                                                Next_stInit2 <=SendApp;
531                                        else
532                                                TimeOut_i<=TimeOut+1;
533                                        end if; -- il est envisagée de terminer le programme à ce point
534                                end if;
535                When GetMainReq =>
536               
537                                        if RankAsked='1' then
538                                                Next_stInit2 <=NewRank;
539                                        else
540                                                Next_stInit2 <=SendApp;
541                                        end if;
542                When NewRank =>
543                                Next_stInit2 <=SendRank;
544                When SendRank =>
545                                        if Send_RDY='1' then  --RankSent
546                                                Next_stInit2 <=RegRank;
547                                                RankSent_i<='1';  -- le rang a été envoyé
548                                                TimeOut_i<=0;   -- prépare le traitement de la prochaine requête
549                                                                                                -- d'attente des ports
550                                        end if;
551                When RegRank =>
552                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
553                                        -- la donnée ...
554                                        if dma_wr_grant = '1' then 
555                                                       
556                                       
557                                                        if DS_RDY='1' then
558                                                                RankSent_i<='0';
559                                                                Next_stInit2 <=GetMainReq;
560                                                        elsif Timeout=10 then
561                                                                Next_stInit2 <=SendApp;
562                                                        else
563                                                                TimeOut_i<=TimeOut+1;
564                                                        end if; -- il est envisagée
565                                       
566                                        end if;
567                When SendApp =>  -- envoyer au programme un signal
568                                        -- et attendre un acquittement et l'adresse de base
569                                        If AppAck='1' then
570                                                Next_stInit2 <=EndInit;
571                                        end if;
572               
573               
574                When EndInit=>
575                 
576                       
577                        Next_stInit2<=Init;
578      end case;     
579   end process;
580       
581--================================================
582--sauvegarde du rang et du main port à l'adresse de retour de la fonction Init
583--==================================================
584
585--====================================================
586--envoie des données sur le port
587--===================================================
588selector<=(Rcv_on,Cmd_on,Snd_on);
589
590process (selector,Rport_out_rd_en,cport_out_rd_en,sPort_in_wr_en ,cPort_in_wr_en,
591                                tosend ,tosend4)
592begin
593   case selector is
594       
595      when "000" => port_in_data<=(others=>'Z');
596                                                Port_in_wr_en<='0';
597                                                Port_out_rd_en<='0';
598     
599                when "001" => port_in_data<=tosend; --envoie de données
600                                                Port_in_wr_en<=sPort_in_wr_en ;
601                                                Port_out_rd_en<='0';
602      when "101" => port_in_data<=tosend; --envoie de données
603                                                Port_in_wr_en<=sPort_in_wr_en ;
604                                                Port_out_rd_en<=Rport_out_rd_en ;
605                when "010" | "110" | "011" | "111" => 
606                                                port_in_data<=tosend4; --envoie de commande GetPort
607                                                Port_in_wr_en<=cPort_in_wr_en;
608                                                Port_out_rd_en<=cport_out_rd_en;
609     
610          when "100" => port_in_data<=(others=>'Z'); -- réception de données
611                                                Port_in_wr_en<='0';
612                                                Port_out_rd_en<=Rport_out_rd_en ;
613     
614                when others => port_in_data<=(others=>'Z');
615                                                        Port_in_wr_en<='0';                                                     
616                                                        Port_out_rd_en<='0';
617   end case;
618end process;
619 
620--==================================================   
621       
622        --===============================================================
623        --processus d'accès au réseau
624        --===============================================================
625
626
627
628
629
630        preceiv:process(clk,reset)
631       
632        variable origport,destport : natural range 0 to 15;
633        variable dcount,dlen ,rtimeout:natural range 0 to 255;
634        variable ptype : std_logic_vector(3 downto 0);
635        begin
636--                             
637        if  rising_edge(clk) then 
638        if reset='1' then
639                etrec<=r_wait;
640                destport:=1;
641                rtimeout:=0;
642        else
643                        case  etrec is
644                        when r_wait =>
645                               
646                                rtimeout:=0;
647                               
648                        if Port_out_data_available='1' and CTR='1'  then 
649                                ptype:=port_out_data(7 downto 4);
650                                origport:=to_integer(unsigned(port_out_data(3 downto 0)));
651                               
652                                if ptype=MPI_INIT or ptype=INIT_SETRANK or ptype=INIT_SEEKMAIN then 
653                                                etrec<=r_dlen; --identification de la signature d'en tête valide
654                                                Datareceived(0)<=Port_out_data; --stocker l'entête
655                                else
656                                        --une donnée non attendue est présente sur le port
657                                        etrec<=r_drop;
658                                end if;
659                        --elsif Port_out_data_available='1' and CTR='0' then
660                        --              etrec<=r_drop;
661                        else
662                               
663                                etrec<=r_wait;
664                        end if;
665                       
666                        When r_drop => -- ignorer les messages qui arrivent à ce noeud tant que
667                                                                --l'application n'a pas été initialisée
668                                                if port_out_data_available='0' then 
669                                                        etrec<=r_end;
670                                                end if;
671                                                --Rport_out_rd_en<='1'; --lire les données qui sont dans le tampon de sortie           
672                                                --DS_RDY<='0';
673                        when r_Dlen =>   --positionnement du mot de longueur des données
674                        if Port_out_data_available ='1' then 
675                       
676                        --Rport_out_rd_en<='1';
677                        etrec<=r_glen;
678                        rtimeout:=0;
679                        else
680                                rtimeout:=rtimeout+1;
681                                        if rtimeout>=30 then 
682                                        Exectime_out<='1';  --read Noc time out
683                                                etrec<=r_end;             -- données pas prêtes
684                                        end if;
685                       
686                       
687                        end if;
688                        --DS_RDY<='0';
689                        -- 
690                        when r_glen =>   --lecture effective de la longueur des données
691                        if port_out_data_available='1' then 
692                        dlen:=to_integer(unsigned(port_out_data(Word-1 downto 0)));
693                        Datareceived(1)<=Port_out_data;
694                        --RPort_out_rd_en<='0';
695                        etrec<=r_data;
696                        dcount:=2;  -- initialisation du compteur de reception (il y a
697                                                        -- déjà deux mots reçues
698                        else
699                                rtimeout:=rtimeout+1;
700                                        if rtimeout>=30 then 
701                                        ExecTime_out<='1';
702                                                etrec<=r_end;             -- données pas prêtes
703                                        end if;
704                       
705                        end if;
706                        --DS_RDY<='0';
707                        when r_data =>                                          -- lecture des données
708                        if port_out_data_available='1'  then 
709                                       
710                                        --Rport_out_rd_en<='1';   --autoriser la lecture
711                                        DataReceived(dcount)<=Port_out_data; --récupération des données
712                                        --assert true report "Donnée lue :"; --& string(unsigned(port4_out(Word-1 downto 0)))
713                                        --DS_RDY<='0';
714                                        dcount:=dcount+1;
715                                        --severity note;
716                                        if dlen <=dcount then -- ce doit être égale ici et non <= ???
717                                                etrec<=r_end;
718                                                --DS_RDY<='1'; -- jeu de données disponibles
719                                        elsif dcount=255 then   --dépassement de la capacité
720                                                --DS_RDY<='0';
721                                                etrec<=r_end;
722                                        end if;
723                        else
724                                        rtimeout:=rtimeout+1;
725                                        if rtimeout>=30 then 
726                                           ExecTime_out<='1';
727                                                etrec<=r_end;             -- données pas prêtes
728                                        end if;
729                                        --DS_RDY<='0';
730                                       
731                        end if;
732                        when r_pulse =>
733                                        etrec<=r_end; 
734                        when r_end =>
735                       
736                       
737                       
738                        --rPort_out_rd_en <='0';
739                       
740                        if DS_ACK='1' or rtimeout> 30 or CTR='0' then 
741                                --DS_RDY<='0';
742                                etrec<=r_wait;
743                        end if;
744                       
745                       
746                       
747                        end case;
748                 end if;--reset='1'
749                end if;   
750  end process preceiv;
751 
752 val_preceiv: process (etrec)
753  begin
754  case etrec is
755                                        when r_wait  =>
756                                                DS_RDY<='0';
757                                               
758                                                Rport_out_rd_en <='0';
759                                        when r_dlen  =>
760                                                        DS_RDY<='0';
761                                                        Rport_out_rd_en <='1';
762                                                        rcv_On<='1';
763                                        when r_drop  =>
764                                                        DS_RDY<='0';
765                                                        Rport_out_rd_en <='1';
766                                                        rcv_On<='1';
767                                        when r_glen =>
768                                                        Rport_out_rd_en <='1';
769                                                        DS_RDY<='0';
770                                                        rcv_On<='1';
771                                        when r_data =>
772                                                        Rport_out_rd_en <='1';
773                                                        DS_RDY<='0';
774                                                        rcv_On<='1';
775                                        when r_pulse =>
776                                                                Rport_out_rd_en <='0';
777                                                                rcv_On<='1';
778                                                                DS_RDY<='1';
779                                        when r_end =>
780                                                        Rport_out_rd_en <='0';
781                                                        DS_RDY<='1';
782                                                        rcv_On<='0';
783                                        when others =>
784                                                        Rport_out_rd_en <='0';
785                                                        DS_RDY<='0';
786                                                        rcv_On<='0';
787                                end case;
788        end process;
789 
790  psend:process(clk,reset)
791                --génération des paquets à partir du  port courant
792                variable pactype :natural range 0 to 15;
793                variable destport : natural range 0 to 15:=0;
794                variable realdlen, i,i_pair : natural range 0 to 255;
795                variable MaxPort : natural :=to_integer(unsigned(NOCMAX)); -- en fait ne doit pas être 0
796               
797               
798                                begin
799                                if rising_edge(clk) then 
800                                                 if reset='1' then 
801                                                                etsnd<=s_init;
802                                 
803                                   
804                                                 
805                                                else -- le process s'exécute sur chaque front
806                                                                                                                        -- montant de l'horloge
807                                                case etsnd is
808                                                when s_init => tosend<=(others=>'Z');
809                                                                                        MaxPort :=to_integer(unsigned(NOCMAX));
810                                                                sPort_in_wr_en<='0';
811                                                        if port_in_full='0' and Rts_dat='1' then   --on peut aussi tester si le port est vide
812                                                                BCast_RDY<='0';  -- pas la fin de du Broadcasting
813                                                                          Send_RDY<='0';
814                                                                          Snd_on<='1';
815                                                                          if Bcast='1' then -- envoyer à tous les ports le même message ?
816                                                                          DestPort :=0;
817                                                                          else
818                                                                                DestPort:=to_integer(unsigned(DataToSend(0)(3 downto 0)));
819                                                                          end if;
820                                                                          etsnd<=s_head;
821                                                        end if;
822                                                when s_head  =>    -- construction et envoie de l'en-tête
823                                                Send_RDY<='0'; --l'envoi commence
824                                                BCast_RDY<='0';
825                                                Snd_on<='1';
826                                                --pactype:=to_integer(MPI_INIT);--
827                                                pactype:=to_integer(unsigned(DataToSend(0)(7 downto 4)));
828                                                --realdlen:=to_integer(unsigned(Datalen));
829                                                --? destport:=MAXPORT; -- le port de destination
830                                               
831                                                tosend <=STD_LOGIC_VECTOR(to_unsigned(pactype,4)) & STD_LOGIC_VECTOR(to_unsigned(destport,4));
832                                                 sPort_in_wr_en<='1';   --
833                                                 
834                                                 i:=1;
835                                                 etsnd<=s_len2;  -- passer à l'état suivant
836                                                 
837                                                when s_len => 
838                                                        BCast_RDY<='0';
839                                                        Send_RDY<='0';
840                                                        Snd_on<='1';
841                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(Realdlen,8)));
842                                                        tosend<=DataToSend(1);
843                                                        sPort_in_wr_en <='1';
844                                                       
845
846                                                        --port1_in<=tosend1; --copie directe sur le port
847                                                        etsnd<=s_len2;
848                                                when s_len2 => 
849                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(realdlen,8)));
850                                                        sPort_in_wr_en<='1';
851                                                        tosend<=DataToSend(1);
852
853                                                        --port1_in<=tosend1; --copie directe sur le port
854                                                        etsnd<=s_data; 
855                                                        BCast_RDY<='0';
856                                                        Send_RDY<='0';
857                                                        Snd_on<='1';
858                                                        i:=i+1;
859                                                when s_data =>
860                                                        Snd_on<='1';
861                                                        if Port_in_full='0'and RTS_dat='1' then
862                                                                sPort_in_wr_en<='1';
863                                                               
864                                                                     --envoie des données sur le port   
865                                                                        tosend<=DataToSend(i);
866                                                               
867                                                               
868                                                                if i+1>=datalen then 
869                                                                        etsnd<=s_end;
870                                                                        Send_RDY<='1'; --l'envoi est terminé
871                                                                        if BCast='1' and destport=MAXPort then
872                                                                                BCAST_RDY<='1'; --l'envoi collectif aussi
873                                                                        else 
874                                                                                BCast_RDY<='0';
875                                                       
876                                                                        end if;
877                                                                else
878                                                                        BCast_RDY<='0';
879                                                                        Send_RDY<='0';
880                                                                        i:=i+1;
881                                                                end if;
882                                                        else
883                                                                sPort_in_wr_en<='0';
884                                                                BCast_RDY<='0';
885                                                                Send_RDY<='0';
886                                                        end if;
887                                                when s_end  =>
888                                                 tosend<=(others=>'Z');
889                                                        Send_RDY<='1'; 
890                                                        sPort_in_wr_en<='0';
891                                                        Snd_on<='0';
892                                                        if Bcast='1' then
893                                                                DestPort:=Destport+1;
894                                                                if DestPort<=MaxPort then
895                                                                etsnd<=s_head;
896                                                                else
897                                                                BCast_RDY<='1' ; -- BroadCast End=Ok
898                                                                        if Send_ack='1' then
899                                                                                etsnd<=s_init;
900                                                                        end if;
901                                                                end if;
902                                                        else
903                                                                BCast_RDY<='0';
904                                                                if Send_ack='1' then
905                                                                        etsnd<=s_init;
906                                                                end if;
907                                                               
908                                                        end if;
909                                                end case;       
910                                               
911                                                                               
912                                                end if;  --reset ='1'
913                                        end if; --rising_edge...
914                end process psend;     
915
916-- envoi des commandes         
917pcmd:process(clk,reset)
918       
919        variable origport,destport,pid,mport : natural range 0 to 15;
920        variable ctimeout:natural range 0 to 255;
921        begin
922       
923        if  rising_edge(clk) then
924                if reset='1' then
925                        etcmd<=cmdstart;
926                        destport:=0;
927                        ctimeout:=0;
928                        origport:=1;
929        --              sorigport<=origport;
930                else
931                                        case  etcmd is
932                                        when cmdstart =>
933                                                if Port_in_empty='1' and RTS_Cmd='1' then 
934                                                                        etcmd<=cmdpost;
935                                               
936                                                end if;
937                                 when cmdpost =>
938                                        if Port_in_empty='1' then 
939                                                etcmd<=cmdread;
940                                        end if;
941                                       
942                                when cmdpostidle  =>   --permet juste la prise en compte de la commande
943                                                etcmd<=cmdread;
944                                                dcount<=0;-- initialisation du compteur de reception
945                                 when cmdread =>
946                                               
947                                               
948                                                ctimeout:=0;
949                                               
950                                        if Port_out_data_available='1' then 
951                                                mport:=to_integer(unsigned(port_out_data(7 downto 4)));
952                                                pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
953                                                CmdReceived(dcount)<=port_out_data;
954                                                --cdata_out_en(origport)<='1';
955--                                              if pid=origport then --le port a été bien identifié
956                                                                etcmd<=cmdglen; --
957                                                                dcount<=dcount+1;
958--                                                      else
959--                                                      etcmd<=cmdtimeout;
960--                                              end if;
961                                        else
962
963                                                etcmd<=cmdread;
964                                        end if;
965                                       
966                                       
967                                        when cmdlen =>   --positionnement du mot de longueur des données
968                                        if Port_out_data_available='1' then 
969                                       
970                                        etcmd<=cmdglen;
971                                        ctimeout:=0;
972                                        else
973                                                ctimeout:=ctimeout+1;
974                                                        if ctimeout>=30 then 
975                                                                etcmd<=cmdtimeout;             -- données pas prêtes
976                                                        end if;
977                                       
978                                       
979                                        end if;
980                                        when cmdglen =>   --lecture effective de la longueur des données
981                                        if Port_out_data_available='1' then 
982                                                cdlen<=to_integer(unsigned(port_out_data(Word-1 downto 0)));
983                                                CmdReceived(dcount)<=port_out_data;
984                                                etcmd<=cmddata;
985                                          dcount<=dcount+1;
986                                        else
987                                                ctimeout:=ctimeout+1;
988                                                        if ctimeout>=30 then 
989                                                        --time_out(destport)<='1';
990                                                                etcmd<=cmdtimeout;             -- données pas prêtes
991                                                        end if;
992                                       
993                                        end if;
994                                       
995                                        when cmddata =>
996                                        if (port_out_data_available='1' and ctimeout<30) then 
997                                                       
998                                                        --cdata_out_en(origport)<='1';
999                                                        mport:=to_integer(unsigned(port_out_data(7 downto 4)));
1000                                                        --attention les ports sont numérotés à partir de 0
1001                                                        pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
1002                                                        CmdReceived(dcount)<=port_out_data;
1003                                                        if (dcount>=cdlen-1 ) then--attention le compteur de données commence à 0
1004                                                                etcmd<=cmdend;
1005                                                                --CM_RDY<='1';
1006                                                        else
1007                                                                dcount<=dcount+1;
1008                                                        end if;                 
1009                                        Else
1010                                                       
1011                                                        if ctimeout>=30 then 
1012                                                                --time_out(destport)<='1';
1013                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1014                                                        else
1015                                                        ctimeout:=ctimeout+1;
1016                                                        etcmd<=cmdend;
1017                                                        end if;
1018                                        end if;
1019                                        when cmdend =>
1020                               
1021                                                        etcmd<=cmdstart;
1022
1023                                        when cmdtimeout =>
1024
1025                                          etcmd<=cmdstart;
1026                                        end case;
1027                --sorigport<=origport; 
1028                end if;   --reset='1'
1029        end if;
1030  end process pcmd;     
1031
1032majetcmd: process (etcmd,DataToSend, port_out_data_available, dcount,port_out_data)
1033variable origport : natural;
1034variable i:natural:=0;
1035        begin
1036                        case  etcmd is
1037                when cmdstart =>
1038                                i:=0;
1039                                Port_in_cmd_en<='0';
1040                                tosend4<=(others=>'Z');
1041                                cport_out_rd_en<='0';
1042                                cport_in_wr_en<='0';
1043                                CM_RDY<='0';
1044                                Cmd_on<='0';
1045                 when cmdpost | cmdpostidle =>
1046                                cport_in_wr_en<='1';
1047                                tosend4<=DataToSend(0); ---code pour getportid
1048                                Port_in_cmd_en<='1';
1049                                cport_out_rd_en<='0';
1050                                CM_RDY<='0';
1051                                Cmd_on<='1';
1052                 when cmdread =>
1053                                tosend4<=(others=>'Z');
1054                                cPort_in_wr_en<='0';
1055                                cport_out_rd_en<=port_out_data_available;
1056                                --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1057                                Port_in_cmd_en<='1';
1058                                CM_RDY<='0';
1059                                Cmd_on<='1';
1060                when cmdlen |cmdglen =>   --positionnement du mot de longueur des données
1061                                        tosend4<=(others=>'Z');
1062                                        cport_in_wr_en<='0';
1063                                        cport_out_rd_en<=port_out_data_available;
1064                                        Port_in_cmd_en<='1';
1065                                        --CmdReceived(dcount)<= port_out_data;
1066                                        CM_RDY<='0';
1067                                        Cmd_on<='1';
1068                when cmddata =>
1069                                        tosend4<=(others=>'Z');
1070                                        cport_in_wr_en<='0';
1071                                        cport_out_rd_en<=Port_out_data_available;
1072                                        Port_in_cmd_en<='1';
1073                                        --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1074                                        i:=i+1;
1075                                        CM_RDY<='0';
1076                                        Cmd_on<='1';
1077                        when cmdend =>
1078                                        tosend4<=(others=>'Z');
1079                                cport_in_wr_en<='0';
1080                                cport_out_rd_en<='0';
1081                                --CmdReceived(dcount)<=port_out_data;
1082                                Port_in_cmd_en<='0';
1083                            CM_RDY<='1';
1084                                 Cmd_on<='0';
1085                        when cmdtimeout =>
1086                                        tosend4<=(others=>'Z');
1087                                  cport_in_wr_en<='0';
1088                                  cport_out_rd_en<='0';
1089                                  Port_in_cmd_en<='0';
1090                                        Cmd_on<='1';                             
1091                        end case;
1092               
1093end process majetcmd ; 
1094end Behavioral;
1095
Note: See TracBrowser for help on using the repository browser.