OpenCores
URL https://opencores.org/ocsvn/saturn/saturn/trunk

Subversion Repositories saturn

[/] [saturn/] [trunk/] [FPGA Concentrateur SIL4/] [fpga_cosil4/] [con_communication_sil4.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 DavidRAMBA
--============================================================================= 
2
--  TITRE : CON_COMMUNICATION_SIL4
3
--  DESCRIPTION : 
4
--        Implémente la pile communication SATURN       coté concentrateur      
5
--  FICHIER :        con_communication_sil.vhd 
6
--=============================================================================
7
--  CREATION 
8
--  DATE              AUTEUR    PROJET  REVISION 
9
--  10/04/2014  DRA        SATURN       V1.0 
10
--=============================================================================
11
--  HISTORIQUE  DES  MODIFICATIONS :
12
--  DATE              AUTEUR    PROJET  REVISION
13
--  27/04/15   DRA      SATURN   V1.1
14
--     Augmentation des FIFO fifo_tx pour permettre au pic de stocker
15
--     d'avantage de trames de commande.
16
--=============================================================================
17
 
18
LIBRARY IEEE;
19
USE IEEE.STD_LOGIC_1164.ALL;
20
USE IEEE.STD_LOGIC_ARITH.ALL;
21
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
22
 
23
ENTITY con_communication_sil4 IS
24
   PORT (
25
      -- Ports système
26
      clk_sys  : IN  STD_LOGIC;                    -- Clock système
27
      rst_n    : IN  STD_LOGIC;                    -- Reset général système
28
      baudrate : IN  STD_LOGIC_VECTOR(2 DOWNTO 0); -- Baudrate en mdoe maitre
29
      actif    : IN  STD_LOGIC;                    -- Indique que le concentrateur est actif
30
      ad_con   : IN  STD_LOGIC_VECTOR(7 DOWNTO 0); -- Addresse logique du concentrateur (TID)
31
      top_cycle: IN  STD_LOGIC;                    -- TOP de synchro de début de cycle
32
      ena_filt_dble : IN STD_LOGIC;                -- Autorise le filtrage des trames en double
33
 
34
      -- Interfaces séries 1 et 2
35
      rx1      : IN  STD_LOGIC;                    -- Réception série port 1 
36
      tx1      : OUT STD_LOGIC;                    -- Transmission série port 1
37
      rx2      : IN  STD_LOGIC;                    -- Réception série port 2
38
      tx2      : OUT STD_LOGIC;                    -- Transmission série port 2
39
 
40
      copy_ena1: IN  STD_LOGIC;                    -- Autorise la recopie du port 1 sur le port 2
41
      copy_ena2: IN  STD_LOGIC;                    -- Autorise la recopie du port 2 sur le port 1
42
 
43
      -- Interfaces de lecture des trames port 1 côté µC1
44
      filt_rx1_uc1   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Données applicatives reçues sur port 1
45
      filt_soc1_uc1  : OUT STD_LOGIC;           -- Indique un début de trame
46
      filt_rd1_uc1   : IN  STD_LOGIC;           -- Signal de lecture d'un octet de plus
47
      filt_comdispo1_uc1 : OUT STD_LOGIC;       -- Indique qu'au moins une trame est dispo en mémoire
48
      layer7_newframe1 : OUT STD_LOGIC;         -- Indique la réception d'une nouvelle trame
49
      layer7_l2ok1     : OUT STD_LOGIC;         -- Indique que la trame reçue est conforme
50
      layer7_overflow1 : OUT STD_LOGIC;         -- Indique un débordement de mémoire
51
      -- Interfaces de lecture des trames port 2 côté µC1
52
      filt_rx2_uc1   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Idem port 1
53
      filt_soc2_uc1  : OUT STD_LOGIC;
54
      filt_rd2_uc1   : IN  STD_LOGIC;
55
      filt_comdispo2_uc1 : OUT STD_LOGIC;
56
      layer7_newframe2 : OUT STD_LOGIC;
57
      layer7_l2ok2     : OUT STD_LOGIC;
58
      layer7_overflow2 : OUT STD_LOGIC;
59
      -- Interfaces de lecture des trames port 1 côté µC1
60
      filt_rx1_uc2   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Données applicatives reçues sur port 1
61
      filt_soc1_uc2  : OUT STD_LOGIC;           -- Indique un début de trame
62
      filt_rd1_uc2   : IN  STD_LOGIC;           -- Signal de lecture d'un octet de plus
63
      filt_comdispo1_uc2 : OUT STD_LOGIC;       -- Indique qu'au moins une trame est dispo en mémoire
64
      -- Interfaces de lecture des trames port 2 côté µC1
65
      filt_rx2_uc2   : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Idem port 1
66
      filt_soc2_uc2  : OUT STD_LOGIC;
67
      filt_rd2_uc2   : IN  STD_LOGIC;
68
      filt_comdispo2_uc2 : OUT STD_LOGIC;
69
 
70
      -- Interfaces de lecture des trames reçues sur le port 1 pour le PCIe
71
      data_storerx1  : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données
72
      val_storerx1   : OUT STD_LOGIC;              -- Validant du bus data
73
      sof_storerx1   : OUT STD_LOGIC;              -- Début de trame
74
      eof_storerx1   : OUT STD_LOGIC;              -- Fin de trame
75
      crcok_storerx1 : OUT STD_LOGIC;              -- CRC ok pour la trame reçue
76
 
77
      -- Interfaces de lecture des trames reçues sur le port 2 pour le PCIe
78
      data_storerx2  : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Idem quepour port 1
79
      val_storerx2   : OUT STD_LOGIC;
80
      sof_storerx2   : OUT STD_LOGIC;
81
      eof_storerx2   : OUT STD_LOGIC;
82
      crcok_storerx2 : OUT STD_LOGIC;
83
 
84
      -- Interface d'écriture des trames côté µC1
85
      txdat_free       : OUT STD_LOGIC;         -- Indique que le module couche transport Tx est dispo
86
      acq_stuf         : OUT STD_LOGIC;         -- Indique que la commande d'envoi des caractères 7Fh est terminée
87
 
88
      tx_dat_uc1       : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données applicatives à transmettre
89
      val_txdat_uc1    : IN  STD_LOGIC;         -- Indique un octet dispo sur tx_dat
90
      tx_sof_uc1       : IN  STD_LOGIC;         -- Indique un début de trame
91
      tx_eof_uc1       : IN  STD_LOGIC;         -- Indique une fin de trame
92
      clr_fifo_tx_uc1  : IN  STD_LOGIC;         -- Clear de la FIFO transport Tx
93
      stuf_phys_uc1    : IN  STD_LOGIC;         -- Pour envoyer des caractères de controle 7Fh
94
      tx_available_uc1 : IN  STD_LOGIC;         -- Signale au module de communication qu'une trame est en attente d'émission
95
      tx_commena_uc1   : OUT STD_LOGIC;         -- Autorise l'émission de la trame en attente
96
 
97
      -- Interface d'écriture des trames côté µC2
98
      tx_dat_uc2       : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données applicatives à transmettre
99
      val_txdat_uc2    : IN  STD_LOGIC;         -- Indique un octet dispo sur tx_dat
100
      tx_sof_uc2       : IN  STD_LOGIC;         -- Indique un début de trame
101
      tx_eof_uc2       : IN  STD_LOGIC;         -- Indique une fin de trame
102
      clr_fifo_tx_uc2  : IN  STD_LOGIC;         -- Clear de la FIFO transport Tx
103
      stuf_phys_uc2    : IN  STD_LOGIC;         -- Pour envoyer des caractères de controle 7Fh
104
      tx_available_uc2 : IN  STD_LOGIC;         -- Signale au module de communication qu'une trame est en attente d'émission
105
      tx_commena_uc2   : OUT STD_LOGIC;         -- Autorise l'émission de la trame en attente
106
 
107
      -- Trames UC1 et UC2 Tx multiplexées vers la passerelle
108
      tx_dat_pas       : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
109
      val_txdat_pas    : OUT STD_LOGIC;
110
      tx_sof_pas       : OUT STD_LOGIC;
111
      tx_eof_pas       : OUT STD_LOGIC
112
      );
113
END con_communication_sil4;
114
 
115
ARCHITECTURE rtl of con_communication_sil4 is
116
   -- Définit le nombre de bit nécessaires pour mesurer la durée du bit le plus lent avec l'horloge système
117
   -- i.e. 1 Bit à 50Kbit/s = 20µs nbbit_div = Log2(96MHz x 20µs)
118
   CONSTANT nbbit_div      : INTEGER := 11;
119
   CONSTANT freq_clk       : INTEGER := 96;     -- clk_sys = 96MHz
120
 
121
   -- DFF pour la métastabilité de rx1 et rx2
122
   SIGNAL rx1_r1, rx1_r2   : STD_LOGIC;
123
   SIGNAL rx2_r1, rx2_r2   : STD_LOGIC;
124
 
125
   -- Diviseur d'horloge pour le baud rate
126
   SIGNAL tc_divclk        : STD_LOGIC_VECTOR(nbbit_div - 1 DOWNTO 0);  -- Diviseur multiplexé selon le mode
127
   SIGNAL divclk_autobaud  : STD_LOGIC_VECTOR(nbbit_div - 1 DOWNTO 0);  -- diviseur déterminé par la fonction d'autobaud
128
   SIGNAL baud_locked      : STD_LOGIC;                  -- Indique que l'algo d'autobaud a convergé
129
 
130
   -- Interfaces du SWITCH1
131
   SIGNAL layer1_rx1    : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de donnée brut reçu sur Rx1
132
   SIGNAL layer1_val1   : STD_LOGIC;                     -- Validant du flux ded onnée sur Rx1
133
   SIGNAL sw_ena1       : STD_LOGIC;                     -- Indique qu'on est entre 2 trames en réception
134
   SIGNAL layer1_tx1    : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de donnée brut à transmettre sur Tx1
135
   SIGNAL layer1_rd1    : STD_LOGIC;                     -- Demande un octet de plus à transmettre sur Tx1
136
   SIGNAL layer1_empty1 : STD_LOGIC;                     -- Indique que la FIFO de transmission sur Tx1 est vide
137
 
138
   -- Interfaces du SWITCH2
139
   SIGNAL layer1_rx2    : STD_LOGIC_VECTOR(7 DOWNTO 0);     -- Idem que pour le port 1
140
   SIGNAL layer1_val2   : STD_LOGIC;
141
   SIGNAL sw_ena2       : STD_LOGIC;
142
   SIGNAL layer1_tx2    : STD_LOGIC_VECTOR(7 DOWNTO 0);
143
   SIGNAL layer1_rd2    : STD_LOGIC;
144
   SIGNAL layer1_empty2 : STD_LOGIC;
145
 
146
   -- Interfaces du module layer2_rx1_pic
147
   SIGNAL layer2_rx1_pic    : STD_LOGIC_VECTOR(7 DOWNTO 0); -- Flux de données destuffé port 1
148
   SIGNAL layer2_rxval1_pic : STD_LOGIC;
149
   SIGNAL layer2_sof1_pic   : STD_LOGIC;
150
   SIGNAL layer2_eof1_pic   : STD_LOGIC;
151
   SIGNAL layer2_l2ok1_pic  : STD_LOGIC;
152
   SIGNAL dont_keep1        : STD_LOGIC;
153
 
154
   -- Interfaces du module layer2_rx2_pic
155
   SIGNAL layer2_rx2_pic    : STD_LOGIC_VECTOR(7 DOWNTO 0); -- Flux de données destuffé port 2
156
   SIGNAL layer2_rxval2_pic : STD_LOGIC;
157
   SIGNAL layer2_sof2_pic   : STD_LOGIC;
158
   SIGNAL layer2_eof2_pic   : STD_LOGIC;
159
   SIGNAL layer2_l2ok2_pic  : STD_LOGIC;
160
   SIGNAL dont_keep2        : STD_LOGIC;
161
 
162
   -- Interfaces du module FRAME_STORE1
163
   SIGNAL layer7_rx1       : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données
164
   SIGNAL layer7_soc1      : STD_LOGIC;            -- Indique un début de trame
165
   SIGNAL layer7_rd1       : STD_LOGIC;            -- Signal de elcture d'un octet de plus
166
   SIGNAL layer7_comdispo1 : STD_LOGIC;            -- Indique qu'au moins une trame est dispo
167
   SIGNAL overflow_store1  : STD_LOGIC;            -- Indique qu'une trame n'a pas pu être stockée
168
   SIGNAL overflow_filter1 : STD_LOGIC;            -- Overflow de l'algo de filtrage doubletrame coté 1
169
 
170
   -- Interfaces du module FRAME_STORE2
171
   SIGNAL layer7_rx2       : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données
172
   SIGNAL layer7_soc2      : STD_LOGIC;            -- Indique un début de trame
173
   SIGNAL layer7_rd2       : STD_LOGIC;            -- Signal de elcture d'un octet de plus
174
   SIGNAL layer7_comdispo2 : STD_LOGIC;            -- Indique qu'au moins une trame est dispo
175
   SIGNAL overflow_store2  : STD_LOGIC;            -- Indique qu'une trame n'a pas pu être stockée
176
   SIGNAL overflow_filter2 : STD_LOGIC;            -- Overflow de l'algo de filtrage doubletrame coté 2
177
 
178
   -- Interfaces du module LAYER2_TX
179
   SIGNAL layer2_txdat     : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux ded onnée applicatif à transmettre
180
   SIGNAL layer2_txval     : STD_LOGIC;
181
   SIGNAL layer2_progfull1 : STD_LOGIC;                     -- FIFO Tx1 presque pleine
182
   SIGNAL layer2_progfull2 : STD_LOGIC;                     -- FIFO Tx2 presque pleine
183
   SIGNAL layer2_full1     : STD_LOGIC;                     -- FIFO Tx1 pleine
184
   SIGNAL layer2_full2     : STD_LOGIC;                     -- FIFO Tx2 pleine
185
   SIGNAL txdat_free_buf   : STD_LOGIC;                     -- Indique que le module Tx est dipo pour prendre une donnée
186
 
187
   -- Signaux de multiplexage des écritures des trames Tx par les 2 PIC
188
   SIGNAL mux_tx       : STD_LOGIC;         -- '0' pour sélectionner le PIC1 comme émetteur, '1' pour le PIC2
189
   SIGNAL tx_encours   : STD_LOGIC;         -- indique qu'une FIFO Tx d'un des PIC est en cours de transfert
190
   SIGNAL tx_dat       : STD_LOGIC_VECTOR(7 DOWNTO 0);  -- Flux de données applicatives à transmettre
191
   SIGNAL val_txdat    : STD_LOGIC;         -- Indique un octet dispo sur tx_dat
192
   SIGNAL tx_sof       : STD_LOGIC;         -- Indique un début de trame
193
   SIGNAL tx_eof       : STD_LOGIC;         -- Indique une fin de trame
194
   SIGNAL clr_fifo_tx  : STD_LOGIC;         -- Clear de la FIFO transport Tx
195
   SIGNAL stuf_phys    : STD_LOGIC;         -- Emissiond es octets de stuffing
196
 
197
        COMPONENT autobaud
198
        PORT(
199
                clk_sys     : IN STD_LOGIC;
200
                rst_n       : IN STD_LOGIC;
201
                rx1         : IN STD_LOGIC;
202
                val_rx1     : IN STD_LOGIC;
203
                eof1        : IN STD_LOGIC;
204
                dat_rx1     : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);
205
      l2_ok1      : IN STD_LOGIC;
206
                rx2         : IN STD_LOGIC;
207
                val_rx2     : IN STD_LOGIC;
208
                eof2        : IN STD_LOGIC;
209
                dat_rx2     : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);
