source: PROJECT_CORE_MPI/MPI_HCL/BRANCHES/v2.1/CORE_MPI/EX4_FSM.vhd @ 144

Last change on this file since 144 was 142, checked in by rolagamo, 10 years ago
File size: 60.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           Ready : out STD_LOGIC; --indique que le module est disponible
44           NocSize : out  STD_LOGIC_VECTOR(3 downto 0);
45                             PortId : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
46           AppRank : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
47           AppSize : out  STD_LOGIC_VECTOR(3 downto 0):=(others=>'0');
48           IsMain : out  STD_LOGIC;
49           I_fifo_full :in STD_LOGIC; --instruction fifo
50                       I_fifo_wr_en: out STD_LOGIC;--instruction fifo Write enable
51                       I_fifo_data_in :out STD_LOGIC_vector(Word-1 downto 0); --instruction fifo data
52                             Initialized : out STD_LOGIC;
53                          Snd_Ack : IN std_logic;
54                Rec_Rdy : IN std_logic;
55                Rec_Data : IN Typ_PortIO(0 to 3);
56                Snd_data : OUT Typ_PortIO(0 to 3);
57                Snd_Start : out std_logic;
58                Rec_Ack : OUT std_logic;       
59                                   dma_wr_grant : in  STD_LOGIC;
60                                   dma_wr_request : out  STD_LOGIC;
61                                dma_rd_grant : in  STD_LOGIC;
62                                dma_rd_request : out  STD_LOGIC;
63                                ram_rd : out std_logic;
64                                ram_wr : out std_logic;
65                                ram_address : out std_logic_vector(ADRLEN-1 downto 0);--accès au stockage
66                                Ram_data_in : out STD_LOGIC_VECTOR (Word-1 downto 0);
67                                Ram_data_out : in STD_LOGIC_VECTOR (Word-1 downto 0);
68                       
69                          AppAck : in  STD_LOGIC;
70           AppReq : in  STD_LOGIC;
71                          port_in_cmd_en : out  STD_LOGIC:='0';
72                          port_in_wr_en : out  STD_LOGIC:='0';
73                          port_in_empty : in  STD_LOGIC;
74           port_in_full : in  STD_LOGIC;
75           port_in_data : out  STD_LOGIC_VECTOR (Word-1 downto 0):=(others=>'-');
76                          port_out_data : in  STD_LOGIC_VECTOR (Word-1 downto 0);
77           port_out_rd_en : out  STD_LOGIC:='0';
78           port_out_data_available : in  STD_LOGIC);
79end EX4_FSM;
80
81architecture Behavioral of EX4_FSM is
82
83COMPONENT SetBit
84        PORT(
85                clk : IN std_logic;
86                reset : IN std_logic;
87                BitNum : IN std_logic_vector(0 to 2);
88                BitVal : IN std_logic;
89                dma_wr_grant : IN std_logic;
90                dma_rd_grant : IN std_logic;
91                Ram_data_in : IN std_logic_vector(7 downto 0);
92                   
93                dma_wr_request : OUT std_logic;
94                dma_rd_request : OUT std_logic;
95                ram_rd : OUT std_logic;
96                ram_wr : OUT std_logic;
97                ram_address : OUT std_logic_vector(15 downto 0);
98                Ram_data_out : OUT std_logic_vector(7 downto 0)
99                );
100        END COMPONENT;
101Type Ar_MPIPort_In is array (positive range <>) of Typ_MPIPort_in;
102Type Ar_MPIPort_out is array (positive range <>) of Typ_MPIPort_out;
103
104        --MAE pour emission de init
105   --type init1_type is (init,NocSize,InitToNoc,NextPort,EndBCast);
106        --      MAE pour affectation des rangs aux différentes librairies MPI
107        type init2_type is (init,GetPortNum,DecodeData,IsPortZero,SeekMain1,SeekMain2,StoreMain,SetMainFlag,ReadNoc,GetMainReq,StoreRank,NewRank,SendRank,RegRank,SendPeerStat,AskPeerStat,GetPeerStat,SendApp,SpawnApp,SpawnLoad,ErrSpawn,EndInit);
108   -- MAE pour réception de init depuis le réseau;
109        type init3_type is  (init,GetNocSize,ReadInitHead,StorePort,EndInit); 
110        type typ_send is (s_init,s_head,s_len,s_len2,s_data,s_end);
111        type typ_receiv is (r_wait,r_dlen,r_drop,r_glen,r_data,r_pulse,r_end);
112        type typ_cmd is (cmdstart,cmdpost,cmdpostidle,cmdread,cmdlen,cmdglen,cmddata,cmdend,cmdtimeout);
113  type typ_mem16 is array(natural range <>) of std_logic_vector(15 downto 0);--
114        type typ_sendproc is (Hcl_init_off,Hcl_init_on);
115         
116                signal etsnd : typ_send;
117                signal etrec:typ_receiv;   --pour la machine à état de réception
118                signal etcmd :typ_cmd;     --pour la machine à état de commande
119    signal et_sendproc :typ_sendproc;
120signal IS_state,next_Is_state : natural range 0 to 3:=0;
121
122--      signal stInit1, next_stInit1 : init1_type;
123        signal stInit2, next_stInit2 : init2_type; 
124        --signal stInit3, next_stInit3 : init3_type;
125        --signaux pour l'interface avec les ports
126        signal cport_in_wr_en,sport_in_wr_en:std_logic;
127        signal cport_out_rd_en,rport_out_rd_en:std_logic;
128        signal rdy:std_logic:='0'; --signal busy/ready
129        signal tosend,tosend4 :std_logic_vector(Word-1 downto 0);
130        signal PeerStat,PeerStat_i : std_logic_vector(15 downto 0):=(others=>'0'); --état des autres Lib initialisées
131  signal SpawnReq,SpawnReq_Q : std_logic_vector(15 downto 0):=(others=>'0'); --état des autres HT qui ont appelés le Spawn     
132        signal Spawn_grp,Spawn_grp_Q :typ_mem16(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0')); --un max de quatre groupes de fils est prévu
133        signal Grp_id,grp_id_i :natural range 0 to 3:=0; --id du groupe des HT fils
134        signal selector : std_logic_vector (2 downto 0); -- pour le MUX des signaux vers le port
135        --signaux pour les états des MAE
136        signal  NocSizeOk,PortCountFlag : std_logic;
137        signal PortNumFlag,PortNumFlag_i,EquFlag,EquFlag_i,MainResp: std_logic:='0';
138        signal StatAsked,RankAsked,RankSent:std_logic;
139        signal  nextr,nextr_i : natural :=0;
140   signal RTS_cmd,RTS_dat,RTS_I,CTR,BCast,Send_Ack,DS_Ack,CM_Ack:std_logic:='0';
141        signal I_Send_Ack,I_Send_Rdy:std_logic:='0';
142        signal Rcv_On,Snd_On,Cmd_On : std_logic:='0'; --status des MAE d'envoie et de réception
143        signal SpawnOn,SpawnInit ,SpawnInit_i:std_logic:='0'; --indique que le Spawn est activé
144        signal SpawnNbReq,SpawnNbAck,SpawnNBAck_i : natural range 0 to 15 :=0; --compte le nombre de requêtes et le nombre d'acquitement
145        signal SpawnNbReq_Q : natural range 0 to 15 :=0; --compte le nombre de requêtes et le nombre d'acquitement
146        signal SpawnCmd0,SpawnCmd1, SpawnCmd2 :std_logic_vector(Word-1 downto 0):=(others=>'0');
147        signal SpawnCmd0_Q,SpawnCmd1_Q, SpawnCmd2_Q :std_logic_vector(Word-1 downto 0):=(others=>'0');
148        signal SpawnDest :std_logic_vector(3 downto 0);
149        Signal Ht_Start,Ht_Start_i : natural range 0 to 15:=0;
150        Signal vPeerStat,vPeerStat_i : std_logic_vector(15 downto 0):=(others=>'0');
151        signal IsMain_i,IsMain1,Initialized_i,HCL_init,HCL_Init_i: std_logic:='0';
152        signal DS_RDY ,BCast_Rdy,Send_RDY,CM_RDY:std_logic:='0';
153        signal ExecTime_out:std_logic;
154        --signaux de gestion de la RAM
155        signal Ram_Next_Address : std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
156        signal Ram_NExt_Address_i :std_logic_vector(ADRLEN-1 downto 0):=std_logic_vector(to_unsigned(Core_BASE_ADR+CORE_Rank2port_BASE,16));
157        signal n,n_i:natural range 0 to 15 :=0;
158        signal n0,n0_i:natural range 0 to 7:=0;
159        signal DataToRam : std_logic_vector(Word-1 downto 0) ;
160        signal dma_rd,dma_wr,rd_ok ,wr_ok:std_logic:='0';
161        --Signaux des résultats et de l'état
162  signal PortNum_i,PortNum,MyPort : std_logic_vector(3 downto 0);  --
163        signal NocMax ,NocMax_i: std_logic_vector(3 downto 0):=(others=>'0'); -- Nombre de ports du réseau -1 ?
164        signal MyRank : std_logic_vector(3 downto 0) ; --rang du PE
165        signal AppSize_i,AppSize1:std_logic_vector(3 downto 0) ;--taille de l'application
166        signal Spawn_done,Spawn_done_i:std_logic:='0'; --indique que le Spawn a été effectué
167        signal MainPort,MainPort_i : std_logic_vector(3 downto 0) ; --Port de la lib main
168        signal NextRank,NextRank_i : std_logic_vector(3 downto 0):=(others=>'0'); --utiliser pour gérer les affectations de rangs MPI
169   signal Data_To_Send,Data_to_send_i : Typ_PortIo(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0')); -- permet d'empiler les données à envoyer
170        signal RankToPort :Typ_PortIo(0 to 15);--permet d'associer un port réseau à chaque  rang
171        signal CmdReceived : Typ_PortIO(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0'));
172        signal DataReceived : Typ_PortIO(0 to 3):=((others=>'0'),(others=>'0'),(others=>'0'),(others=>'0'));
173        signal Datalen,DataLen_i : natural range 0 to 7:=0; --indique la longueur des données
174        --other outputs
175        signal StatAsked_i,RankAsked_i,MainResp_i,RankSent_i,Result_i:std_logic:='0';
176        signal snd_start_q,snd_start_i:std_logic:='0';--version interne des signaux de sortie
177   --signal BCast_Rdy_i : std_logic;
178        signal cdlen,dcount : natural range 0 to 255:=0; --longueur du paquet reçu par le process pcmd
179        signal timeout,timeout_i : natural range 0 to 4095:=0;
180        signal PortStat,PortStat_i : std_logic_vector(3 downto 0):=(others=>'0');
181        signal PeerPort,PeerPort_i : natural range 0 to 15:=0; -- désigne le port qui emet une requête
182        signal PeerRTS,PeerRTS_i,PeerCTR:std_logic:='0';
183        signal cpt,cpt_peer : natural range 0 to 31:=0; --compteur pour le nombre de HT initialisés
184        signal clk_cyl,clk_cyl_i : natural range 0 to 15:=0;
185begin
186--=======================================================================================
187--fonctions du module
188--=======================================================================================
189--=======================================================================================
190 
191-- Inst_SetBit: SetBit PORT MAP(
192--              clk => clk,
193--              reset => reset ,
194--              ce => cmd,
195--              BitNum => ,
196--              BitVal => '1',
197--              dma_wr_grant => dma_wr_grant ,
198--              dma_wr_request => dma_wr_request,
199--              dma_rd_grant => dma_rd_grant,
200--              dma_rd_request => dma_rd_request,
201--              ram_rd => ram_rd,
202--              ram_wr => ram_wr,
203--              ram_address => ,
204--              Ram_data_in => Ram_data_in,
205--              Ram_data_out => Ram_data_out
206--      );
207
208 
209   -- Gestion de l'initialisation du Core MPI
210  sync_Init2 : process (clk,reset)
211  begin
212        if reset='1' then
213                stinit2<=init;
214                StatAsked<='0';
215                MyPort<=(others=>'0');
216                NextRank<=(others =>'0');
217                PortNumFlag<='0';
218                RankSent<='0';
219                AppRank<="0000";
220                AppSize1<="0000";
221                SpawnNbAck<=0;
222                ISMain1<='0';
223                MyPort<="0000";
224                MyRank<="0000";
225                Ready<='0';
226                SpawnNbReq_q<=0;
227                SpawnReq_Q<=(others=>'0');
228                SpawnCmd0_Q<=(others=>'0');
229                SpawnCmd1_Q<=(others=>'0');
230                SpawnCmd2_Q<=(others=>'0');
231                --Spawn_grp_q<=Spawn_grp; --à traiter
232                for i in 0 to 3 loop
233                Spawn_grp_q(i)<=(others=>'0');
234                end loop;
235                PeerRTS<='0';
236                PortNum<="0000";
237                Spawn_done<='0';
238                HCL_init<='0';
239                MainResp<='0';
240                SpawnInit<='0';
241                PeerStat<=(others=>'0');
242                PortStat<=(others=>'0');
243                HCL_init<='0';
244                PeerStat<=(others=>'0');
245                DataLen<=0;
246                MainPort<=(others=>'0');
247                Nextr<=0;
248                NocMax<=(others=>'0');
249                PeerPort<=0;
250                grp_id<=0;
251                HT_Start<=0;
252                vPeerStat<=(others=>'0');
253        elsif rising_edge(clk) then
254                stinit2<=next_stinit2;
255                IS_State<=Next_IS_State;
256                n0<=n0_i;
257                --ajout des autres affectations ici
258                Ram_Next_Address<=Ram_Next_Address_i;
259                PortNumFlag<=PortNumFlag_i;
260                RankAsked<=RankAsked_i;
261                RankSent<=RankSent_i;
262                AppRank<=MyRank;
263                timeout<=timeout_i;
264                SpawnInit<=SpawnInit_i;
265                cpt<=cpt_peer;
266                clk_cyl<=clk_cyl_i;
267                NextRank<=NextRank_i;
268                StatAsked<=StatAsked_i;
269                MainResp<=MainResp_i;
270                AppSize1<=AppSize_i;
271                n<=n_i;
272                Ht_Start<=Ht_Start_i;
273                Grp_Id<=Grp_Id_i;
274                vPeerStat<=vPeerStat_i;
275                SpawnNbAck<=SpawnNbAck_i;
276                PortStat<=PortStat_i;
277                EquFlag<=EquFlag_i;
278                --IsMain1<=IsMain_i;
279                if ismain_i='1' then
280                        IsMain1<='1';
281                       
282                else
283                        IsMain1<=IsMain1;
284                end if;
285                if stInit2=DecodeData then 
286                        MyPort<=Cmdreceived(2)(3 downto 0);
287                end if;
288               
289                if stInit2=StoreRank and ExecTime_Out='1' then
290                        MyRank<=MyPort;
291                elsif stInit2=StoreRank then
292                        MyRank<=DataReceived(2)(3 downto 0);
293                elsif stInit2=SetMainFlag then
294                  MyRank<=MyPort;
295                end if;
296                Ready<=Rdy;
297                snd_start_q<=snd_start_i;
298                SpawnNbReq_q<=SpawnNbReq;
299                SpawnReq_Q<=SpawnReq;
300                SpawnCmd0_Q<=SpawnCmd0;
301                SpawnCmd1_Q<=SpawnCmd1;
302                SpawnCmd2_Q<=SpawnCmd2;
303                Spawn_grp_q<=Spawn_grp;
304                PeerRTS<=PeerRTS_i;
305                PortNum<=PortNum_i;
306                Spawn_done<=Spawn_done_i;
307                HCL_init<=Hcl_init_i;
308                PeerStat<=PeerStat_i;
309                DataLen<=DataLen_i;
310                MainPort<=MainPort_i;
311                Nextr<=NextR_i;
312                NocMax<=NoCMax_i;
313                PeerPort<=PeerPort_i;
314                grp_id<=grp_id_i;
315                for i in 0 to 3 loop
316                        data_to_send(i)<=data_to_send_i(i);
317                end loop;
318        end if;
319end process;
320
321AppSize<=AppSize1;
322
323  Init2_DECODE: process (stinit2,n, CmdReceived, EquFlag, MyPort, DS_RDY, MainResp, DataReceived, 
324  SpawnOn,Ram_Next_Address,PeerRTS,PortSTAT,dma_rd,dma_wr,Send_rdy,I_Send_rdy,rd_ok,wr_ok,Instruction,
325  MainPort,PeerStat,SpawnCmd0,SpawnCmd1,SpawnCmd2,SpawnInit,BCast_rdy,Data_to_send,portnum,
326  PortNumFlag,peerport,NocMax,Nextrank,rankasked,NextR,IsMain1,ExecTime_out,DataToRam)
327   variable nextadr : natural :=0;--to_integer(unsigned(Ram_Next_Address));
328        variable nport : natural range 0 to 15:=0;
329        begin
330      for i in 0 to 3 loop
331                        data_to_send_i(i)<=data_to_send(i);
332                end loop;
333                PortNum_i<=PortNum;
334                PortNumFlag_i<=PortNumFlag;
335                PortID<=MyPort;
336                PeerPort_i<=PeerPort;
337                NocMax_i<=NoCMax;
338                NextRank_i<=NextRank;
339                MainPort_i<=MainPort;
340                PeerStat_i<=PeerStat;
341                EquFlag_i<=EquFlag;
342                RankAsked_i<=RankAsked;
343                NextR_i<=NextR;
344                Ram_Next_Address_i<=Ram_Next_Address;
345                Ram_address<=(others=>'1');
346                Ram_data_in<=(others=>'1');
347                dma_rd_request<='0';
348                dma_wr_request<='0';
349                Initialized_i<='0';
350                rdy<='0';
351                ram_rd<='0';
352                ram_wr<='0';
353                I_Send_ack<='0';
354                IsMain_i<='0';
355                send_ack<='0';
356                DataLen_i<=0;
357      Case stInit2 is
358                When Init =>
359                        RTS_cmd<='0';
360                        --RTS_dat<='0';
361                        RTS_I<='0';
362                        BCast<='0';
363                        Result_En<='0';
364                        Initialized_i<='0';
365                        CM_Ack <='0';
366                        CTR<='0' ;
367                        DS_ACK<='0';
368                        Send_Ack<='0';
369                        ram_wr<='0';
370                        rdy<='1';--le module est disponible
371                        ResultOut<=(others=>'0');
372                        if PortNumFlag='1'  and IsMain1='1' then
373                                PortNum_i<=Instruction(3 downto 0);
374                        else
375                                PortNum_i<=(others=>'-');
376                        end if;
377                        EquFlag_i<='0';
378                        RankAsked_i<='0';
379                        dma_wr_request<='0';
380                        dma_rd_request<='0';
381                When GetPortNum =>
382                        RTS_cmd<='1';
383                        RTS_I<='0';
384                       
385                        Result_En<='0';
386                        Initialized_i<='0';
387                        BCast<='0';   --réalise un envoie non collectif
388                        CM_Ack<='0';   -- les données sont maintenant attendues
389                        CTR<='0' ;
390                        data_to_send_i(0)<=X"0" & GETPORTID;
391                        DS_ACK<='0';
392                        Send_Ack<='0';
393                        ram_wr<='0';
394                        rdy<='0';
395                        IsMain_i<='0';
396                        ResultOut<=(others=>'0');
397                        PortNum_i<=(others=>'-');
398                        RankAsked_i<='0';
399                        dma_wr_request<='0';
400                When DecodeData =>
401                        EquFlag_i<=(All_zeros(Cmdreceived(2)(3 downto 0)));
402                        RTS_cmd<='0';
403                        RTS_I<='0';
404                        BCast<='0';
405                       
406                        Result_En<='0';
407                       
408                        CM_Ack <='1'; --les données ont été reçues
409                        --MyPort<=Cmdreceived(2)(3 downto 0);
410                        PortNum_i<=Cmdreceived(2)(3 downto 0); --récupère les valeurs de port
411                        PeerPort_i<=To_integer(unsigned(Cmdreceived(2)(3 downto 0)));
412                        NocMax_i<=Cmdreceived(2)(7 downto 4);  -- et la taille du réseau
413                        PortNumFlag_i<='1';  -- le numéro du port est maintenant connu
414                        CTR<='0' ;
415                        DS_ACK<='0';
416                        Send_Ack<='0';
417                        ram_wr<='0';
418                        rdy<='0';
419                        RankAsked_i<='0';
420                        ResultOut<=(others=>'0');
421                        dma_wr_request<='0';
422                When IsPortZero => --Ce port est-il le n° 0 du NoC ?
423                        BCast<='0';
424                        Result_En<='0';
425                        RTS_cmd<='0';
426                        RTS_I<='0';
427                        NextRank_i<="0001"; -- le prochain rang à affecter sera le n° 1
428                        nextr_i<=1;
429                        IsMain_i<=EquFlag;
430                        --MyRank<="0000";
431                        MainPort_i<="0000";
432                        --MainAdr<="0000";   -- le port 0 est le main Lib par défaut;
433                        CTR<='0' ;
434                        DS_ACK<='0';
435                        ram_wr<='0';
436                                                rdy<='0';
437                        RankAsked_i<='0';
438                        ResultOut<=(others=>'0');
439                        dma_wr_request<='0';
440                When SeekMain1 =>    -- recherche de la lib main
441                                RTS_cmd<='0';
442                                --RTS_DAT<='1';
443                                RTS_I<='1';
444                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
445                                DS_ACK<='0'; --les données sont attendus
446                                Send_Ack<=BCast_rdy;
447                                I_Send_Ack<=BCAst_rdy;
448                                data_to_send_i(0)<=MPI_INIT & MyPort ;
449                                data_to_send_i(1)<="00000100"; -- la longueur du packet =4
450                                data_to_send_i(2)<="0000" & MyPort; --propose sa propre adresse
451                                data_to_send_i(3)<=INIT_SEEKMAIN & MyPort ;
452                                DataLen_i<=4;
453                                BCast<='1';
454                               
455                                Result_En<='0';
456                                Initialized_i<='0';
457                                ram_wr<='0';
458                                rdy<='0';
459                                ResultOut<=(others=>'0');
460                                RankAsked_i<='0';
461                                dma_wr_request<='0';
462                When SeekMain2 =>    -- recherche de la lib main
463                                RTS_cmd<='0';
464                                RTS_I<='0';
465                                CTR<='1' ; -- prêt à recevoir les données Clear To Receive
466                                DS_ACK<= DS_RDY; --les données sont acquittées aussitôt reçues
467                                Send_Ack<=BCast_rdy;
468--                              data_to_send_i(0)<=INIT_SEEKMAIN & MyPort ;
469--                              data_to_send_i(1)<="00000011"; -- la longueur du packet =3
470--                              data_to_send_i(2)<="0000" & MyPort; --propose sa propre adresse
471--                              DataLen<=3;
472                                BCast<='0';                             
473                                Result_En<='0';
474                                Initialized_i<='0';
475                                ram_wr<='0';
476                                rdy<='0';
477                                ResultOut<=(others=>'0');
478                                EquFlag_i<='0';
479                                RankAsked_i<='0';
480                                dma_wr_request<='0';
481                When StoreMain =>     -- la Main Lib est une autre
482                                BCAST<='0';
483                                Result_En<='0';
484                                IsMain_i<='0';
485                                Initialized_i<='0';
486                                DS_ACK<=DS_RDY;
487                                Send_Ack<='0';
488                                RTS_cmd<='0';
489                                RTS_I<='0';
490                                CTR<=not(MainResp);  -- essayer de recevoir tant que le main n'a pas répondu
491                                ram_wr<='1';
492                                rdy<='0';
493                                ResultOut<=(others=>'0');
494                                RankAsked_i<='0';
495                                EquFlag_i<='0';
496                                MainPort_i<=DataReceived(0)(3 downto 0);
497                                ram_address<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
498                                ram_data_in<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
499                                dma_wr_request<= '0';  ---pas très sûr
500               
501                When AskPeerStat =>    -- Interroge les données d'initialisation
502                                RTS_cmd<='0';
503                                if n=0 then
504                                --RTS_DAT<='0'; --on peut envoyer les données
505                                RTS_I<='1';
506                                else
507                                  --RTS_DAT<='0'; --on désactive l'envoie des données
508                                  RTS_I<='0';
509                                 end if;
510                                CTR<='0' ; -- prêt à recevoir les données Clear To Receive
511                                DS_ACK<='0'; --les données sont attendus
512                                I_Send_Ack<=I_Send_rdy;
513                                Send_Ack<=Send_rdy;
514                                data_to_send_i(0)<=MPI_INIT & MainPort ;
515                                data_to_send_i(1)<="00000100"; -- la longueur du packet =4
516                                data_to_send_i(2)<="0000" & MyPort; --indique sa propre adresse
517                                data_to_send_i(3)<=INIT_STAT & MyPort ;
518                                DataLen_i<=4;
519                                BCast<='0';
520                                Result_En<='0';
521                                ram_wr<='0';
522                                rdy<='0';
523                                ResultOut<=(others=>'0');
524                                EquFlag_i<='0';
525                                RankAsked_i<='0';
526                                dma_wr_request<='0';
527                When SetMainFlag =>   -- Cette Lib est la Main Lib
528                                if (Datareceived(3)(7 downto 4) = INIT_SEEKMAIN) then 
529                                        RankAsked_i<='1';
530                                else 
531                                        RankAsked_i<='0';
532                                end if;
533                                RTS_cmd<='0';
534                                Initialized_i<='0';
535                      RTS_I<='0';
536                                BCast<='0';
537                                IsMain_i<='1';
538                                Result_En<='0';
539                                --MyRank<="0000";
540                                MainPort_i<="0000";
541                                PeerStat_i(0)<='1'; --la main lib est initialisée
542                                CTR<='1';
543                                DS_ACK<='0';
544                                ram_wr<='1';
545                                rdy<='0';
546                                ResultOut<=(others=>'0');
547                                EquFlag_i<='0';
548                                ram_address<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
549                                ram_data_in<=(others =>'0');  -- le port vaut 0 et la mainlib est aussi à 0
550                                dma_wr_request<='1';
551                When ReadNoc =>
552                                if (Datareceived(3)(7 downto 4) = INIT_SEEKMAIN) then
553                                        RankAsked_i<='1' ;
554                                else 
555                                        RankAsked_i<='0';
556                                end if;
557                                ram_wr<='0';  -- pas d'écriture en RAM
558                                rdy<='0';
559                                BCast<='0';
560                                DS_ACK<='0';
561                                --IsMain<='0';
562                                Result_En<='0';                 
563                                RTS_cmd<='0';
564                                RTS_I<='0';
565                                CTR<='1';
566                                ResultOut<=(others=>'0');
567                                PortNum_i<=DataReceived(2)(3 downto 0); -- le port qui demande un rang;
568                                PeerPort_i<= To_integer(unsigned(DataReceived(2)(3 downto 0)));
569                                --EquFlag<='1';
570                                dma_wr_request<='0';
571                When GetMainReq  =>
572                                --RankAsked_i<='1';
573                                ram_wr<='0';  -- pas
574                                BCast<='0';
575                                DS_ACK<='1';                           
576                                Result_En<='0';                         
577                                RTS_cmd<='0';
578                                RTS_I<='0';
579                                CTR<='1';
580                                ResultOut<=(others=>'0');
581                                PortNum_i<=DataReceived(0)(3 downto 0); -- le port qui demande un rang;
582                                EquFlag_i<='1';
583                                dma_wr_request<='0';
584                When GetPeerStat  =>
585                                --RankAsked_i<='1';
586                                ram_wr<='0';  -- pas
587                                BCast<='0';
588                                DS_ACK<=DS_RDY;
589                                Result_En<='0';
590                                RTS_cmd<='0';
591                                RTS_I<='0';
592                                CTR<=rd_ok;
593                                ResultOut<=(others=>'0');
594                                PortNum_i<=DataReceived(0)(3 downto 0); --adresse du Main Port
595                                PeerStat_i(7 downto 0)<=DataReceived(2); -- état des initialisations
596                                EquFlag_i<='0';
597                                dma_wr_request<=dma_wr;
598                                ram_wr<=wr_ok;
599                                rdy<='0';
600                                ram_rd<=rd_ok;
601                                Ram_Next_Address_i<= STD_logic_vector(to_unsigned(CORE_Init_Adr+2,ADRLEN)); --incr_vec(Ram_Next_Address,'1');
602                                ram_address<=Ram_Next_Address;  --
603                                ram_data_in<=DataReceived(2); --enregistrer les ports actifs
604                               
605                When NewRank =>
606                                nport:=to_integer(Unsigned(PortNum)); --port ayant sollicité le rang
607                                nextr_i<=to_integer(unsigned(nextrank));
608                                if PeerStat(nport)='0' then -- si le rang n'a pas encore été affecté à ce port
609                                nextrank_i<=incr_vec(nextrank,'1');
610                                RankToPort(to_integer(unsigned(nextrank)))<="0000" & PortNum;
611                                NextAdr:=NextAdr+1;
612                                end if;
613                                data_to_send_i(0)<=MPI_INIT & PortNum ;
614                                data_to_send_i(1)<="00000100";
615                                data_to_send_i(2)<="0000" & NextRank;  --ici c'est la valeur avant incrémentation !
616                                data_to_send_i(3)<=INIT_SETRANK & PortNum ;
617                                PeerStat_i(nport)<='1'; -- mise à jour du status
618                                DataLen_i<=4;
619                                BCast<='0';
620                                DS_ACK<='0';
621                                Result_En<='0';
622                                EquFlag_i<='1';
623                                RTS_cmd<='0';
624                                RTS_I<='1';
625                                CTR<='0' ;
626                                ram_wr<='0';
627                                rdy<='0';
628                                RankAsked_i<='1';
629                                ResultOut<=(others=>'0');
630                                dma_wr_request<='0';
631                               
632                When SendRank =>
633                                BCast<='0';
634                                Result_En<='0';
635                                EquFlag_i<='1';
636
637                                RTS_I<='1';
638                                DataLen_i<=4;
639                                RTS_cmd<='0';
640                                DS_ACK<='0';
641                                Send_Ack<='0';
642                                CTR<='0' ;
643                                ram_wr<='0';
644                                Ram_Next_Address_i<= STD_logic_vector(to_unsigned(CORE_RANK_ADR+Nextr-1,16));
645                                ResultOut<=(others=>'0');
646                                RankAsked_i<='1';
647                                dma_wr_request<='0';
648                When RegRank =>
649                                        RankAsked_i<='0';
650
651                                CTR<='1' ; -- continuer à recevoir les données du NoC
652                                Result_En<='0';
653                                RTS_cmd<='0';
654                                DS_ACK<='0';
655                                Send_Ack<=Send_RDY;
656                                I_Send_ack<=i_send_rdy;
657                                Rts_I<='0';
658                                BCast<='0';
659                                EquFlag_i<='1';
660                                ram_wr<='1';
661                               
662                                Ram_Next_Address_i<= STD_logic_vector(to_unsigned(CORE_RANK_ADR+Nextr-1,16)); --incr_vec(Ram_Next_Address,'1');
663                                ram_address<=Ram_Next_Address;  -- le rang qui a été envoyé;
664                                -- "le motif 0001 indique juste que le port est bien activé
665                                ram_data_in<="0001" & PortNum; --enregistrer le port qui a fait la demande en RAM
666                                ResultOut<=(others=>'0');
667                                dma_wr_request<='1';
668                When SendPeerStat =>
669                                BCast<='0';
670                                Result_En<='0';
671                                EquFlag_i<='0';
672                                RTS_I<=PeerRTS;
673                                RTS_cmd<='0';
674                                DS_ACK<='0';
675                                data_to_send_i(0)<=MPI_INIT & PortStat ;
676                                data_to_send_i(1)<="00000100";
677                                data_to_send_i(2)<=PeerStat(7 downto 0);
678                                data_to_send_i(3)<=INIT_REGISTER & MyPort ;
679                                Send_Ack<=Send_Rdy;
680                                I_Send_Ack<=I_Send_Rdy;
681                                CTR<='0' ;
682                                ram_wr<='0';
683                                rdy<='0';
684                                ResultOut<=(others=>'0');
685                                RankAsked_i<='1';
686                                dma_wr_request<='0';
687                                Initialized_i<='1';
688                When StoreRank => --le processus qui écoute le Port et qui
689                                                                --stoke les adresses des autres bib va gérer le stockage du rang
690                                BCAST<='0';
691                                DS_ACK<='1';
692                                Send_Ack<='0';
693                                RTS_cmd<='0';
694                                EquFlag_i<='0';
695                                RTS_I<='0';
696                                CTR<='0';
697                                Result_En<='0';
698                               
699                                if ExecTime_out='1' then
700                                MainPort_i<="0000";
701                                --MyRank<=MyPort;
702                                initialized_i<='0';
703                                else
704                                MainPort_i<=DataReceived(0)(3 downto 0);
705                                --MyRank<=DataReceived(2)(3 downto 0);
706                                Initialized_i<='1'; 
707                                end if;
708                                ram_wr<='1';
709                                --ram_address<=DataReceived(2);  -- le rang qui a été envoyé;
710                                ram_address<= STD_logic_vector(to_unsigned(Core_init_adr+1,16));
711                                ram_data_in<=DataReceived(0)(3 downto 0)& DataReceived(2)(3 downto 0);  --MainPort & MyRank
712                                ResultOut<=(others=>'0');
713                                RankAsked_i<='0';
714                                dma_wr_request<='1';
715                When SendApp =>  --ajouter du code pour recevoir l'adr du reg status
716                                Initialized_i<='1';
717                                ResultOut<="00000001"; -- Init Ok
718                                Result_En<='1';
719                                PortId<=MyPort;
720                                BCAST<='0';
721                                DS_ACK<='1';
722                                Send_Ack<='0';
723                                RTS_cmd<='0';
724                                RTS_I<='0';
725                                CTR<='0';
726                                ram_wr<='0';
727                                rdy<='0';
728                                RankAsked_i<='0';
729                                dma_wr_request<='0';
730                When SpawnApp =>
731                                RTS_cmd<='0';
732                                RTS_I<='0';
733                                Result_En<='0';
734                                DS_ACK<=DS_RDY;
735                                BCAST<='0';
736                                CTR<='0';  --cette mise à 1 permet de ctrler la fin de réception
737                                rdy<='0';
738                                ram_wr<=wr_ok;
739                                ram_rd<=rd_ok;
740                                Ram_Next_Address_i<= STD_logic_vector(to_unsigned(CORE_BASE_ADR,ADRLEN)); --incr_vec(Ram_Next_Address,'1');
741                                ram_address<=Ram_Next_Address;  -- le rang qui a été envoyé;
742                                -- "le motif 0001 indique juste que le port est bien activé
743                                ram_data_in<=DataToRam; --enregistrer le port qui a fait la demande en RAM
744                                dma_rd_request <= dma_rd;
745                                dma_wr_request <=dma_wr;
746                                RankAsked_i<='0';
747                                if n>=3 then
748                                        ResultOut<=("00000010");--spawn completed
749                                else
750                                        ResultOut<=("00000000");--spawn message received
751                                end if;
752                               
753                When SpawnLoad =>
754                    RTS_cmd<='0';
755                                --RTS_DAT<='1'; --à tester
756                                RTS_I<=PeerRTS; -- pour le timing
757                                Result_En<='0';
758                                DS_ACK<='0';
759                                BCAST<='0';
760                                CTR<='0';
761                                rdy<='0';
762                                ram_wr<=wr_ok;
763                                ram_rd<=rd_ok;
764                      data_to_send_i(0)<=SpawnCmd0;
765          data_to_send_i(1)<="00000100";
766          data_to_send_i(2)<=SpawnCmd1;
767          data_to_send_i(3)<=SpawnCmd2; -- SPAWN_LOAD & MyPort ;
768          Send_Ack<=Send_Rdy;
769                                I_Send_Ack<=I_Send_rdy;
770          RankAsked_i<='0';
771                                if SpawnInit='1' then
772                                        ResultOut<=("10000000"); --spawn completed
773                                else
774                                        ResultOut<=("01000000");--spawn in progress
775                                end if;
776                When ErrSpawn =>
777                                RTS_cmd<='0';
778                                RTS_I<='0';
779                                Result_En<='1';
780                                DS_ACK<='0';
781                                Send_Ack<='0';
782                                BCAST<='0';
783                                CTR<='0';
784                                ram_wr<='0';
785                                rdy<='0';
786                                RankAsked_i<='0';
787                               
788                                ResultOut<=(others=>'0');
789                                dma_wr_request<='0';
790                                dma_rd_request<='0';
791                When EndInit =>
792                                RTS_cmd<='0';
793                                RTS_I<='0';                             
794                                Result_En<='0';
795                                DS_ACK<='0';
796                                Send_Ack<='0';
797                                BCAST<='0';
798                                CTR<='0';
799                                ram_wr<='0';
800                                rdy<='0';
801                                RankAsked_i<='0';
802                                ResultOut<=(others=>'0');
803                                dma_wr_request<='0';
804                                dma_rd_request<='0';
805                end case;
806   end process;
807       
808result_proc:process (ISMain_i,Initialized_i,stInit2,reset,HCL_init)
809begin
810if reset='1' then
811        --IsMain1<='0';
812        Initialized<='0';
813        HCL_Init_i<='0';
814       
815Else
816        HCL_init_i<=HCl_init;
817        Initialized<=Hcl_init;
818--      if ismain_i='1' then
819--              IsMain1<='1';
820--      end if;
821
822        if Initialized_i='1' and stInit2=EndInit then
823                Initialized<='1';
824                HCL_Init_i<='1';
825        elsif stInit2=SendApp then
826          HCL_Init_i<='1';
827        end if;
828end if;
829end process result_proc;
830 --================
831 --Traitement du Spawn
832 --===================
833 
834 --==================
835   NEXT_STInit2_DECODE: process (stInit2,AppReq,Instruction_en, AppAck,PortNumFlag,EquFlag,MainResp,StatAsked,RankAsked,RankSent,CM_RDY, CmdReceived, 
836        BCast_Rdy, DS_RDY, DataReceived,Ht_Start,vPeerStat, Send_RDY,   I_Send_RDY,TimeOut,Dma_rd_grant,Dma_wr_grant,cpt,n,clk_cyl,IsMain1,SpawnOn,
837        Instruction,Hcl_Init,Spawn_done,mainport,PeerStat,PeerRTS,Rec_Data,SpawnInit,grp_id,Ram_data_out,Spawn_grp,MyPort,spawnNbreq_q,
838        Appsize1,portstat,spawncmd0_q,spawncmd1_q,spawncmd2_q,spawn_grp_q,SpawnReq_q,MyRank,ExecTime_out,peerport,portnum)
839   variable InitTimeOut :natural:=0;
840        variable LastPort,Ht_hole : std_logic:='0';
841        variable i,nbSpawn,htloc,Ht_Id : natural range 0 to 15:=0;
842        --variable vPeerStat : std_logic_vector(15 downto 0);
843   variable vPortStat,nulvect : std_logic_vector(3 downto 0):="0000";   
844        variable tempval : std_logic_vector(Word-1 downto 0);
845  begin
846      --declare default state for next_state to avoid latches
847      next_stInit2 <= stInit2;  --default is to stay in current state
848      --insert statements to decode next_state
849      --below is a simple example
850                vPeerStat_i<=vPeerStat;
851                SpawnNbReq<=SpawnNbReq_q;
852                StatAsked_i<=StatAsked;
853                MainResp_i<=MainResp;
854                AppSize_i<=AppSize1;
855                PortStat_i<=PortStat;
856                SpawnInit_i<=SpawnInit;
857                grp_id_i<=grp_id;
858                PeerRTS_i<=PeerRTS;
859                RankSent_i<=RankSent;
860                --PortNumFlag_i<=PortNumFlag;
861                SpawnReq<=SpawnReq_q;
862                Spawn_done_i<=Spawn_done;
863                Ht_Start_i<=Ht_Start;
864                SpawnCmd0<=SpawnCmd0_Q;
865                SpawnCmd1<=SpawnCmd1_Q;
866                SpawnCmd2<=SpawnCmd2_Q;
867                Timeout_i<=Timeout;
868                clk_cyl_i<=clk_cyl;
869                n_i<=n;
870                Cpt_peer<=cpt;
871                DataToRam<=(others=>'0');--A revoir
872                dma_rd<='0';
873                dma_wr<='0';
874                rd_ok<='0';
875                wr_ok<='0';
876                for i in 0 to 3 loop
877                Spawn_grp(i)<=Spawn_grp_q(i);
878                end loop;
879      case (stInit2) is
880         
881                       
882                When Init =>If Instruction_en='1' and AppReq='1'  then
883                                         If PortNumFlag='1'  and IsMain1='1' then
884                                                if instruction(7 downto 4)=INIT_SEEKMAIN and (instruction(3 downto 0)/=MyRank) then 
885                                                        Next_stInit2 <=NewRank;--affecter un rang au demandeur.
886                                                elsif instruction(7 downto 4)=INIT_STAT then
887                                                  StatASked_i<='1';
888                                                        Next_stInit2 <=SendPeerStat; --envoyer des stat au demandeur
889                                                elsif instruction(7 downto 4)=SPAWN_LOAD then
890                                                        SpawnInit_i<='0'; -- indique le debut du Spawn
891                                                        Next_stInit2 <=SpawnLoad; 
892                                                elsif instruction(7 downto 4)=INIT_SPAWN then
893                                                        SpawnInit_i<='1'; -- indique la fin du
894                                                        Next_stInit2 <=SpawnLoad; --dans ce cas il s'agit de terminer le spawn
895                                                else --ignorer ce message
896                                                        Next_stInit2 <=SendApp;
897                                                end if;
898                                         elsif HCL_Init='1' and IsMain1='0' then 
899                                                Next_stInit2 <=SendApp; --ignorer ce message simplement
900                                        else 
901                                                Next_stInit2 <=GetPortNum; -- initialiser la bibliothèque normalement
902                                        end if;
903                                        TimeOut_i<=0;PeerRTS_i<='0';
904                                       
905                                 elsif SpawnOn='1' and Spawn_done='0' then 
906                                        Next_stInit2 <=SpawnApp;
907                                        TimeOut_i<=0;
908                                 end if;
909                                cpt_peer<=0;LastPort:='0';n_i<=0;
910                When GetPortNum =>  -- récupérer le numéro du port
911                                                                                               
912                                                if CM_RDY='1' then 
913                                                        Next_stInit2 <=DecodeData;
914                                                end if;
915                                               
916                When DecodeData =>  -- cet état permet de lire les données reçues du port
917                                                        --if CM_RDY='1' then
918                                                                if ((Cmdreceived(2)(3 downto 0) or nulvect)=nulvect) then -- teste si le n° du port est zero
919                                                                  --EquFlag<='1';
920                                                                 else
921                                                                  --EquFlag<='0';
922                                                                end if;
923                                                               
924                                                                Next_stInit2 <=IsPortZero;
925                                                        --end if;
926                When IsPortZero => 
927                                                if PortNumFlag='1' then 
928                                               
929                                                End if;
930                                                if EquFlag='0'  then  --tester le numéro de port obtenu
931                                                        Next_stInit2 <=SeekMain1; -- chercher le numéro de port sur le réseau
932                                                else 
933                                                        Next_stInit2<=SetMainFlag; -- enregistrer le numéro de port
934                                                End If;
935                                                TimeOut_i<=0;
936               
937                When SeekMain1 =>If BCast_RDY='1' then  -- si tous les envois ont été postés
938                                                                        Next_stInit2<=SeekMain2;
939                                                        End if;                         
940                When SeekMain2 => 
941                                                        If DS_RDY='1' then  -- Si un jeu de données a été reçu
942                                                                                if (Datareceived(3)(7 downto 4) = INIT_SETRANK) then 
943                                                                                                MainResp_i<='1';
944                                                                                                Next_stInit2 <=StoreMain; -- de la librairie pricipale
945                                                                         else
946                                                                                                MainResp_i<='0';
947                                                                                                Timeout_i<=0;
948                                                                         end if;       
949                                                                               
950                                                        elsif (ExecTime_Out='1') then 
951                                                                       
952                                                                                                -- le Noc ne répond pas
953                                                                                                -- affecter un numéro en raport avec le port
954                                                                                Next_stInit2 <=SeekMain2;
955                                                        elsif TimeOut=800 then
956                                                                                                --essayer de redemander l'initialisation
957                                                                        assert true report "Ex4:seekmain ->redemander l'initialisation"
958                      severity failure;
959                                                                        Timeout_i<=0;                   
960                                                                        Next_stInit2 <=SeekMain1;
961                                                        else
962                                                                                Timeout_i<=TimeOut+1;
963                                                        End if;
964                                                       
965                                                         
966                                                         
967                When StoreMain =>
968                                if DataReceived(3)(7 downto 4)= INIT_SETRANK then
969                                -- enregistrer le Main Adresse et les adresses des autres processus
970                                -- dans la variable prévue à cet effet
971                                Next_stInit2 <=StoreRank;
972                               
973                                elsif Datareceived(3)(7 downto 4) = INIT_SEEKMAIN then 
974                                -- ignorer ce message
975                                Next_stInit2 <=StoreMain; --essayer de recevoir le rang
976                               
977                               
978                                end if;
979                                       
980                When StoreRank =>
981                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
982                                        -- la donnée ...
983                                        if dma_wr_grant = '1' then 
984                                                if clk_cyl=2 then --prévoir deux cycle d'horloge pour lire en RAM
985                                                        Next_stInit2 <=AskPeerStat;
986                                                        TimeOut_i<=0;
987                                                        clk_cyl_i<=0;
988                                                else 
989                                                        clk_cyl_i<=clk_cyl+1;
990                                                end if;
991                                        else
992                                                        Next_stInit2 <=StoreRank;
993                                                        TimeOut_i<=0;
994                                                        clk_cyl_i<=0;
995                                        end if;
996                When AskPeerStat =>if n=0 then 
997                        If I_SEND_RDY='1' then  -- si tous les envois ont été postés
998                                                                        n_i<=1;
999                                                                        StatAsked_i<='0';
1000                                                        End if;         
1001                                                elsif n=1 then 
1002                                                If I_SEND_RDY='0' then  -- si tous les envois ont été postés
1003                                                                        Next_stInit2<=GetPeerStat;
1004                                                                        StatAsked_i<='1';
1005                                                                        MainResp_i<='0';
1006                                                           n_i<=0;
1007                                                        End if;         
1008                                                end if;         
1009                When GetPeerStat => rd_ok<='0';
1010                                                        if n=0 then
1011                                                        rd_ok<='1';
1012                                                        If DS_RDY='1' then  -- Si un jeu de données a été reçu
1013                                                                         if (Datareceived(3) = INIT_REGISTER & MainPort ) then 
1014                                                                                                MainResp_i<='1';
1015                                                                                                n_i<=n+1;
1016                                                                                               
1017                                                                         else
1018                                                                                                MainResp_i<='0';
1019                                                                                                Timeout_i<=0;
1020                                                                                                n_i<=n;
1021                                                                         end if;       
1022                                                                               
1023                                                        elsif TimeOut=1800 then
1024                                                                                                --essayer de redemander les statistiques
1025                                                                        assert true report "Ex4:GetPeerStat timeout  ->Les statistiques n'ont pas été reçu"
1026                                                                        severity failure;
1027                                                                        Timeout_i<=0;   
1028                                                                        If StatAsked='1' then
1029                                                                        Next_stInit2 <=AskPeerStat; -- ceci n'est pas sûr
1030                                                                        else
1031                                                                        Next_stInit2 <=GetPeerStat;
1032                                                                        end if;
1033                                                        else
1034                                                                                Timeout_i<=TimeOut+1;
1035                                                        End if; 
1036                                                        elsif n=1 then  --écrire le résultat de l'initialisation
1037                                                        dma_wr<='1';
1038                                                        if dma_wr_grant='1' then
1039                                                                n_i<=n+1;
1040                                                                wr_ok<='1';
1041                                                        end if;
1042                                                        elsif n=2 then
1043                                                                n_i<=n+1;   --écriture dans la RAM
1044                                                        elsif n=3 then
1045                                                                n_i<=0;
1046                                                                dma_wr<='0';
1047                                                                Next_stInit2 <=SendApp; -- de la librairie pricipale
1048                                                        end if;
1049                When SetMainFlag =>
1050                                if dma_wr_grant='1' then   
1051                                                TimeOut_i<=0;
1052                                                Next_stInit2 <=ReadNoc;
1053                                        elsif Timeout=800 then
1054                                                assert true report "Ex4:SetMainFlag timeout  ->La mémoire n'est pas dispo dma_wr_grant=0"
1055                                                severity failure;
1056                                                Next_stInit2 <=SendApp;
1057                                        else
1058                                                TimeOut_i<=TimeOut+1;
1059--                                      end if; -- il est envisagée de terminer le programme à ce point
1060                                end if;
1061                when ReadNoc => if DS_RDY='1' then
1062                                                                        if (Datareceived(3)(7 downto 4) = INIT_STAT) then
1063                                                                                        StatAsked_i<='1' ;
1064                                                                                        Next_stInit2 <=SendPeerStat;
1065                                                                                        LastPort:='0';
1066                                                                        else 
1067                                                                                StatAsked_i<='0';
1068                                                                                Next_stInit2 <=GetMainReq;
1069                                                                        end if;
1070                                                                       
1071                                                                        Timeout_i<=0;
1072                                                                elsif Timeout=400 then
1073                                                                        assert true report "Ex4:ReadNoc timeout pas de données lues sur le NoC après 200 cycles"       
1074                                                                        severity failure;                                                         
1075                                                                        Timeout_i<=0;
1076                                                                        --if StatAsked = '1' then
1077                                                                                --Next_stInit2 <=ErrSpawn; --il y a eu une erreur
1078                                                                                Next_stInit2 <=SendApp;
1079                                                                --      else
1080                                                                        --      Next_stInit2 <=SendPeerStat;
1081                                                                --      end if;
1082                                                                else
1083                                                                        TimeOut_i<=TimeOut+1;
1084                                                                end if; 
1085                               
1086                When GetMainReq => if RankAsked='1' and PeerStat(PeerPort)='0' then
1087                                                                        Next_stInit2 <=NewRank; -- un nouveau rang est demandé
1088                                                                else
1089                                                                        Next_stInit2 <=ReadNoC; -- sinon essayer encore de lire un jeu de données.
1090                                                                end if;
1091                When NewRank =>
1092                                Next_stInit2 <=SendRank;
1093                When SendRank =>
1094                                        if I_Send_RDY='1' then  --RankSent
1095                                                Next_stInit2 <=RegRank;
1096                                                RankSent_i<='1';  -- le rang a été envoyé
1097                                                TimeOut_i<=0;   -- prépare le traitement de la prochaine requête
1098                                                                                                -- d'attente des ports
1099                                  elsif Timeout=800 then
1100                                    assert true report "Impossible d'envoyer le rang"
1101                                    severity failure;
1102                                    timeout_i<=0;
1103                                  else 
1104                                    TimeOut_i<=TimeOut+1; 
1105                                        end if;
1106                When RegRank =>
1107                                        --il faut prévoir du code pour s'assurer que la RAM a bien enregistrer
1108                                        -- la donnée ...
1109                                        if dma_wr_grant = '1' then 
1110--                                                      if DS_RDY='1' then
1111                                                                RankSent_i<='0';
1112                                                                if DS_RDY='0' then
1113                                                                 
1114                                                                        Next_stInit2 <=ReadNoc;
1115                                                                end if;
1116                                                        elsif Timeout=800 then
1117                                                                Next_stInit2 <=SendApp;
1118                                                                assert true report "Ex4:RegRank Timeout dma_wr_grant=0 "
1119                                    severity failure;
1120                                                        else
1121                                                                TimeOut_i<=TimeOut+1;
1122--                                                      end if; -- il est envisagée
1123                                        end if;
1124                                        --calcul de la taille de l'appli
1125                                        HtLoc:=0;
1126                                        for i in 0 to 7 loop
1127                                                if peerStat(i)='1' then --trouve le prochai rang libre
1128                                                        HtLoc:=HtLoc+1;
1129                                                end if;
1130                                        end loop;
1131                                        AppSize_i<=std_logic_vector(to_unsigned(HtLoc,4));
1132               
1133                When SendPeerStat =>
1134                                       
1135                                        if cpt<=unsigned(NoCMax)and LastPort='0' then
1136                                                if peerRts='0' then -- pas encore envoyer les données alors les préparer
1137                                                                if StatAsked='1' then 
1138                                                                       
1139                                                                        PortStat_i<=PortNum;
1140                                                                        vPortStat:=std_logic_vector(to_unsigned(PeerPort,4));
1141                                                                else
1142                                                                        PortStat_i<=std_logic_vector(to_unsigned(cpt,4));--Port à contacter
1143                                                                        vPortStat:=std_logic_vector(to_unsigned(cpt,4));
1144                                                                end if;
1145                                                               
1146                                                                if StatAsked='1' then 
1147                                                                        LastPort:='1';  -- on traite u seul port celui qui en a fait la demande
1148                                                                        if PeerStat(PeerPort)='1' then
1149                                                                        PeerRts_i<='1';
1150                                                                        end if;
1151                                                                else
1152                                                                        if (PeerStat(cpt)='1') and not(vPortStat=MyPort) then
1153                                                                                PeerRts_i<='1';
1154                                                                        end if;
1155                                                                        if cpt<unsigned(NoCMax) then 
1156                                                                                cpt_peer<=cpt+1;
1157                                                                                LastPort:='0';
1158                                                                        else
1159                                                                                if LastPort='0' then
1160                                                                                                LastPort:='1';
1161                                                                                                cpt_peer<=cpt+1;--ceci permet de déclencher l'évaluation du process
1162                                                                                end if;
1163                                                                        end if;
1164                                                                end if;
1165                                                                TimeOut_i<=0;
1166                                        else
1167                                                        if I_Send_RDY='1' then 
1168                                                                               
1169                                                                                RankSent_i<='1';        -- les stat ont été envoyé
1170                                                                                TimeOut_i<=0;           -- prépare le traitement de la prochaine requête
1171                                                                                PeerRts_i<='0';                                                                         -- d'attente des ports
1172                                                          elsif TimeOut=800 then
1173                                                                        Next_stInit2 <=EndInit ;-- impossible d'envoyer sur le NoC
1174                                                           assert true report "Ex4:SendPeerStat Timeout -> Impossible d'envoyer sur le NoC"
1175                                        severity failure;
1176                                                          else
1177                                                                        TimeOut_i<=TimeOut+1; 
1178                                                        end if;
1179                                        end if;
1180                                        elsif PeerRTS='1' then -- le dernier port est il activé ?
1181                                                if I_Send_RDY='1' then 
1182                                                                RankSent_i<='1';        -- les stat ont été envoyé
1183                                                                                TimeOut_i<=0;           -- prépare le traitement de la prochaine requête
1184                                                                                PeerRts_i<='0';
1185                                                        if statAsked='1' then 
1186                                                         -- Next_stInit2<=ReadNoc;
1187                                                       
1188                                                        Next_stInit2<=SendApp; --terminer l'application
1189                                                  end if;
1190                                               
1191                                                elsif TimeOut=100 then
1192                                                        Next_stInit2 <=EndInit;
1193                                                        assert true report "Ex4:SendPeerStat Timeout -> Impossible d'envoyer sur le NoC"
1194                                        severity failure;
1195                                                else 
1196                                                        TimeOut_i<=TimeOut+1; 
1197                                                end if;
1198                                        else
1199                                                Next_stInit2<=SendApp;
1200                                        end if;
1201                When SendApp =>  -- envoyer au programme un signal
1202                                        -- et attendre un acquittement et l'adresse de base
1203                                        If AppAck='1' then
1204                                                Next_stInit2 <=EndInit;
1205                                        end if;
1206               
1207                When SpawnLoad =>
1208               
1209                                if n=0 then
1210                                        ht_id:=to_integer(unsigned(rec_data(0)(3 downto 0)));
1211                                        vPeerStat_i<=PeerStat; --récupérer la situation actuelle des tâches créées
1212                                        if IsMain1='1' and SpawnInit='0' then 
1213                                         SpawnNbReq<=to_integer(unsigned(Instruction(3 downto 0))); -- sauver le nombre de HT à créer
1214 
1215                                        n_i<=1;
1216                                        SpawnReq(ht_id)<='1'; --Note l'id de HT qui a appelé le Spawn
1217                                        elsif IsMain1='1' and SpawnInit='1'  then -- il faut envoyer les acquittements
1218                                        ht_id:=to_integer(unsigned(rec_data(0)(3 downto 0)));
1219                                        Spawn_grp(grp_id)(ht_id)<='1'; --noter le port du Fils Spawné dans ce groupe
1220                                        Ht_start_i<=0; --compte le nombre de tâches chargées
1221                                                        n_i<=6;
1222                                       
1223                                        else 
1224                                           if SpawnOn='1' then --if IsMain_i='0' then  -- il faut juste charger puis activer la tâche
1225                                             n_i<=7;
1226                                            end if;
1227                                            assert true
1228                                           Report "SpawnLoad : Cas non prévu !"
1229                                          severity failure;
1230                                        end if;
1231                                elsif n=1 then
1232                                if PeerStat=SpawnReq_q then --tous les Hts ont appelés Spawn ?
1233                                ht_hole:='0';           
1234        L1:                     for i in 0 to 15 loop
1235                                                if vPeerStat(i)='0' then
1236                                                        SpawnDest<=std_logic_vector(to_unsigned(i,4)); -- le port à activer
1237                                                        SpawnCmd0<=MPI_SPAWN & std_logic_vector(to_unsigned(i,4));
1238                                                        vPeerStat_i(i)<='1';
1239                                                        Ht_Start_i<=Ht_Start+1;
1240                                                        Ht_Hole:='1'; -- une place a été trouvé
1241                                                else
1242                                                        Ht_hole:='0'; -- pas de place trouvé
1243                                                end if;
1244                                                exit L1 when ht_hole='1';
1245                                        end loop L1;
1246                                        if Ht_hole='0' then -- toutes les tâches n'ont pas été créés
1247                                                -- aller à la fin ! en signalant une erreur!
1248                                                SpawnCMd2<=Spawn_Err & "0001"; --erreur pas assez de ports sur le NoC
1249                                                n_i<=9;
1250                                        else
1251                                                n_i<=n+1;
1252                                                SpawnCmd1<=PeerStat(7 downto 0);
1253                                                SpawnCmd2<=SPAWN_START & MyPort;
1254                                        end if;
1255                                        else --Tous les Hts n'ont pas appelé Spawn encore
1256                                          Next_stInit2<=SendApp; --on termine normalement
1257                                          n_i<=0;
1258                                        end if;
1259                                elsif n=2 then
1260                                PeerRTS_i<='1'; -- envoyer les données du Spawn
1261                                n_i<=n+1;
1262                                elsif n=3 then
1263                                        if I_Send_RDy='1' then
1264                                                n_i<=n+1;
1265                                                PeerRts_i<='0';
1266                                        end if;
1267                                elsif n=4 then
1268                                        if SpawnInit='0' then
1269                                        if Ht_Start>=SpawnNbReq_q then
1270                                                n_i<=n+1;
1271                                        else
1272                                                n_i<=1; -- passer à la création du HT suivant
1273                                        end if;
1274                                        else
1275                                                n_i<=7; -- passer au contact du HT suivant
1276                                        end if;
1277                                elsif n=5 then
1278                                                                -- Aller à la fin le résultat du Spawn
1279                               
1280                                n_i<=10;
1281                                elsif n=6 then
1282                                  nbSpawn:=0;
1283                                  for i in 0 to 15 loop
1284                                      if Spawn_grp(grp_id)(i)='1' then
1285                                         nbSpawn:=nbSpawn+1;
1286                                       end if;
1287                                   end loop;
1288                                  if nbSpawn=SpawnNbReq_q then
1289                                  n_i<=n+1; --aller renvoyer les réponses
1290                                  else
1291                                    n_i<=10; --fin du Spawn
1292                                   
1293                                   end if;
1294                                elsif n=7 then
1295                                Ht_hole:='0';
1296L2:                     for i in 0 to 7 loop --for i in Ht_start to 7 loop
1297                                                if i>=Ht_start then
1298                                                if vPeerStat(i)='1' and Spawn_grp(grp_id)(i)='0' then  --on avertit les membres du groupe parent
1299                                                  --mais pas ceux du groupe Fils !
1300                                                        SpawnDest<=std_logic_vector(to_unsigned(i,4)); -- le port à avertir
1301                                                        SpawnCmd0<=MPI_ACK & std_logic_vector(to_unsigned(i,4));
1302                                                        vPeerStat_i(i)<='0';
1303                                                        Ht_Start_i<=i+1; -- le prochain Ht à prévenir
1304                                                        Ht_Hole:='1'; -- Une tâche doit être avertie
1305                                                else
1306                                                        Ht_hole:='0'; --
1307                                                end if;
1308                                                end if;
1309                                                exit L2 when ht_hole='1';
1310                                        end loop L2;
1311                                        n_i<=n+1;
1312                        elsif n=8 then
1313                                 if Ht_hole='1' then --
1314                                                -- un HT existant à prévenir !
1315                                                SpawnCmd1<=Spawn_grp(grp_id)(7 downto 0);
1316                                                SpawnCMd2<=MPI_SPAWN & MyRank; -- fin du Spawn
1317                                                n_i<=2; --envoyer la  donnée sur le réseau
1318                                        elsif vpeerstat /=spawn_grp(grp_id) then --il ne reste plus de membres à prévenir ?
1319              n_i<=7; --on est sorti mais ce n'est pas la fin
1320
1321                                        else -- fin du Spawn car tous ont été averti
1322                                                n_i<=10;
1323                                                SpawnNbReq<=0;
1324                                                SpawnReq<=(others=>'0');
1325                                                vPeerStat_i<=(others=>'0');
1326                                                grp_id_i<=grp_id+1; --incrementer le compteur de groupes************
1327                                        end if;
1328                                elsif n=9 then
1329                                  assert true report "error in Spawn command"
1330                                   severity failure;
1331                                elsif n=10 then
1332                                  n_i<=0;
1333                                  Next_stInit2<=SendApp;
1334                                 end if;
1335               
1336        When SpawnApp=>
1337                --Mise à jour du bit 6 du registre status du COre.
1338                if n>=0 and n <4 then     
1339                       
1340                        dma_wr<='1';  --demander un accès exclusif au bus
1341                        dma_rd<='1'; -- pour éviter une mauvaise mise à jour des données
1342                else
1343                        dma_wr<='0';                                                                           
1344                        dma_rd<='0';
1345                end if;
1346               
1347                if n=0 then
1348                  if DS_RDY='1' then ---
1349                      if Datareceived(3)(7 downto 4)=SPAWN_START then
1350                        n_i<=n+1;
1351                       else
1352                         Next_stInit2<=ErrSpawn;
1353                         n_i<=0; --erreur instruction incorrecte
1354                        end if;
1355                           
1356                           rd_ok<='1';
1357                           wr_ok<='0';
1358                        end if;
1359                elsif n=1 or n=2 then
1360                        if dma_rd_grant='1' then
1361                                n_i<=n+1;
1362                                tempval:=Ram_data_out;
1363                        end if;
1364                                rd_ok<='1';
1365                                wr_ok<='0';
1366                         
1367                elsif n=3 then
1368                                if dma_rd_grant='1' and dma_wr_grant='1' then
1369                                        n_i<=n+1;
1370                                        tempval:=Ram_data_out;
1371                                        tempval(6):='1';       
1372                                                       
1373                                        dataToram<=tempval;
1374                                        rd_ok<='0';
1375                                        wr_ok<='1';
1376                                else
1377                                        rd_ok<='1';
1378                                        wr_ok<='0';
1379                                end if;
1380                elsif n=4 then
1381                if spawninit='0' then
1382                  Spawn_done_i<='1';
1383                end if;
1384                rd_ok<='0';
1385                wr_ok<='0';
1386                n_i<=0;
1387                Next_stInit2<=EndInit;
1388                end if;
1389                       
1390                When ErrSpawn =>
1391                  assert true
1392                  report "Ex4/stInit2/SpawnApp:Erreur lors de Spawn"
1393                  severity failure;
1394                        Next_stInit2<=Init;
1395                When EndInit=>
1396                 
1397                        StatAsked_i<='0'; --reset de ces variables
1398                        Next_stInit2<=Init;
1399      end case;     
1400   end process;
1401       
1402--================================================
1403--sauvegarde du rang et du main port à l'adresse de retour de la fonction Init
1404--==================================================
1405
1406--====================================================
1407--envoie des données sur le port
1408--===================================================
1409selector<=(Rcv_on,Cmd_on,Snd_on);
1410
1411process (selector,Rport_out_rd_en,cport_out_rd_en,sPort_in_wr_en ,cPort_in_wr_en,
1412                                tosend ,tosend4)
1413begin
1414   case selector is
1415       
1416      when "000" => port_in_data<=(others=>'-');
1417                                                Port_in_wr_en<='0';
1418                                                Port_out_rd_en<='0';
1419     
1420                when "001" => port_in_data<=tosend; --envoie de données
1421                                                Port_in_wr_en<=sPort_in_wr_en ;
1422                                                Port_out_rd_en<='0';
1423      when "101" => port_in_data<=tosend; --envoie de données
1424                                                Port_in_wr_en<=sPort_in_wr_en ;
1425                                                Port_out_rd_en<=Rport_out_rd_en ;
1426                when "010" | "110" | "011" | "111" => 
1427                                                port_in_data<=tosend4; --envoie de commande GetPort
1428                                                Port_in_wr_en<=cPort_in_wr_en;
1429                                                Port_out_rd_en<=cport_out_rd_en;
1430     
1431          when "100" => port_in_data<=(others=>'-'); -- réception de données
1432                                                Port_in_wr_en<='0';
1433                                                Port_out_rd_en<=Rport_out_rd_en ;
1434     
1435                when others => port_in_data<=(others=>'-');
1436                                                        Port_in_wr_en<='0';                                                     
1437                                                        Port_out_rd_en<='0';
1438   end case;
1439end process;
1440 
1441--==================================================   
1442       
1443        --===============================================================
1444        --processus d'accès au réseau
1445        --===============================================================
1446
1447
1448
1449
1450
1451        preceiv:process(clk,reset)
1452       
1453        variable origport,destport : natural range 0 to 15;
1454        variable dcount,dlen ,rtimeout:natural range 0 to 1023;
1455        variable ptype : std_logic_vector(3 downto 0);
1456        variable bad_paquet :std_logic:='0';
1457        begin
1458--                             
1459       
1460        if reset='1' then
1461                etrec<=r_wait;
1462                destport:=1;
1463                rtimeout:=0;
1464                bad_paquet:='0';
1465                spawnon<='0';
1466        else
1467        if  rising_edge(clk) then 
1468                        case  etrec is
1469                        when r_wait =>
1470                               
1471                                rtimeout:=0;
1472                                bad_paquet:='0';       
1473                                --modifier le 01-08-pour gérer le Spawn
1474                        if Port_out_data_available='1' and Cmd_on='0' then 
1475                                ptype:=port_out_data(7 downto 4);
1476                                origport:=to_integer(unsigned(port_out_data(3 downto 0)));
1477                               
1478                                if ptype=MPI_SPAWN and not(portnumflag='1') then
1479                                                etrec<=r_dlen; --identification de la signature d'en tête valide
1480                                                Datareceived(0)<=Port_out_data; --stocker l'entête
1481                                                bad_paquet:='0';
1482                                                SpawnOn<='1'; --le spawn est actif
1483                                elsif Instruction_en='0' and CTR='0' and Hcl_init= '0' then
1484                                  --il faut éliminer ce paquet qui est inoportun !
1485                                  Bad_paquet:='1';
1486                                  etrec<=r_glen; --il faut ignorer cette donnée et quitter
1487                                        dcount:=1;
1488                                elsif CTR='1' then
1489                                if ptype=MPI_INIT or ptype=INIT_SETRANK or ptype=INIT_SEEKMAIN or ptype=INIT_REGISTER then 
1490                                                etrec<=r_dlen; --identification de la signature d'en tête valide
1491                                                Datareceived(0)<=Port_out_data; --stocker l'entête
1492                                                bad_paquet:='0';
1493                                else
1494                                        --une donnée non attendue est présente sur le port
1495                                        etrec<=r_dlen; --il faut ignorer cette donnée et quitter
1496                                        dcount:=1;
1497                                        bad_paquet:='1';
1498                                        Datareceived(0)<=(others=>'0');
1499                                end if;
1500                                end if;
1501                        --elsif Port_out_data_available='1' and CTR='0' then
1502                        --              etrec<=r_drop;
1503                        else
1504                               
1505                                etrec<=r_wait;
1506                        end if;
1507                        DS_RDY<='0';
1508                        When r_drop => -- ignorer les messages qui arrivent à ce noeud tant que
1509                                                                --l'application n'a pas été initialisée
1510                                                if port_out_data_available='0' then 
1511                                                        etrec<=r_end;
1512                                                        dcount:=0;
1513                                                       
1514                                                end if;
1515                                               
1516                                               
1517                                               
1518                                                --Rport_out_rd_en<='1'; --lire les données qui sont dans le tampon de sortie           
1519                                                DS_RDY<='0';
1520                        when r_Dlen =>   --positionnement du mot de longueur des données
1521                        if Port_out_data_available ='1' then 
1522                       
1523                        --Rport_out_rd_en<='1';
1524                        etrec<=r_glen;
1525                        rtimeout:=0;
1526                        else
1527                                rtimeout:=rtimeout+1;
1528                                        if rtimeout>=30 then 
1529                                          assert true report "Ex4:etrec r_glen Timeout -> Impossible de recevoir du NoC"
1530                                        severity failure;
1531                                        Exectime_out<='0';  --read Noc time out
1532                                                etrec<=r_end;             -- données pas prêtes
1533                                        end if;
1534                       
1535                       
1536                        end if;
1537                        DS_RDY<='0';
1538                        -- 
1539                        when r_glen =>   --lecture effective de la longueur des données
1540                        if port_out_data_available='1' then 
1541                        dlen:=to_integer(unsigned(port_out_data(Word-1 downto 0)));
1542                        Datareceived(1)<=Port_out_data;
1543                        --RPort_out_rd_en<='0';
1544                        etrec<=r_data;
1545                        dcount:=2;  -- initialisation du compteur de reception (il y a
1546                                                        -- déjà deux mots reçues
1547                        else
1548                                rtimeout:=rtimeout+1;
1549                                        if rtimeout>=30 then 
1550                                         assert true report "Ex4:etrec Timeout -> Impossible de recevoir sur le NoC"
1551                                        severity failure;
1552                                        ExecTime_out<='0';
1553                                                etrec<=r_end;             -- données pas prêtes
1554                                        end if;
1555                       
1556                        end if;
1557                        DS_RDY<='0';
1558                        when r_data =>                                          -- lecture des données
1559                        if port_out_data_available='1'  then 
1560                                       
1561                                        --Rport_out_rd_en<='1';   --autoriser la lecture
1562                                        if bad_paquet='0' then
1563                                                DataReceived(dcount)<=Port_out_data; --récupération des données
1564                                        else
1565                                                DataReceived(2)<=(others=>'0');
1566                                          --ignorer ces données
1567                                        end if;
1568                                        --assert true report "Donnée lue :"; --& string(unsigned(port4_out(Word-1 downto 0)))
1569                                        DS_RDY<='0';
1570                                        dcount:=dcount+1;
1571                                        --severity note;
1572                                        if dlen <=dcount then -- ce doit être égale ici et non <= ???
1573                                                etrec<=r_end;
1574                                                DS_RDY<= not bad_paquet; -- jeu de données disponibles
1575                                        elsif dcount=255 then   --dépassement de la capacité
1576                                                DS_RDY<='0';
1577                                                etrec<=r_end;
1578                                        end if;
1579                        else
1580                                        rtimeout:=rtimeout+1;
1581                                        if rtimeout>=30 then 
1582                                           ExecTime_out<='0';
1583                                                etrec<=r_end;             -- données pas prêtes
1584                                        end if;
1585                                        DS_RDY<='0';
1586                                       
1587                        end if;
1588                        when r_pulse =>
1589                                        etrec<=r_end; 
1590                                        DS_RDY<=not bad_paquet;
1591                        when r_end =>
1592                                               
1593                        --rPort_out_rd_en <='0';
1594                       
1595                        if DS_ACK='1' or rtimeout> 30 or (CTR='0' and SpawnOn='0') or bad_paquet='1' then 
1596                                DS_RDY<='0';
1597                                SpawnOn<='0';
1598                                etrec<=r_wait;
1599                        else
1600                                DS_RDY<=DS_RDY;
1601                        end if;                 
1602                        end case;
1603                 end if;--reset='1'
1604                end if;   
1605  end process preceiv;
1606 
1607 val_preceiv: process (etrec)
1608  begin
1609  case etrec is
1610                                        when r_wait  =>
1611--                                              DS_RDY<='0';
1612                                                rcv_on<='0';
1613                                                Rport_out_rd_en <='0';
1614                                        when r_dlen  =>
1615--                                                      DS_RDY<='0';
1616                                                        Rport_out_rd_en <='1';
1617                                                        rcv_On<='1';
1618                                        when r_drop  =>
1619--                                                      DS_RDY<='0';
1620                                                        Rport_out_rd_en <='1';
1621                                                        rcv_On<='1';
1622                                        when r_glen =>
1623                                                        Rport_out_rd_en <='1';
1624--                                                      DS_RDY<='0';
1625                                                        rcv_On<='1';
1626                                        when r_data =>
1627                                                        Rport_out_rd_en <='1';
1628--                                                      DS_RDY<='0';
1629                                                        rcv_On<='1';
1630                                        when r_pulse =>
1631                                                                Rport_out_rd_en <='0';
1632                                                                rcv_On<='1';
1633--                                                              DS_RDY<='1';
1634                                        when r_end =>
1635                                                        Rport_out_rd_en <='0';
1636--                                                      DS_RDY<='0';
1637                                                        rcv_On<='0';
1638                                        when others =>
1639                                                        Rport_out_rd_en <='0';
1640--                                                      DS_RDY<='0';
1641                                                        rcv_On<='0';
1642                                end case;
1643        end process;
1644 
1645  psend:process(clk,reset)
1646                --génération des paquets à partir du  port courant
1647                variable pactype :natural range 0 to 15;
1648                variable destport : natural range 0 to 15:=0;
1649                variable realdlen, i,i_pair : natural range 0 to 255;
1650                variable MaxPort : natural :=4; -- en fait ne doit pas être 0
1651               
1652               
1653                                begin
1654                                if rising_edge(clk) then 
1655                                                 if reset='1' then 
1656                                                                etsnd<=s_init;
1657                                 
1658                                   
1659                                                 
1660                                                else -- le process s'exécute sur chaque front
1661                                                                                                                        -- montant de l'horloge
1662                                                case etsnd is
1663                                                when s_init => tosend<=(others=>'-');
1664                                                                                        MaxPort :=to_integer(unsigned(NOCMAX));
1665                                                                sPort_in_wr_en<='0';
1666                                                                BCast_RDY<='0';  -- pas la fin de du Broadcasting
1667                                                                Send_RDY<='0';
1668                                                        if port_in_full='0' and Rts_dat='1' then   --on peut aussi tester si le port est vide
1669                                               
1670                                                                          Snd_on<='1';
1671                                                                          if Bcast='1' then -- envoyer à tous les ports le même message ?
1672                                                                          DestPort :=0;
1673                                                                          else
1674                                                                                DestPort:=to_integer(unsigned(data_to_send(0)(3 downto 0)));
1675                                                                          end if;
1676                                                                          etsnd<=s_head;
1677                                                        end if;
1678                                                when s_head  =>    -- construction et envoie de l'en-tête
1679                                                Send_RDY<='0'; --l'envoi commence
1680                                                BCast_RDY<='0';
1681                                                Snd_on<='1';
1682                                                --pactype:=to_integer(MPI_INIT);--
1683                                                pactype:=to_integer(unsigned(data_to_send(0)(7 downto 4)));
1684                                                --realdlen:=to_integer(unsigned(Datalen));
1685                                                --? destport:=MAXPORT; -- le port de destination
1686                                               
1687                                                tosend <=STD_LOGIC_VECTOR(to_unsigned(pactype,4)) & STD_LOGIC_VECTOR(to_unsigned(destport,4));
1688                                                 sPort_in_wr_en<='1';   --
1689                                                 
1690                                                 i:=1;
1691                                                 etsnd<=s_len2;  -- passer à l'état suivant
1692                                                 
1693                                                when s_len => 
1694                                                        BCast_RDY<='0';
1695                                                        Send_RDY<='0';
1696                                                        Snd_on<='1';
1697                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(Realdlen,8)));
1698                                                        tosend<=data_to_send(1);
1699                                                        sPort_in_wr_en <='1';
1700                                                       
1701
1702                                                        --port1_in<=tosend1; --copie directe sur le port
1703                                                        etsnd<=s_len2;
1704                                                when s_len2 => 
1705                                                        --tosend<=(STD_LOGIC_VECTOR(to_unsigned(realdlen,8)));
1706                                                        sPort_in_wr_en<='1';
1707                                                        tosend<=data_to_send(1);
1708
1709                                                        --port1_in<=tosend1; --copie directe sur le port
1710                                                        etsnd<=s_data; 
1711                                                        BCast_RDY<='0';
1712                                                        Send_RDY<='0';
1713                                                        Snd_on<='1';
1714                                                        i:=i+1;
1715                                                when s_data =>
1716                                                        Snd_on<='1';
1717                                                        if Port_in_full='0' and RTS_dat='1' then
1718                                                                sPort_in_wr_en<='1';
1719                                                               
1720                                                                     --envoie des données sur le port   
1721                                                                        tosend<=data_to_send(i);
1722                                                               
1723                                                               
1724                                                                if i+1>=datalen then 
1725                                                                        etsnd<=s_end;
1726                                                                        Send_RDY<='1'; --l'envoi est terminé
1727                                                                        if BCast='1' and destport=MAXPort then
1728                                                                                BCAST_RDY<='1'; --l'envoi collectif aussi
1729                                                                        else 
1730                                                                                BCast_RDY<='0';
1731                                                       
1732                                                                        end if;
1733                                                                else
1734                                                                        BCast_RDY<='0';
1735                                                                        Send_RDY<='0';
1736                                                                        i:=i+1;
1737                                                                end if;
1738                                                        elsif port_in_full='1' then
1739                                                                sPort_in_wr_en<='0';
1740                                                        else
1741                                                                sPort_in_wr_en<='0';
1742                                                                BCast_RDY<='0';
1743                                                                Send_RDY<='0';
1744                                                        end if;
1745                                                when s_end  =>
1746                                                 tosend<=(others=>'-');
1747                                                       
1748                                                        sPort_in_wr_en<='0';
1749                                                        if Bcast='1' then
1750                                                             if destPort<Maxport then
1751                                                                        DestPort:=Destport+1;
1752                                                                        etsnd<=s_head;
1753                                                                        BCast_RDY<='0';
1754                                                                    else
1755                                                                        BCast_RDY<='1' ; -- BroadCast End=Ok
1756                                                                               if Send_ack='1' then
1757                                                                                        etsnd<=s_init;
1758                                                                                        Send_RDY<='0';
1759                                                                                        Snd_on<='0';
1760                                                                               end if;
1761                                                       
1762                                                                    end if;
1763                                                        else
1764                                                                    BCast_RDY<='0';
1765                                                                    if Send_ack='1' then
1766                                                                             etsnd<=s_init;
1767                                                                             Send_RDY<='0';
1768                                                                             Snd_on<='0';
1769                                                                    end if;
1770                                                               
1771                                                        end if;
1772                                                end case;       
1773                                               
1774                                                                               
1775                                                end if;  --reset ='1'
1776                                        end if; --rising_edge...
1777                end process psend;     
1778
1779-- envoi des commandes         
1780pcmd:process(clk,reset)
1781       
1782        variable origport,destport,pid,mport : natural range 0 to 15;
1783        variable ctimeout:natural range 0 to 255;
1784        begin
1785       
1786       
1787                if reset='1' then
1788                        etcmd<=cmdstart;
1789                       
1790        --              sorigport<=origport;
1791                else
1792                if  rising_edge(clk) then
1793                                        case  etcmd is
1794                                        when cmdstart =>
1795                                                if Port_in_empty='1' and RTS_Cmd='1' then 
1796                                                                        etcmd<=cmdpost;
1797                                               
1798                                                end if;
1799                                                destport:=0;
1800                                                ctimeout:=0;
1801                                                origport:=1;
1802                                                dcount<=0;
1803                                 when cmdpost =>
1804                                        if Port_in_empty='1' then 
1805                                                etcmd<=cmdread;
1806                                        end if;
1807                                       
1808                                when cmdpostidle  =>   --permet juste la prise en compte de la commande
1809                                                etcmd<=cmdread;
1810                                                dcount<=0;-- initialisation du compteur de reception
1811                                 when cmdread =>
1812                                               
1813                                               
1814                                                ctimeout:=0;
1815                                               
1816                                        if Port_out_data_available='1' then 
1817                                                mport:=to_integer(unsigned(port_out_data(7 downto 4)));
1818                                                pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
1819                                                CmdReceived(dcount)<=port_out_data;
1820                                                --cdata_out_en(origport)<='1';
1821--                                              if pid=origport then --le port a été bien identifié
1822                                                                etcmd<=cmdglen; --
1823                                                                dcount<=dcount+1;
1824--                                                      else
1825--                                                      etcmd<=cmdtimeout;
1826--                                              end if;
1827                                        else
1828
1829                                                etcmd<=cmdread;
1830                                        end if;
1831                                       
1832                                       
1833                                        when cmdlen =>   --positionnement du mot de longueur des données
1834                                        if Port_out_data_available='1' then 
1835                                       
1836                                        etcmd<=cmdglen;
1837                                        ctimeout:=0;
1838                                        else
1839                                                ctimeout:=ctimeout+1;
1840                                                        if ctimeout>=30 then 
1841                                                          assert true report "Ex4:etcmd Timeout -> impossible de recevoir du le NoC"
1842                                        severity failure;
1843                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1844                                                        end if;
1845                                       
1846                                       
1847                                        end if;
1848                                        when cmdglen =>   --lecture effective de la longueur des données
1849                                        if Port_out_data_available='1' then 
1850                                                cdlen<=to_integer(unsigned(port_out_data(Word-1 downto 0)));
1851                                                CmdReceived(dcount)<=port_out_data;
1852                                                etcmd<=cmddata;
1853                                          dcount<=dcount+1;
1854                                        else
1855                                                ctimeout:=ctimeout+1;
1856                                                        if ctimeout>=30 then 
1857                                                        --time_out(destport)<='1';
1858                                                         assert true report "Ex4:etcmd Timeout -> impossible de recevoir du le NoC"
1859                                        severity failure;
1860                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1861                                                        end if;
1862                                       
1863                                        end if;
1864                                       
1865                                        when cmddata =>
1866                                        if (port_out_data_available='1' and ctimeout<30) then 
1867                                                       
1868                                                        --cdata_out_en(origport)<='1';
1869                                                        mport:=to_integer(unsigned(port_out_data(7 downto 4)));
1870                                                        --attention les ports sont numérotés à partir de 0
1871                                                        pid:=to_integer(unsigned(port_out_data(3 downto 0)))+1;
1872                                                        CmdReceived(dcount)<=port_out_data;
1873                                                        if (dcount>=cdlen-1 ) then--attention le compteur de données commence à 0
1874                                                                etcmd<=cmdend;
1875                                                                --CM_RDY<='1';
1876                                                        else
1877                                                                dcount<=dcount+1;
1878                                                        end if;                 
1879                                        Else
1880                                                       
1881                                                        if ctimeout>=30 then 
1882                                                                --time_out(destport)<='1';
1883                                                                etcmd<=cmdtimeout;             -- données pas prêtes
1884                                                         assert true report "Ex4:etcmd. cmddata Timeout -> impossible de recevoir du le NoC"
1885                                        severity failure;
1886                                                        else
1887                                                        ctimeout:=ctimeout+1;
1888                                                        etcmd<=cmdend;
1889                                                        end if;
1890                                        end if;
1891                                        when cmdend =>
1892                               
1893                                                        etcmd<=cmdstart;
1894
1895                                        when cmdtimeout =>
1896
1897                                          etcmd<=cmdstart;
1898                                        end case;
1899                --sorigport<=origport; 
1900                end if;   --reset='1'
1901        end if;
1902  end process pcmd;     
1903
1904majetcmd: process (etcmd,data_to_send, port_out_data_available, dcount,port_out_data)
1905variable origport : natural;
1906variable i:natural:=0;
1907        begin
1908                        case  etcmd is
1909                when cmdstart =>
1910                                i:=0;
1911                                Port_in_cmd_en<='0';
1912                                tosend4<=(others=>'-');
1913                                cport_out_rd_en<='0';
1914                                cport_in_wr_en<='0';
1915                                CM_RDY<='0';
1916                                Cmd_on<='0';
1917                 when cmdpost | cmdpostidle =>
1918                                cport_in_wr_en<='1';
1919                                tosend4<=data_to_send(0); ---code pour getportid
1920                                Port_in_cmd_en<='1';
1921                                cport_out_rd_en<='0';
1922                                CM_RDY<='0';
1923                                Cmd_on<='1';
1924                 when cmdread =>
1925                                tosend4<=(others=>'-');
1926                                cPort_in_wr_en<='0';
1927                                cport_out_rd_en<=port_out_data_available;
1928                                --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1929                                Port_in_cmd_en<='1';
1930                                CM_RDY<='0';
1931                                Cmd_on<='1';
1932                when cmdlen |cmdglen =>   --positionnement du mot de longueur des données
1933                                        tosend4<=(others=>'-');
1934                                        cport_in_wr_en<='0';
1935                                        cport_out_rd_en<=port_out_data_available;
1936                                        Port_in_cmd_en<='1';
1937                                        --CmdReceived(dcount)<= port_out_data;
1938                                        CM_RDY<='0';
1939                                        Cmd_on<='1';
1940                when cmddata =>
1941                                        tosend4<=(others=>'-');
1942                                        cport_in_wr_en<='0';
1943                                        cport_out_rd_en<=Port_out_data_available;
1944                                        Port_in_cmd_en<='1';
1945                                        --CmdReceived(dcount)<=port_out_data;  --mettre les données dans le tampon
1946                                        i:=i+1;
1947                                        CM_RDY<='0';
1948                                        Cmd_on<='1';
1949                        when cmdend =>
1950                                        tosend4<=(others=>'-');
1951                                cport_in_wr_en<='0';
1952                                cport_out_rd_en<='0';
1953                                --CmdReceived(dcount)<=port_out_data;
1954                                Port_in_cmd_en<='0';
1955                            CM_RDY<='1';
1956                                 Cmd_on<='0';
1957                        when cmdtimeout =>
1958                                        tosend4<=(others=>'-');
1959                                  cport_in_wr_en<='0';
1960                                  cport_out_rd_en<='0';
1961                                  Port_in_cmd_en<='0';
1962                                        Cmd_on<='1';
1963                                        cm_rdy<='0';
1964                        end case;
1965               
1966end process majetcmd ; 
1967snd_start<=snd_start_q;
1968i_send_val:process(et_sendproc,snd_start_q,HCL_Init,Send_RDY,RTS_I,Snd_Ack,I_send_ack,data_to_send,Bcast_rdy,Bcast)
1969begin
1970snd_start_i<=snd_start_q;
1971RTS_DAT<='0';
1972case et_sendproc is
1973when Hcl_Init_off =>
1974  if RTS_I='1' and i_send_ack='0' then
1975  RTS_DAT<='1';
1976 elsif i_send_ack='1' then
1977 
1978 RTS_DAT<='0';
1979 end if;
1980 i_send_rdy<=send_rdy;
1981 for i in 0 to 3 loop 
1982 Snd_data(i)<=(others=>'0');
1983 end loop;
1984When Hcl_Init_on =>
1985if RTS_I='1' and snd_ack='0' then
1986  snd_start_i<='1';
1987 elsif i_send_ack='1' then
1988 
1989 snd_start_i<='0';
1990 else
1991   snd_start_i<='0';
1992 end if;
1993 i_send_rdy<=snd_ack;
1994  Snd_data<=data_to_send;
1995end case; 
1996end process;
1997mae_send:process(clk,reset)
1998begin
1999  if reset='1' then 
2000    et_sendproc<=Hcl_init_off;
2001  elsif rising_edge(clk) then
2002   
2003if HCL_Init='1' then
2004  et_sendproc<=Hcl_init_on;
2005else
2006   et_sendproc<=Hcl_init_off;
2007end if;
2008end if;
2009end process;
2010end Behavioral;
2011
Note: See TracBrowser for help on using the repository browser.