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