210
      l2_ok2      : IN STD_LOGIC;
211
                tc_divclk   : OUT STD_LOGIC_VECTOR(10 downto 0);
212
                baud_locked : OUT STD_LOGIC
213
                );
214
        END COMPONENT;
215
 
216
        COMPONENT switch
217
   GENERIC (
218
      nbbit_div : INTEGER := 10);
219
        PORT(
220
                clk_sys     : IN STD_LOGIC;
221
                rst_n       : IN STD_LOGIC;
222
      baud_lock   : IN  STD_LOGIC;
223
                tc_divclk   : IN STD_LOGIC_VECTOR(nbbit_div-1 downto 0);
224
                rx          : IN STD_LOGIC;
225
                rx_dat      : OUT STD_LOGIC_VECTOR(7 downto 0);
226
                rx_val      : OUT STD_LOGIC;
227
                tx          : OUT STD_LOGIC;
228
                tx_dat      : IN STD_LOGIC_VECTOR(7 downto 0);
229
                tx_rd       : OUT STD_LOGIC;
230
                tx_empty    : IN STD_LOGIC;
231
                sw_ena      : IN STD_LOGIC;
232
                copy_ena    : IN STD_LOGIC
233
                );
234
        END COMPONENT;
235
 
236
        COMPONENT con_layer2_rx
