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

Last change on this file was 148, checked in by rolagamo, 10 years ago

A jour

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