237
   GENERIC (
238
      nbbit_div : INTEGER := 10);
239
        PORT(
240
                clk_sys     : IN STD_LOGIC;
241
                rst_n       : IN STD_LOGIC;
242
      ad_con      : IN  STD_LOGIC_VECTOR(7 DOWNTO 0);
243
                sw_ena      : OUT STD_LOGIC;
244
                dat_in      : IN STD_LOGIC_VECTOR(7 downto 0);
245
                val_in      : IN STD_LOGIC;
246
                tc_divclk   : IN STD_LOGIC_VECTOR(nbbit_div-1 downto 0);
247
      sof_pic     : OUT  STD_LOGIC;
248
      eof_pic     : OUT  STD_LOGIC;
249
      l2_ok_pic   : OUT  STD_LOGIC;
250
      dat_out_pic : OUT  STD_LOGIC_VECTOR(7 downto 0);
251
      val_out_pic : OUT  STD_LOGIC;
252
      sof_pas     : OUT  STD_LOGIC;
253
      eof_pas     : OUT  STD_LOGIC;
254
      l2_ok_pas   : OUT  STD_LOGIC;
255
      dat_out_pas : OUT  STD_LOGIC_VECTOR(7 downto 0);
256
      val_out_pas : OUT  STD_LOGIC
257
                );
258
        END COMPONENT;
259
 
260
        COMPONENT frame_store
261
        PORT(
262
                clk_sys     : IN STD_LOGIC;
263
                rst_n       : IN STD_LOGIC;
264
                dat_in      : IN STD_LOGIC_VECTOR(7 downto 0);
265
                val_in      : IN STD_LOGIC;
266
                sof         : IN STD_LOGIC;
267
                eof         : IN STD_LOGIC;
268
                l2_ok       : IN STD_LOGIC;
269
                dat_out     : OUT STD_LOGIC_VECTOR(7 downto 0);
270
      soc_out     : OUT STD_LOGIC;
271
                rd_datout   : IN STD_LOGIC;
272
                new_frame   : OUT STD_LOGIC;
273
                com_dispo   : OUT STD_LOGIC;
274
                l7_ok       : OUT STD_LOGIC;
275
      overflow    : OUT STD_LOGIC
276
                );
277
        END COMPONENT;
278
 
279
   COMPONENT filter_dbl_frame_sil4 IS
280
   PORT (
281
      clk_sys              : IN STD_LOGIC;
282
      rst_n                : IN STD_LOGIC;
283
      top_cycle            : IN  STD_LOGIC;
284
      ena_filt_dble        : IN  STD_LOGIC;
285
      data_port1           : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
286
      soc_port1            : IN STD_LOGIC;
287
      com_dispo1           : IN STD_LOGIC;
288
      rd_port1             : OUT STD_LOGIC;
289
      data_port2           : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
290
      soc_port2            : IN STD_LOGIC;
291
      com_dispo2           : IN STD_LOGIC;
292
      rd_port2             : OUT STD_LOGIC;
293
      data_filt1_uc1       : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
294
      soc_filt1_uc1        : OUT STD_LOGIC;
295
      frm_dispo_filt1_uc1  : OUT STD_LOGIC;
296
      rd_filt1_uc1         : IN  STD_LOGIC;
297
      data_filt2_uc1       : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
298
      soc_filt2_uc1        : OUT STD_LOGIC;
299
      frm_dispo_filt2_uc1  : OUT STD_LOGIC;
300
      rd_filt2_uc1         : IN  STD_LOGIC;
301
      data_filt1_uc2       : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
302
      soc_filt1_uc2        : OUT STD_LOGIC;
303
      frm_dispo_filt1_uc2  : OUT STD_LOGIC;
304
      rd_filt1_uc2         : IN  STD_LOGIC;
305
      data_filt2_uc2       : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
306
      soc_filt2_uc2        : OUT STD_LOGIC;
307
      frm_dispo_filt2_uc2  : OUT STD_LOGIC;
308
      rd_filt2_uc2         : IN  STD_LOGIC;
309
      dpram_overflow1      : OUT STD_LOGIC;
310
      dpram_overflow2      : OUT STD_LOGIC
311
      );
312
   END COMPONENT;
313
 
314
   COMPONENT con_layer2_tx
315
   PORT(
316
      clk_sys     : IN STD_LOGIC;
317
      rst_n       : IN STD_LOGIC;
318
      stuf_phys   : IN  STD_LOGIC;
319
      acq_stuf    : OUT STD_LOGIC;
320
      dat_in      : IN STD_LOGIC_VECTOR(7 downto 0);
321
      val_in      : IN STD_LOGIC;
322
      sof         : IN STD_LOGIC;
323
      eof         : IN STD_LOGIC;
324
      datin_free  : OUT STD_LOGIC;
325
      dat_out     : OUT STD_LOGIC_VECTOR(7 downto 0);
326
      val_out     : OUT STD_LOGIC;
327
      clr_fifo    : IN   STD_LOGIC;
328
      progfull1   : IN   STD_LOGIC;
329
      progfull2   : IN   STD_LOGIC;
330
      full1       : IN   STD_LOGIC;
331
      empty1      : IN   STD_LOGIC;
332
      full2       : IN   STD_LOGIC;
333
      empty2      : IN   STD_LOGIC
334
      );
335
   END COMPONENT;
336
 
337
   COMPONENT fifo_tx
338
   PORT (
339
      clk      : IN STD_LOGIC;
340
      srst     : IN STD_LOGIC;
341
      din      : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
342
      wr_en    : IN STD_LOGIC;
343
      rd_en    : IN STD_LOGIC;
344
      dout     : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
345
      full     : OUT STD_LOGIC;
346
      empty    : OUT STD_LOGIC;
347
      prog_full: OUT STD_LOGIC
348
      );
349
   END COMPONENT;
350
 
351
BEGIN
352
   --------------------------------------------
353
   -- Gestion de la métastbilité de rx1 et rx2
354
   --------------------------------------------
355
   meta : PROCESS(clk_sys, rst_n)
356
   BEGIN
357
      IF (rst_n = '0') THEN
358
         rx1_r1 <= '1';
359
         rx1_r2 <= '1';
360
         rx2_r1 <= '1';
361
         rx2_r2 <= '1';
362
      ELSIF (clk_sys'EVENT and clk_sys = '1') THEN
363
         rx1_r1 <= rx1;
364
         rx1_r2 <= rx1_r1;
365
         rx2_r1 <= rx2;
366
         rx2_r2 <= rx2_r1;
367
      END IF;
368
   END PROCESS;
369
 
370
   --------------------------------------------
371
   -- Sélection du baud rate fixé par registre ou autobaudrate
372
   --------------------------------------------
373
   mux_baud : PROCESS(clk_sys)
374
   BEGIN
375
      IF (clk_sys'EVENT and clk_sys = '1') THEN
376
         IF (actif = '1') THEN
377
         -- Si le concentrateur est maitre
378
            CASE baudrate IS
379
            -- LE baudrateest défini par registre
380
               WHEN "000" =>
381
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/50-1, tc_divclk'length);
382
               WHEN "001" =>
383
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/100-1, tc_divclk'length);
384
               WHEN "010" =>
385
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/200-1, tc_divclk'length);
386
               WHEN "011" =>
387
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/500-1, tc_divclk'length);
388
               WHEN "100" =>
389
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/1000-1, tc_divclk'length);
390
               WHEN "101" =>
391
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/2000-1, tc_divclk'length);
392
               WHEN "110" =>
393
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/6000-1, tc_divclk'length);
394
               WHEN "111" =>
395
                  tc_divclk <= CONV_STD_LOGIC_VECTOR(freq_clk*1000/12000-1, tc_divclk'length);
396
               WHEN OTHERS =>
397
                  NULL;
398
            END CASE;
399
         ELSE
400
         -- Si le cocentrateur n'est pas maitre
401
            tc_divclk <= divclk_autobaud;       -- C'est l'autobaud qui définit le baudrate
402
         END IF;
403
      END IF;
404
   END PROCESS;
405
 
406
        inst_autobaud: autobaud
407
   PORT MAP(
408
                clk_sys =>  clk_sys,
409
                rst_n =>    rst_n,
410
                rx1 =>      rx1_r2,
411
                rx2 =>      rx2_r2,
412
                val_rx1 =>  layer1_val1,
413
                dat_rx1 =>  layer1_rx1,
414
      eof1 =>     layer2_eof1_pic,
415
                l2_ok1 =>   layer2_l2ok1_pic,
416
                val_rx2 =>  layer1_val2,
417
      dat_rx2 =>  layer1_rx2,
418
                eof2 =>     layer2_eof2_pic,
419
                l2_ok2 =>   layer2_l2ok2_pic,
420
                tc_divclk => divclk_autobaud,
421
                baud_locked => baud_locked
422
        );
423
 
424
        inst_switch1: switch
425
   GENERIC MAP (
426
      nbbit_div => nbbit_div)
427
   PORT MAP(
428
                clk_sys =>     clk_sys,
429
                rst_n =>       rst_n,
430
      baud_lock =>   baud_locked,
431
                tc_divclk =>   tc_divclk,
432
                rx =>          rx1_r2,
433
                rx_dat =>      layer1_rx1,
434
                rx_val =>      layer1_val1,
435
                tx =>          tx2,
436
                tx_dat =>      layer1_tx2,
437
                tx_rd =>       layer1_rd2,
438
                tx_empty =>    layer1_empty2,
439
                sw_ena =>      sw_ena1,
440
                copy_ena =>    copy_ena1
441
        );
442
 
443
        inst_switch2: switch
444
   GENERIC MAP (
445
      nbbit_div => nbbit_div)
446
   PORT MAP(
447
                clk_sys =>     clk_sys,
448
                rst_n =>       rst_n,
449
      baud_lock =>   baud_locked,
450
                tc_divclk =>   tc_divclk,
451
                rx =>          rx2_r2,
452
                rx_dat =>      layer1_rx2,
453
                rx_val =>      layer1_val2,
454
                tx =>          tx1,
455
                tx_dat =>      layer1_tx1,
456
                tx_rd =>       layer1_rd1,
457
                tx_empty =>    layer1_empty1,
458
                sw_ena =>      sw_ena2,
459
                copy_ena =>    copy_ena2
460
        );
461
 
462
        inst_layer2_rx1: con_layer2_rx
463
   GENERIC MAP (
464
      nbbit_div => nbbit_div)
465
   PORT MAP(
466
                clk_sys =>     clk_sys,
467
                rst_n =>       rst_n,
468
      ad_con =>      ad_con,
469
                sw_ena =>      sw_ena1,
470
                dat_in =>      layer1_rx1,
471
                val_in =>      layer1_val1,
472
                tc_divclk =>   tc_divclk,
473
                sof_pic =>     layer2_sof1_pic,
474
                eof_pic =>     layer2_eof1_pic,
475
                l2_ok_pic =>   layer2_l2ok1_pic,
476
                dat_out_pic => layer2_rx1_pic,
477
                val_out_pic => layer2_rxval1_pic,
478
      sof_pas =>     sof_storerx1,
479
      eof_pas =>     eof_storerx1,
480
      l2_ok_pas =>   crcok_storerx1,
481
      dat_out_pas => data_storerx1,
482
      val_out_pas => val_storerx1
483
        );
484
 
485
        inst_layer2_rx2: con_layer2_rx
486
   GENERIC MAP (
487
      nbbit_div => nbbit_div)
488
   PORT MAP(
489
                clk_sys =>     clk_sys,
490
                rst_n =>       rst_n,
491
      ad_con =>      ad_con,
492
                sw_ena =>      sw_ena2,
493
                dat_in =>      layer1_rx2,
494
                val_in =>      layer1_val2,
495
                tc_divclk =>   tc_divclk,
496
                sof_pic =>     layer2_sof2_pic,
497
                eof_pic =>     layer2_eof2_pic,
498
                l2_ok_pic =>   layer2_l2ok2_pic,
499
                dat_out_pic => layer2_rx2_pic,
500
                val_out_pic => layer2_rxval2_pic,
501
      sof_pas =>     sof_storerx2,
502
      eof_pas =>     eof_storerx2,
503
      l2_ok_pas =>   crcok_storerx2,
504
      dat_out_pas => data_storerx2,
505
      val_out_pas => val_storerx2
506
        );
507
 
508
        inst_frame_store1: frame_store
509
   PORT MAP(
510
                clk_sys =>     clk_sys,
511
                rst_n =>       rst_n,
512
                dat_in =>      layer2_rx1_pic,
513
                val_in =>      layer2_rxval1_pic,
514
                sof =>         layer2_sof1_pic,
515
                eof =>         layer2_eof1_pic,
516
                l2_ok =>       layer2_l2ok1_pic,
517
                dat_out =>     layer7_rx1,
518
      soc_out =>     layer7_soc1,
519
                rd_datout =>   layer7_rd1,
520
                new_frame =>   layer7_newframe1,
521
                com_dispo =>   layer7_comdispo1,
522
                l7_ok =>       layer7_l2ok1,
523
      overflow =>    overflow_store1
524
        );
525
   layer7_overflow1 <= overflow_store1 OR overflow_filter1;
526
 
527
        inst_frame_store2: frame_store
528
   PORT MAP(
529
                clk_sys =>     clk_sys,
530
                rst_n =>       rst_n,
531
                dat_in =>      layer2_rx2_pic,
532
                val_in =>      layer2_rxval2_pic,
533
                sof =>         layer2_sof2_pic,
534
                eof =>         layer2_eof2_pic,
535
                l2_ok =>       layer2_l2ok2_pic,
536
                dat_out =>     layer7_rx2,
537
      soc_out =>     layer7_soc2,
538
                rd_datout =>   layer7_rd2,
539
                new_frame =>   layer7_newframe2,
540
                com_dispo =>   layer7_comdispo2,
541
                l7_ok =>       layer7_l2ok2,
542
      overflow =>    overflow_store2
543
        );
544
   layer7_overflow2 <= overflow_store2 OR overflow_filter2;
545
 
546
   inst_dble_filt : filter_dbl_frame_sil4
547
   PORT MAP(
548
      clk_sys        => clk_sys,
549
      rst_n          => rst_n,
550
      top_cycle      => top_cycle,
551
      ena_filt_dble  => ena_filt_dble,
552
      data_port1     => layer7_rx1,
553
      soc_port1      => layer7_soc1,
554
      com_dispo1     => layer7_comdispo1,
555
      rd_port1       => layer7_rd1,
556
      data_port2     => layer7_rx2,
557
      soc_port2      => layer7_soc2,
558
      com_dispo2     => layer7_comdispo2,
559
      rd_port2       => layer7_rd2,
560
      data_filt1_uc1 => filt_rx1_uc1,
561
      soc_filt1_uc1  => filt_soc1_uc1,
562
      frm_dispo_filt1_uc1=> filt_comdispo1_uc1,
563
      rd_filt1_uc1   => filt_rd1_uc1,
564
      data_filt2_uc1 => filt_rx2_uc1,
565
      soc_filt2_uc1  => filt_soc2_uc1,
566
      frm_dispo_filt2_uc1=> filt_comdispo2_uc1,
567
      rd_filt2_uc1   => filt_rd2_uc1,
568
      data_filt1_uc2 => filt_rx1_uc2,
569
      soc_filt1_uc2  => filt_soc1_uc2,
570
      frm_dispo_filt1_uc2=> filt_comdispo1_uc2,
571
      rd_filt1_uc2   => filt_rd1_uc2,
572
      data_filt2_uc2 => filt_rx2_uc2,
573
      soc_filt2_uc2  => filt_soc2_uc2,
574
      frm_dispo_filt2_uc2=> filt_comdispo2_uc2,
575
      rd_filt2_uc2   => filt_rd2_uc2,
576
      dpram_overflow1=> overflow_filter1,
577
      dpram_overflow2=> overflow_filter2
578
      );
579
 
580
 
581
   arbitrage_tx : PROCESS(clk_sys, rst_n)
582
   BEGIN
583
      IF (rst_n = '0') THEN
584
         mux_tx      <= '0';
585
         tx_encours  <= '0';
586
         tx_commena_uc1 <= '0';
587
         tx_commena_uc2 <= '0';
588
      ELSIF (clk_sys'EVENT and clk_sys = '1') THEN
589
         IF (tx_encours = '0') THEN
590
         -- Si une trame n'est pas en cours de recopie
591
            IF (tx_available_uc1 = '1') THEN
592
            -- Si le PIC 1 a une trame en attente d'émission
593
               IF (tx_available_uc2 = '1') THEN
594
               -- Si le PIC 2 a aussi une trame en attente
595
                  mux_tx <= NOT(mux_tx);        -- On traite le côté qui n'a pas été traité au coup d'avant (flip-flop)
596
                  tx_commena_uc1 <= mux_tx;        -- On anticipe le fait que mux_tx aura changé au cycle suvant : ie NOT(NOT(mux_tx))
597
                  tx_commena_uc2 <= NOT(mux_tx);   -- On anticipe le fait que mux_tx aura changé au cycle suvant : ie NOT(mux_tx)
598
                  tx_encours  <= '1';           -- On mémorise le fait qu'on a choisi un côté
599
               ELSE
600
               -- Si PIC 1 uniquement a quelque chose à transmettre
601
                  mux_tx      <= '0';           -- On sélecitonne la voie 1
602
                  tx_commena_uc1 <= '1';           -- On autorise le PIC 1
603
                  tx_commena_uc2 <= '0';
604
                  tx_encours  <= '1';           -- On mémorise le fait qu'on a choisi un côté
605
               END IF;
606
            ELSIF (tx_available_uc2 = '1') THEN
607
            -- Si le PIC1 n'a rien à dire mais le PIC 2 oui
608
               mux_tx      <= '1';              -- On sélecitonne la voie 2
609
               tx_commena_uc1 <= '0';
610
               tx_commena_uc2 <= '1';              -- On autorise le PIC 2
611
               tx_encours  <= '1';              -- On mémorise le fait qu'on a choisi un côté
612
            END IF;
613
 
614
         ELSE
615
         -- Si on a choisi un côté
616
            IF (tx_sof = '1') THEN
617
            -- On a attend que la transmission commence pour annuler les autorisations
618
               tx_commena_uc1 <= '0';
619
               tx_commena_uc2 <= '0';
620
            END IF;
621
            IF (tx_eof = '1') THEN
622
            -- Lorsuq'on voit passer le fin de trame
623
               tx_encours  <= '0';              -- On autorise la sélection d'une autre voie
624
            END IF;
625
         END IF;
626
      END IF;
627
   END PROCESS;
628
 
629
   tx_dat      <= tx_dat_uc1      WHEN (mux_tx = '0') ELSE tx_dat_uc2;
630
   val_txdat   <= val_txdat_uc1   WHEN (mux_tx = '0') ELSE val_txdat_uc2;
631
   tx_sof      <= tx_sof_uc1      WHEN (mux_tx = '0') ELSE tx_sof_uc2;
632
   tx_eof      <= tx_eof_uc1      WHEN (mux_tx = '0') ELSE tx_eof_uc2;
633
   clr_fifo_tx <= clr_fifo_tx_uc1 OR clr_fifo_tx_uc2;
634
   stuf_phys   <= stuf_phys_uc1   OR stuf_phys_uc2;
635
 
636
   tx_dat_pas    <= tx_dat;
637
   val_txdat_pas <= val_txdat AND txdat_free_buf; -- On assure que chaque donnée n'est envoyée à la passerelle qu'une seule fois
638
   tx_sof_pas    <= tx_sof;
639
   tx_eof_pas    <= tx_eof;
640
   txdat_free    <= txdat_free_buf;
641
   inst_layer2_tx: con_layer2_tx
642
   PORT MAP(
643
      clk_sys => clk_sys,
644
      rst_n => rst_n,
645
      stuf_phys => stuf_phys,
646
      acq_stuf => acq_stuf,
647
      dat_in => tx_dat,
648
      val_in => val_txdat,
649
      sof => tx_sof,
650
      eof => tx_eof,
651
      datin_free => txdat_free_buf,
652
      dat_out => layer2_txdat,
653
      val_out => layer2_txval,
654
      clr_fifo => clr_fifo_tx,
655
      progfull1 => layer2_progfull1,
656
      progfull2 => layer2_progfull2,
657
      full1     => layer2_full1,
658
      empty1    => layer1_empty1,
659
      full2     => layer2_full2,
660
      empty2    => layer1_empty2
661
        );
662
 
663
   -- La FIFO contient 512 mots, le prog_full est configuré à 500 mots pour laisser une marge de 
664
   -- stockage avant overflow (voir le module layer2_tx)
665
   inst_fifo_tx1 : fifo_tx
666
   PORT MAP (
667
      clk =>   clk_sys,
668
      srst =>  clr_fifo_tx,
669
      din =>   layer2_txdat,
670
      wr_en => layer2_txval,
671
      rd_en => layer1_rd1,
672
      dout =>  layer1_tx1,
673
      full =>  layer2_full1,
674
      empty => layer1_empty1,
675
      prog_full => layer2_progfull1
676
   );
677
 
678
   inst_fifo_tx2 : fifo_tx
679
   PORT MAP (
680
      clk =>   clk_sys,
681
      srst =>  clr_fifo_tx,
682
      din =>   layer2_txdat,
683
      wr_en => layer2_txval,
684
      rd_en => layer1_rd2,
685
      dout =>  layer1_tx2,
686
      full =>  layer2_full2,
687
      empty => layer1_empty2,
688
      prog_full => layer2_progfull2
689
   );
690
 
691
END rtl;
692
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.