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

Subversion Repositories rio

[/] [rio/] [trunk/] [rtl/] [vhdl/] [srio_pcs_struct.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 azdem
-------------------------------------------------------------------------------
2
-- 
3
-- RapidIO IP Library Core
4
-- 
5
-- This file is part of the RapidIO IP library project
6
-- http://www.opencores.org/cores/rio/
7
-- 
8
-- To Do:
9
-- -
10
-- 
11
-- Author(s): 
12
-- - A. Demirezen, azdem@opencores.org 
13
-- 
14
-------------------------------------------------------------------------------
15
-- 
16
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
17
-- 
18
-- This source file may be used and distributed without 
19
-- restriction provided that this copyright statement is not 
20
-- removed from the file and that any derivative work contains 
21
-- the original copyright notice and the associated disclaimer. 
22
-- 
23
-- This source file is free software; you can redistribute it 
24
-- and/or modify it under the terms of the GNU Lesser General 
25
-- Public License as published by the Free Software Foundation; 
26
-- either version 2.1 of the License, or (at your option) any 
27
-- later version. 
28
-- 
29
-- This source is distributed in the hope that it will be 
30
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
31
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
32
-- PURPOSE. See the GNU Lesser General Public License for more 
33
-- details. 
34
-- 
35
-- You should have received a copy of the GNU Lesser General 
36
-- Public License along with this source; if not, download it 
37
-- from http://www.opencores.org/lgpl.shtml 
38
-- 
39
------------------------------------------------------------------------------
40
------------------------------------------------------------------------------
41
--
42
-- File name:    ccs_timer.vhd
43
-- Rev:          0.0
44
-- Description:  This entity watches the CCS (clock compensation sequence) 
45
--               insertion according to RIO Sepec. Part-6, subchapter 4.7.1
46
-- 
47
------------------------------------------------------------------------------
48
------------------------------------------------------------------------------
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.numeric_std.all;
52
use ieee.std_logic_unsigned.all;
53
use work.rio_common.all;
54
 
55
entity ccs_timer is
56
  generic (
57
    TCQ         : time      := 100 ps
58
  );
59
  port (
60
    rst_n               : in  std_logic;
61
    UCLK                : in  std_logic;
62
 
63
    send_ccs            : out std_logic;
64
    ccs_timer_rst       : in  std_logic
65
  );
66
end ccs_timer;
67
 
68
architecture RTL of ccs_timer is
69
--------------------------------------------------------------------------------------
70
signal   ccs_counter            : std_logic_vector(11 downto 0) := (others => '0');
71
constant CCS_INTERVAL           : std_logic_vector(11 downto 0) := x"7FF";  -- = 4096 chars
72
 
73
--------------------------------------------------------------------------------------
74
begin
75
 
76
-- CCS counter process
77
process(rst_n, UCLK)
78
    begin
79
    if rst_n = '0'  then
80
        ccs_counter     <= CCS_INTERVAL;
81
        send_ccs        <= '0';
82
    elsif rising_edge(UCLK) then
83
        if ccs_timer_rst = '0' then
84
            if ccs_counter = CCS_INTERVAL then
85
                send_ccs    <= '1';
86
            else
87
                send_ccs    <= '0';
88
                ccs_counter <= ccs_counter + '1';
89
            end if;
90
        else
91
            send_ccs    <= '0';
92
            ccs_counter <= (others => '0');
93
        end if;
94
    end if;
95
end process;
96
 
97
end RTL;
98
---------------------------------------------------------------------------------------
99
-------------------------------------------------------------------------------
100
-- 
101
-- RapidIO IP Library Core
102
-- 
103
-- This file is part of the RapidIO IP library project
104
-- http://www.opencores.org/cores/rio/
105
-- 
106
-- To Do:
107
-- -
108
-- 
109
-- Author(s): 
110
-- - A. Demirezen, azdem@opencores.org 
111
-- 
112
-------------------------------------------------------------------------------
113
-- 
114
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
115
-- 
116
-- This source file may be used and distributed without 
117
-- restriction provided that this copyright statement is not 
118
-- removed from the file and that any derivative work contains 
119
-- the original copyright notice and the associated disclaimer. 
120
-- 
121
-- This source file is free software; you can redistribute it 
122
-- and/or modify it under the terms of the GNU Lesser General 
123
-- Public License as published by the Free Software Foundation; 
124
-- either version 2.1 of the License, or (at your option) any 
125
-- later version. 
126
-- 
127
-- This source is distributed in the hope that it will be 
128
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
129
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
130
-- PURPOSE. See the GNU Lesser General Public License for more 
131
-- details. 
132
-- 
133
-- You should have received a copy of the GNU Lesser General 
134
-- Public License along with this source; if not, download it 
135
-- from http://www.opencores.org/lgpl.shtml 
136
-- 
137
------------------------------------------------------------------------------
138
------------------------------------------------------------------------------
139
--
140
-- File name:    idle_generator.vhd
141
-- Rev:          0.0
142
-- Description:  This entity generates IDLE1 sequence for SRIO PHY 
143
--               RIO Sepec. Part-6, subchapter 4.7.2
144
-- 
145
------------------------------------------------------------------------------
146
------------------------------------------------------------------------------
147
library ieee;
148
use ieee.std_logic_1164.all;
149
use ieee.numeric_std.all;
150
use ieee.std_logic_unsigned.all;
151
use work.rio_common.all;
152
 
153
entity idle_generator is
154
  generic (
155
            lfsr_init   : std_logic_vector(7 downto 0) := x"01";
156
            TCQ         : time      := 100 ps
157
  );
158
  port (
159
    UCLK                : in  std_logic;
160
    rst_n               : in  std_logic;
161
 
162
    send_idle           : in  std_logic;
163
 
164
    send_K              : out std_logic;
165
    send_A              : out std_logic;
166
    send_R              : out std_logic
167
  );
168
end idle_generator;
169
 
170
architecture RTL of idle_generator is
171
-------------------------------------------------------------------------------------------------------------------------------------------
172
signal q_pseudo_random_number  : std_logic_vector(7 downto 0) := (others => '0');
173
signal pseudo_random_bit       : std_logic                    := '0';
174
 
175
signal down_counter_load_value : std_logic_vector(4 downto 0) := (others => '0');
176
signal down_counter            : std_logic_vector(4 downto 0) := (others => '0');
177
signal Acntr_eq_zero           : std_logic                    := '0';
178
signal send_idle_q             : std_logic                    := '0';
179
-- 
180
 
181
COMPONENT pseudo_random_number_generator
182
GENERIC (
183
         lfsr_init   : std_logic_vector(7 downto 0)
184
        );
185
PORT(
186
        clk     : IN std_logic;
187
        rst_n   : IN std_logic;
188
        q       : OUT std_logic_vector(7 downto 0)
189
        );
190
END COMPONENT;
191
 
192
-------------------------------------------------------------------------------------------------------------------------------------------
193
begin
194
 
195
inst_prng: pseudo_random_number_generator GENERIC MAP(
196
        lfsr_init => lfsr_init  --x"01"
197
        )
198
    PORT MAP(
199
        clk     => UCLK,
200
                rst_n   => rst_n,
201
                q       => q_pseudo_random_number
202
        );
203
 
204
pseudo_random_bit       <= q_pseudo_random_number(0);
205
 
206
down_counter_load_value <= '1' & q_pseudo_random_number(6) & q_pseudo_random_number(4) & q_pseudo_random_number(3) & q_pseudo_random_number(1);
207
 
208
-- down counter process
209
process(rst_n, UCLK)
210
    begin
211
    if rst_n = '0'  then
212
        down_counter      <= (others => '0');
213
    elsif rising_edge(UCLK) then
214
        if Acntr_eq_zero = '1' then
215
            down_counter <= down_counter_load_value;
216
        else
217
            down_counter <= down_counter - '1';
218
        end if;
219
    end if;
220
end process;
221
 
222
Acntr_eq_zero <= '1' when down_counter = "00000" else '0';
223
 
224
-- send_idle delay process
225
process(rst_n, UCLK)
226
    begin
227
    if rst_n = '0'  then
228
        send_idle_q     <= '0';
229
    elsif rising_edge(UCLK) then
230
        send_idle_q     <= send_idle;
231
    end if;
232
end process;
233
 
234
send_K <= send_idle and (not(send_idle_q) or (send_idle_q and not(Acntr_eq_zero) and pseudo_random_bit));
235
send_A <= send_idle and send_idle_q and Acntr_eq_zero;
236
send_R <= send_idle and send_idle_q and not(Acntr_eq_zero) and not(pseudo_random_bit);
237
 
238
end RTL;
239
-------------------------------------------------------------------------------------------------------------------------------------------
240
-------------------------------------------------------------------------------
241
-- 
242
-- RapidIO IP Library Core
243
-- 
244
-- This file is part of the RapidIO IP library project
245
-- http://www.opencores.org/cores/rio/
246
-- 
247
-- To Do:
248
-- -
249
-- 
250
-- Author(s): 
251
-- - A. Demirezen, azdem@opencores.org 
252
-- 
253
-------------------------------------------------------------------------------
254
-- 
255
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
256
-- 
257
-- This source file may be used and distributed without 
258
-- restriction provided that this copyright statement is not 
259
-- removed from the file and that any derivative work contains 
260
-- the original copyright notice and the associated disclaimer. 
261
-- 
262
-- This source file is free software; you can redistribute it 
263
-- and/or modify it under the terms of the GNU Lesser General 
264
-- Public License as published by the Free Software Foundation; 
265
-- either version 2.1 of the License, or (at your option) any 
266
-- later version. 
267
-- 
268
-- This source is distributed in the hope that it will be 
269
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
270
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
271
-- PURPOSE. See the GNU Lesser General Public License for more 
272
-- details. 
273
-- 
274
-- You should have received a copy of the GNU Lesser General 
275
-- Public License along with this source; if not, download it 
276
-- from http://www.opencores.org/lgpl.shtml 
277
-- 
278
------------------------------------------------------------------------------
279
------------------------------------------------------------------------------
280
--
281
-- File name:    idle_generator_dual.vhd
282
-- Rev:          0.0
283
-- Description:  This entity generates IDLE1 sequence for SRIO PHY 
284
--               RIO Sepec. Part-6, subchapter 4.7.2
285
-- 
286
------------------------------------------------------------------------------
287
------------------------------------------------------------------------------
288
library ieee;
289
use ieee.std_logic_1164.all;
290
use ieee.numeric_std.all;
291
use ieee.std_logic_unsigned.all;
292
use work.rio_common.all;
293
 
294
entity idle_generator_dual is
295
  generic (
296
            TCQ         : time      := 100 ps
297
  );
298
  port (
299
    UCLK                : in  std_logic;
300
    rst_n               : in  std_logic;
301
 
302
    send_idle           : in  std_logic_vector(1 downto 0);
303
 
304
    send_K              : out std_logic_vector(1 downto 0);
305
    send_A              : out std_logic_vector(1 downto 0);
306
    send_R              : out std_logic_vector(1 downto 0)
307
  );
308
end idle_generator_dual;
309
 
310
architecture RTL of idle_generator_dual is
311
-------------------------------------------------------------------------------------------------------------------------------------------
312
 
313
COMPONENT idle_generator
314
  generic (
315
            lfsr_init   : std_logic_vector(7 downto 0);
316
            TCQ         : time
317
  );
318
PORT(
319
        UCLK        : IN  std_logic;
320
        rst_n       : IN  std_logic;
321
        send_idle   : IN  std_logic;
322
        send_K      : OUT std_logic;
323
        send_A      : OUT std_logic;
324
        send_R      : OUT std_logic
325
        );
326
END COMPONENT;
327
 
328
-------------------------------------------------------------------------------------------------------------------------------------------
329
begin
330
 
331
        Inst_idle_generator_0: idle_generator GENERIC MAP(
332
        TCQ         => 100 ps,
333
        lfsr_init   => x"0F"
334
    )
335
        PORT MAP(
336
                UCLK        => UCLK,
337
                rst_n       => rst_n,
338
                send_idle   => send_idle(0),
339
                send_K      => send_K(0),
340
                send_A      => send_A(0),
341
                send_R      => send_R(0)
342
        );
343
 
344
        Inst_idle_generator_1: idle_generator GENERIC MAP(
345
        TCQ         => 100 ps,
346
        lfsr_init => x"F0"
347
    )
348
        PORT MAP(
349
                UCLK        => UCLK,
350
                rst_n       => rst_n,
351
                send_idle   => send_idle(1),
352
                send_K      => send_K(1),
353
                send_A      => send_A(1),
354
                send_R      => send_R(1)
355
        );
356
 
357
end RTL;
358
-------------------------------------------------------------------------------------------------------------------------------------------
359
-------------------------------------------------------------------------------
360
-- 
361
-- RapidIO IP Library Core
362
-- 
363
-- This file is part of the RapidIO IP library project
364
-- http://www.opencores.org/cores/rio/
365
-- 
366
-- To Do:
367
-- -
368
-- 
369
-- Author(s): 
370
-- - A. Demirezen, azdem@opencores.org 
371
-- 
372
-------------------------------------------------------------------------------
373
-- 
374
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
375
-- 
376
-- This source file may be used and distributed without 
377
-- restriction provided that this copyright statement is not 
378
-- removed from the file and that any derivative work contains 
379
-- the original copyright notice and the associated disclaimer. 
380
-- 
381
-- This source file is free software; you can redistribute it 
382
-- and/or modify it under the terms of the GNU Lesser General 
383
-- Public License as published by the Free Software Foundation; 
384
-- either version 2.1 of the License, or (at your option) any 
385
-- later version. 
386
-- 
387
-- This source is distributed in the hope that it will be 
388
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
389
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
390
-- PURPOSE. See the GNU Lesser General Public License for more 
391
-- details. 
392
-- 
393
-- You should have received a copy of the GNU Lesser General 
394
-- Public License along with this source; if not, download it 
395
-- from http://www.opencores.org/lgpl.shtml 
396
-- 
397
------------------------------------------------------------------------------
398
------------------------------------------------------------------------------
399
--
400
-- File name:    pcs_rx_controller.vhd
401
-- Rev:          0.0
402
-- Description:  This entity controls the RX stream 
403
--               
404
-- 
405
------------------------------------------------------------------------------
406
------------------------------------------------------------------------------
407
library ieee;
408
use ieee.std_logic_1164.all;
409
use ieee.numeric_std.all;
410
use ieee.std_logic_unsigned.all;
411
use work.rio_common.all;
412
 
413
entity pcs_rx_controller is
414
  generic (
415
    TCQ                     : time  := 100 ps
416
  );
417
  port (
418
    rst_n                   : in  std_logic;
419
    rio_clk                 : in  std_logic;  -- ~150 MHz
420
    UCLK_x2                 : in  std_logic;  --  312,5 MHz
421
    UCLK                    : in  std_logic;  --  156,25 MHz 
422
    UCLK_x2_DV2             : in  std_logic;  --  312,5 MHz @ x4 mode / 78,125 @ x1 (fallback mode) 
423
    UCLK_or_DV4             : in  std_logic;  --  156,25 MHz @ x4 mode / 39,0625 @ x1 (fallback mode)
424
    -- UCLK_DV4                : in  std_logic;  --  39,0625
425
    --
426
    -- Interface to the RioSerial
427
    inboundRead_i           : in  std_logic;
428
    inboundEmpty_o          : out std_logic;
429
    inboundSymbol_o         : out std_logic_vector(33 downto 0);
430
    --
431
    -- Interface to the GTX transceivers
432
    RXDATA_i                : in  std_logic_vector(63 downto 0);  -- N = 4
433
    RXCHARISK_i             : in  std_logic_vector(7 downto 0);
434
    RXCHARISvalid_i         : in  std_logic_vector(7 downto 0);
435
    --
436
    -- Interface to the port init
437
    port_initalized_i       : in  std_logic;
438
    mode_sel_i              : in  std_logic;
439
    mode_0_lane_sel_i       : in  std_logic
440
 
441
  );
442
end pcs_rx_controller;
443
 
444
architecture RTL of pcs_rx_controller is
445
 
446
-------------------------------------------------------------------------------
447
COMPONENT pcs_rx_boudary_32b_out_64b_in
448
    PORT (
449
    rst             : IN STD_LOGIC;
450
    wr_clk          : IN STD_LOGIC;
451
    rd_clk          : IN STD_LOGIC;
452
    din             : IN STD_LOGIC_VECTOR(67 DOWNTO 0);
453
    wr_en           : IN STD_LOGIC;
454
    rd_en           : IN STD_LOGIC;
455
    dout            : OUT STD_LOGIC_VECTOR(33 DOWNTO 0);
456
    full            : OUT STD_LOGIC;
457
    almost_full     : OUT STD_LOGIC;
458
    empty           : OUT STD_LOGIC;
459
    almost_empty    : OUT STD_LOGIC;
460
    valid           : OUT STD_LOGIC
461
  );
462
END COMPONENT;
463
-------------------------------------------------------------------------------
464
signal rst                  : std_logic:= '0';
465
 
466
signal RXDATA_swap          : std_logic_vector(63 downto 0) := (others => '0');
467
signal RXCHARISK_swap       : std_logic_vector(7  downto 0) := (others => '0');
468
signal RXCHARISvalid_swap   : std_logic_vector(7  downto 0) := (others => '0');
469
 
470
signal RXDATA_u             : std_logic_vector(31 downto 0) := (others => '0');
471
signal RXCHARISK_u          : std_logic_vector(3  downto 0) := (others => '0');
472
signal RXDATA_l             : std_logic_vector(31 downto 0) := (others => '0');
473
signal RXCHARISK_l          : std_logic_vector(3  downto 0) := (others => '0');
474
signal RXCHARISvalid_u      : std_logic_vector(3  downto 0) := (others => '0');
475
signal RXCHARISvalid_l      : std_logic_vector(3  downto 0) := (others => '0');
476
 
477
signal inboundValid           : std_logic:= '0';
478
signal rx_fifo_wr_en          : std_logic:= '0';
479
signal rx_fifo_wr_en_q        : std_logic:= '0';
480
signal rx_fifo_full           : std_logic:= '0';
481
signal rx_fifo_almost_full    : std_logic:= '0';
482
signal rx_fifo_almost_empty   : std_logic:= '0';
483
 
484
signal rx_fifo_data_in        : std_logic_vector(67 downto 0) := (others => '0');
485
signal rx_fifo_data_in_q      : std_logic_vector(67 downto 0) := (others => '0');
486
signal rx_fifo_data_swapped   : std_logic_vector(67 downto 0) := (others => '0');
487
signal rx_fifo_full_p         : std_logic:= '0';
488
 
489
signal port_initalized      : std_logic:= '0';
490
signal mode_sel             : std_logic:= '0';
491
signal mode_0_lane_sel      : std_logic:= '0';
492
 
493
signal port_state           : std_logic_vector(2 downto 0) := (others => '0');
494
 
495
signal upper_symbol_type    : std_logic_vector(1  downto 0) := (others => '0');
496
signal lower_symbol_type    : std_logic_vector(1  downto 0) := (others => '0');
497
 
498
signal upper_symbol_not_idle  : std_logic:= '0';
499
signal lower_symbol_not_idle  : std_logic:= '0';
500
signal upper_symbol_valid     : std_logic:= '0';
501
signal lower_symbol_valid     : std_logic:= '0';
502
signal upper_symbol_not_error : std_logic:= '0';
503
signal lower_symbol_not_error : std_logic:= '0';
504
 
505
-- signal RXDATA_sr              : std_logic_vector(63 downto 0) := (others => '0'); 
506
-- signal RXCHARISK_sr           : std_logic_vector(7  downto 0) := (others => '0');
507
-- signal RXCHARISvalid_sr       : std_logic_vector(7  downto 0) := (others => '0'); 
508
 
509
signal RXDATA_sr_done         : std_logic_vector(63 downto 0) := (others => '0');
510
signal RXCHARISK_sr_done      : std_logic_vector(7  downto 0) := (others => '0');
511
signal RXCHARISvalid_sr_done  : std_logic_vector(7  downto 0) := (others => '0');
512
 
513
signal RXDATA_sr              : std_logic_vector(71 downto 0) := (others => '0');
514
signal RXCHARISK_sr           : std_logic_vector(8  downto 0) := (others => '0');
515
signal RXCHARISvalid_sr       : std_logic_vector(8  downto 0) := (others => '0');
516
 
517
signal RXDATA_R_lane          : std_logic_vector(15 downto 0) := (others => '0');
518
signal RXCHARISK_R_lane       : std_logic_vector(1  downto 0) := (others => '0');
519
signal RXCHARISvalid_R_lane   : std_logic_vector(1  downto 0) := (others => '0');
520
 
521
signal valid_byte_cntr        : std_logic_vector(2  downto 0) := (others => '0');
522
signal irregular_stream       : std_logic:= '0';
523
signal done_cntr              : std_logic_vector(1  downto 0) := (others => '0');
524
signal rx_done                : std_logic:= '0';
525
 
526
signal u_l_switch             : std_logic:= '0';
527
 
528
-- signal sr_symbol_not_idle     : std_logic:= '0'; 
529
-- signal sr_symbol_not_idle_q   : std_logic:= '0'; 
530
-- signal sr_symbol_not_error    : std_logic:= '0'; 
531
-- signal sr_symbol_not_error_q  : std_logic:= '0'; 
532
-- signal RXDATA_sr              : std_logic_vector(31 downto 0) := (others => '0'); 
533
-- signal RXCHARISK_sr           : std_logic_vector(3  downto 0) := (others => '0');
534
-- signal RXCHARISvalid_sr       : std_logic_vector(3  downto 0) := (others => '0');                              
535
-- signal sr_symbol_type         : std_logic_vector(1  downto 0) := (others => '0');
536
 
537
signal sr_u_symbol_not_idle     : std_logic:= '0';
538
signal sr_u_symbol_not_idle_q   : std_logic:= '0';
539
signal sr_u_symbol_not_error    : std_logic:= '0';
540
signal sr_u_symbol_not_error_q  : std_logic:= '0';
541
signal RXDATA_u_sr              : std_logic_vector(31 downto 0) := (others => '0');
542
signal RXCHARISK_u_sr           : std_logic_vector(3  downto 0) := (others => '0');
543
signal RXCHARISvalid_u_sr       : std_logic_vector(3  downto 0) := (others => '0');
544
signal sr_u_symbol_type         : std_logic_vector(1  downto 0) := (others => '0');
545
 
546
signal sr_l_symbol_not_idle     : std_logic:= '0';
547
signal sr_l_symbol_not_idle_q   : std_logic:= '0';
548
signal sr_l_symbol_not_error    : std_logic:= '0';
549
signal sr_l_symbol_not_error_q  : std_logic:= '0';
550
signal RXDATA_sr_l              : std_logic_vector(31 downto 0) := (others => '0');
551
signal RXCHARISK_sr_l           : std_logic_vector(3  downto 0) := (others => '0');
552
signal RXCHARISvalid_sr_l       : std_logic_vector(3  downto 0) := (others => '0');
553
signal sr_l_symbol_type         : std_logic_vector(1  downto 0) := (others => '0');
554
 
555
 
556
signal started_once           : std_logic:= '0';
557
signal word_switch            : std_logic:= '0';
558
signal shift_cntr             : std_logic_vector(1  downto 0) := (others => '0');
559
 
560
 
561
----------------------------------------------------------------------------------
562
begin
563
rst                  <= not(rst_n);
564
 
565
rx_boundary_fifo : pcs_rx_boudary_32b_out_64b_in   -- FWFT FIFO
566
  PORT MAP (
567
    rst            => rst,
568
    rd_clk         => rio_clk,
569
    rd_en          => inboundRead_i,
570
    dout           => inboundSymbol_o,
571
    valid          => inboundValid,
572
    empty          => inboundEmpty_o,
573
    almost_empty   => rx_fifo_almost_empty,
574
 
575
    wr_clk         => UCLK_or_DV4,
576
    wr_en          => rx_fifo_wr_en_q,      -- rx_fifo_wr_en,        -- rx_fifo_wr_en_q,         --
577
    din            => rx_fifo_data_in_q,    -- rx_fifo_data_in,      -- rx_fifo_data_in_q,       --
578
    full           => rx_fifo_full,         -- rx_fifo_full    
579
    almost_full    => rx_fifo_almost_full   -- rx_fifo_full    
580
  );
581
 
582
-- Pipelining RX write
583
process(UCLK_or_DV4)
584
    begin
585
    if rising_edge(UCLK_or_DV4) then
586
        rx_fifo_wr_en_q   <= rx_fifo_wr_en;
587
        rx_fifo_data_in_q <= rx_fifo_data_in;
588
    end if;
589
end process;
590
 
591
 
592
-- rx_fifo_data_swapped <= rx_fifo_data_in(33 downto 32) 
593
--                         & rx_fifo_data_in(7 downto 0) & rx_fifo_data_in(15 downto 8) & rx_fifo_data_in(23 downto 16) & rx_fifo_data_in(31 downto 24); 
594
 
595
port_initalized  <= port_initalized_i;
596
mode_sel         <= mode_sel_i;
597
mode_0_lane_sel  <= mode_0_lane_sel_i;
598
 
599
port_state <= port_initalized & mode_sel & mode_0_lane_sel;
600
 
601
-- RX management / FIFO write process  
602
process(rst_n, UCLK)  -- _x2
603
    begin
604
    if rst_n = '0'  then
605
 
606
        rx_fifo_wr_en    <= '0';
607
        word_switch      <= '0';
608
        started_once     <= '0';
609
        rx_fifo_data_in  <= (others => '0');
610
        -- RXDATA_sr        <= (others => '0');    
611
        -- RXCHARISK_sr     <= (others => '1');    
612
        -- RXCHARISvalid_sr <= (others => '0');
613
        shift_cntr       <= (others => '0');
614
 
615
    elsif rising_edge(UCLK) then
616
        -- Alternative If-Else Statement 
617
        if port_initalized = '0' then   -- Port has not been initialized yet
618
            rx_fifo_wr_en   <= '0';
619
            rx_fifo_data_in <= (others => '0');
620
        else                            -- Port has been initialized            
621
            -- if mode_sel = '1' then      -- x4 mode is active
622
                if upper_symbol_valid = '1' and lower_symbol_valid = '1' then
623
                    rx_fifo_data_in <= upper_symbol_type & RXDATA_u & lower_symbol_type & RXDATA_l;
624
                    rx_fifo_wr_en   <= not(rx_fifo_almost_full);
625
                elsif upper_symbol_valid = '1' then
626
                    rx_fifo_data_in <= upper_symbol_type & RXDATA_u & SYMBOL_IDLE & x"00000000";
627
                    rx_fifo_wr_en   <= not(rx_fifo_almost_full);
628
                elsif lower_symbol_valid = '1' then
629
                    rx_fifo_data_in <= SYMBOL_IDLE & x"00000000" & lower_symbol_type & RXDATA_l;
630
                    rx_fifo_wr_en   <= not(rx_fifo_almost_full);
631
                else
632
                    rx_fifo_wr_en   <= '0';
633
                end if;
634
            -- else -- x1 fallback mode is active    
635
            --     if upper_symbol_valid = '1' and lower_symbol_valid = '1' then
636
            --         rx_fifo_data_in <= upper_symbol_type & RXDATA_u & lower_symbol_type & RXDATA_l;                        
637
            --         rx_fifo_wr_en   <= not(rx_fifo_full);
638
            --     elsif upper_symbol_valid = '1' then
639
            --         rx_fifo_data_in <= upper_symbol_type & RXDATA_u & SYMBOL_IDLE & RXDATA_l;                        
640
            --         rx_fifo_wr_en   <= not(rx_fifo_full);       
641
            --     elsif lower_symbol_valid = '1' then
642
            --         rx_fifo_data_in <= SYMBOL_IDLE & RXDATA_u & lower_symbol_type & RXDATA_l;                        
643
            --         rx_fifo_wr_en   <= not(rx_fifo_full);
644
            --     else                  
645
            --         rx_fifo_wr_en   <= '0';                    
646
            --     end if;                  
647
            -- end if;        
648
        end if;
649
    end if;
650
end process;
651
-------------------------------------------------------------------------------------------------------------------------------------------------------
652
 
653
-- -- Pipelining RX stream
654
-- process(UCLK)  
655
--     begin  
656
--     if rising_edge(UCLK) then   
657
--         RXDATA_swap         <= RXDATA_i(15 downto 0)   & RXDATA_i(31 downto 16)  & RXDATA_i(47 downto 32)  & RXDATA_i(63 downto 48);
658
--         RXCHARISK_swap      <= RXCHARISK_i(1 downto 0) & RXCHARISK_i(3 downto 2) & RXCHARISK_i(5 downto 4) & RXCHARISK_i(7 downto 6);
659
--         RXCHARISvalid_swap  <= RXCHARISvalid_i(1 downto 0) & RXCHARISvalid_i(3 downto 2) & RXCHARISvalid_i(5 downto 4) & RXCHARISvalid_i(7 downto 6);
660
--     end if;
661
-- end process;  
662
 
663
-- Pipelining RX stream
664
process(UCLK)
665
    begin
666
    if rising_edge(UCLK) then
667
 
668
        RXDATA_swap         <= RXDATA_i(15 downto 0)   & RXDATA_i(31 downto 16)  & RXDATA_i(47 downto 32)  & RXDATA_i(63 downto 48);
669
        RXCHARISK_swap      <= RXCHARISK_i(1 downto 0) & RXCHARISK_i(3 downto 2) & RXCHARISK_i(5 downto 4) & RXCHARISK_i(7 downto 6);
670
        RXCHARISvalid_swap  <= RXCHARISvalid_i(1 downto 0) & RXCHARISvalid_i(3 downto 2) & RXCHARISvalid_i(5 downto 4) & RXCHARISvalid_i(7 downto 6);
671
 
672
        -- if mode_sel = '1' then      -- x4 mode is active               
673
 
674
        -- else                        -- x1 fallback mode is active  
675
        --     
676
        --     RXDATA_swap         <= RXDATA_sr_done        ;
677
        --     RXCHARISK_swap      <= RXCHARISK_sr_done     ;
678
        --     RXCHARISvalid_swap  <= RXCHARISvalid_sr_done ;
679
        --     
680
        -- end if;  
681
    end if;
682
end process;
683
---                      Lane 0 active                                                  Lane 2 active
684
RXDATA_R_lane         <= RXDATA_i(15 downto 0)          when mode_0_lane_sel = '0' else RXDATA_i(47 downto 32)       ;
685
RXCHARISK_R_lane      <= RXCHARISK_i(1 downto 0)        when mode_0_lane_sel = '0' else RXCHARISK_i(5 downto 4)      ;
686
RXCHARISvalid_R_lane  <= RXCHARISvalid_i(1 downto 0)    when mode_0_lane_sel = '0' else RXCHARISvalid_i(5 downto 4)  ;
687
 
688
-- RXDATA shifting process for x1 mode
689
process(UCLK)  -- _x2  rst_n, 
690
    begin
691
    -- if rst_n = '0'  then                
692
    -- 
693
    --     RXDATA_sr              <= (others => '0');    
694
    --     RXCHARISK_sr           <= (others => '1');    
695
    --     RXCHARISvalid_sr       <= (others => '0');
696
    --     valid_byte_cntr        <= (others => '0');
697
    --     
698
    --     RXDATA_sr_done         <= (others => '0');
699
    --     RXCHARISK_sr_done      <= (others => '1');
700
    --     RXCHARISvalid_sr_done  <= (others => '0');
701
    --     
702
    --     done_cntr              <= (others => '0');
703
    --     rx_done                <= '0';
704
    --     
705
    -- els
706
    if rising_edge(UCLK) then
707
 
708
        if port_initalized = '0' then   -- Port has not been initialized yet
709
 
710
            RXDATA_sr              <= (others => '0');
711
            RXCHARISK_sr           <= (others => '1');
712
            RXCHARISvalid_sr       <= (others => '0');
713
            valid_byte_cntr        <= (others => '0');
714
 
715
            RXDATA_sr_done         <= (others => '0');
716
            RXCHARISK_sr_done      <= (others => '1');
717
            RXCHARISvalid_sr_done  <= (others => '0');
718
 
719
            done_cntr              <= (others => '0');
720
            rx_done                <= '0';
721
 
722
        else
723
            done_cntr <= done_cntr + rx_done;
724
            if RXCHARISvalid_R_lane(0) = '1' and (RXCHARISK_R_lane(0) = '0' or (RXCHARISK_R_lane(0) = '1' and (RXDATA_R_lane(7 downto 0) = SC or RXDATA_R_lane(7 downto 0) = PD))) then
725
                if RXCHARISvalid_R_lane(1) = '1' and (RXCHARISK_R_lane(1) = '0' or (RXCHARISK_R_lane(1) = '1' and (RXDATA_R_lane(15 downto 8) = SC or RXDATA_R_lane(15 downto 8) = PD))) then
726
                --- [VVVV] It may appear anytime
727
                    valid_byte_cntr    <= valid_byte_cntr + "10";
728
                    RXDATA_sr          <= RXDATA_sr(55 downto 0)   & RXDATA_R_lane(15 downto 0);
729
                    RXCHARISK_sr       <= RXCHARISK_sr(6 downto 0) & RXCHARISK_R_lane(1 downto 0);
730
                    RXCHARISvalid_sr   <= RXCHARISvalid_sr(6 downto 0) & RXCHARISvalid_R_lane(1 downto 0);
731
                    if valid_byte_cntr = "110" then
732
                        irregular_stream        <= '0';
733
                        rx_done                 <= '1';
734
                        done_cntr               <= (others => '0');
735
                        RXDATA_sr_done          <= RXDATA_sr(47 downto 0)   & RXDATA_R_lane(15 downto 0);
736
                        RXCHARISK_sr_done       <= RXCHARISK_sr(5 downto 0) & RXCHARISK_R_lane(1 downto 0);
737
                        RXCHARISvalid_sr_done   <= RXCHARISvalid_sr(5 downto 0) & RXCHARISvalid_R_lane(1 downto 0);
738
                    elsif valid_byte_cntr = "111" then
739
                        irregular_stream        <= '1';
740
                        rx_done                 <= '1';
741
                        done_cntr               <= (others => '0');
742
                        RXDATA_sr_done          <= RXDATA_sr(55 downto 0)   & RXDATA_R_lane(15 downto 8);
743
                        RXCHARISK_sr_done       <= RXCHARISK_sr(6 downto 0) & RXCHARISK_R_lane(1);
744
                        RXCHARISvalid_sr_done   <= RXCHARISvalid_sr(6 downto 0) & RXCHARISvalid_R_lane(1);
745
                    elsif done_cntr = "11" then
746
                        rx_done                 <= '0';
747
                        RXCHARISK_sr_done       <= (others => '1');
748
                        RXCHARISvalid_sr_done   <= (others => '0');
749
                    end if;
750
                else
751
                --- [__VV] : It can appear only in the beginning                
752
                    if valid_byte_cntr = "100" then
753
                        valid_byte_cntr    <= valid_byte_cntr + '1';
754
                    else -- either it is an irregular start or something went wrong
755
                        valid_byte_cntr    <= "001";
756
                        irregular_stream   <= '1';
757
                    end if;
758
                    RXDATA_sr          <= RXDATA_sr(63 downto 0)   & RXDATA_R_lane(7 downto 0);
759
                    RXCHARISK_sr       <= RXCHARISK_sr(7 downto 0) & RXCHARISK_R_lane(0);
760
                    RXCHARISvalid_sr   <= RXCHARISvalid_sr(7 downto 0) & RXCHARISvalid_R_lane(0);
761
                    if done_cntr = "11" then
762
                        rx_done                 <= '0';
763
                        RXCHARISK_sr_done       <= (others => '1');
764
                        RXCHARISvalid_sr_done   <= (others => '0');
765
                    end if;
766
                end if;
767
            else
768
                if RXCHARISvalid_R_lane(1) = '1' and (RXCHARISK_R_lane(1) = '0' or (RXCHARISK_R_lane(1) = '1' and (RXDATA_R_lane(15 downto 8) = SC or RXDATA_R_lane(15 downto 8) = PD))) then
769
                --- [VV__] : It can appear only in the end               
770
                    RXDATA_sr          <= RXDATA_sr(63 downto 0)   & RXDATA_R_lane(15 downto 8);
771
                    RXCHARISK_sr       <= RXCHARISK_sr(7 downto 0) & RXCHARISK_R_lane(1);
772
                    RXCHARISvalid_sr   <= RXCHARISvalid_sr(7 downto 0) & RXCHARISvalid_R_lane(1);
773
                    if valid_byte_cntr = "011" then
774
                        valid_byte_cntr    <= valid_byte_cntr + '1';
775
                        irregular_stream   <= '0'; -- irregularity has been compensated for the first symbol
776
                        if done_cntr = "11" then
777
                            rx_done                 <= '0';
778
                            RXCHARISK_sr_done       <= (others => '1');
779
                            RXCHARISvalid_sr_done   <= (others => '0');
780
                        end if;
781
                    elsif valid_byte_cntr = "111" then -- 2 symbols (2x32b) are done
782
                        valid_byte_cntr         <= (others => '0');
783
                        irregular_stream        <= '0'; -- irregularity has been compensated for the second symbol
784
                        rx_done                 <= '1';
785
                        done_cntr               <= (others => '0');
786
                        RXDATA_sr_done          <= RXDATA_sr(55 downto 0)   & RXDATA_R_lane(15 downto 8);
787
                        RXCHARISK_sr_done       <= RXCHARISK_sr(6 downto 0) & RXCHARISK_R_lane(1);
788
                        RXCHARISvalid_sr_done   <= RXCHARISvalid_sr(6 downto 0) & RXCHARISvalid_R_lane(1);
789
                    else -- something went wrong
790
                        valid_byte_cntr    <= (others => '0');
791
                        irregular_stream   <= '0';
792
                        if done_cntr = "11" then
793
                            rx_done                 <= '0';
794
                            RXCHARISK_sr_done       <= (others => '1');
795
                            RXCHARISvalid_sr_done   <= (others => '0');
796
                        end if;
797
                    end if;
798
                else
799
                --- [____]
800
                    if valid_byte_cntr /= "100" then  -- No IDLE allowed, unless between two symbols: Something went wrong probably
801
                        valid_byte_cntr    <= "000";
802
                        irregular_stream   <= '0';
803
                    end if;
804
                    if done_cntr = "11" then
805
                        rx_done                 <= '0';
806
                        RXCHARISK_sr_done       <= (others => '1');
807
                        RXCHARISvalid_sr_done   <= (others => '0');
808
                    end if;
809
                end if;
810
            end if;
811
        end if;
812
    end if;
813
end process;
814
 
815
RXDATA_u           <= RXDATA_swap(63 downto 56) & RXDATA_swap(47 downto 40) & RXDATA_swap(31 downto 24) & RXDATA_swap(15 downto  8) when mode_sel = '1' else -- x4 mode 
816
                      RXDATA_sr_done(63 downto 32);                                                                                                          -- x1 mode 
817
RXCHARISK_u        <= RXCHARISK_swap(7) & RXCHARISK_swap(5) & RXCHARISK_swap(3) & RXCHARISK_swap(1) when mode_sel = '1' else                                 -- x4 mode 
818
                      RXCHARISK_sr_done(7 downto 4);                                                                                                         -- x1 mode                     
819
RXCHARISvalid_u    <= RXCHARISvalid_swap(7) & RXCHARISvalid_swap(5) & RXCHARISvalid_swap(3) & RXCHARISvalid_swap(1) when mode_sel = '1' else                 -- x4 mode 
820
                      RXCHARISvalid_sr_done(7 downto 4);                                                                                                     -- x1 mode 
821
RXDATA_l           <= RXDATA_swap(55 downto 48) & RXDATA_swap(39 downto 32) & RXDATA_swap(23 downto 16) & RXDATA_swap(7 downto  0) when mode_sel = '1' else  -- x4 mode 
822
                      RXDATA_sr_done(31 downto 0);                                                                                                           -- x1 mode 
823
RXCHARISK_l        <= RXCHARISK_swap(6) & RXCHARISK_swap(4) & RXCHARISK_swap(2) & RXCHARISK_swap(0) when mode_sel = '1' else                                 -- x4 mode 
824
                      RXCHARISK_sr_done(3 downto 0);                                                                                                         -- x1 mode
825
RXCHARISvalid_l    <= RXCHARISvalid_swap(6) & RXCHARISvalid_swap(4) & RXCHARISvalid_swap(2) & RXCHARISvalid_swap(0) when mode_sel = '1' else                 -- x4 mode 
826
                      RXCHARISvalid_sr_done(3 downto 0);                                                                                                     -- x1 mode 
827
 
828
-- RXDATA_u           <= RXDATA_swap(63 downto 56) & RXDATA_swap(47 downto 40) & RXDATA_swap(31 downto 24) & RXDATA_swap(15 downto  8);
829
-- RXCHARISK_u        <= RXCHARISK_swap(7) & RXCHARISK_swap(5) & RXCHARISK_swap(3) & RXCHARISK_swap(1);
830
-- RXDATA_l           <= RXDATA_swap(55 downto 48) & RXDATA_swap(39 downto 32) & RXDATA_swap(23 downto 16) & RXDATA_swap(7 downto  0);
831
-- RXCHARISK_l        <= RXCHARISK_swap(6) & RXCHARISK_swap(4) & RXCHARISK_swap(2) & RXCHARISK_swap(0);                   
832
-- RXCHARISvalid_u    <= RXCHARISvalid_swap(7) & RXCHARISvalid_swap(5) & RXCHARISvalid_swap(3) & RXCHARISvalid_swap(1);
833
-- RXCHARISvalid_l    <= RXCHARISvalid_swap(6) & RXCHARISvalid_swap(4) & RXCHARISvalid_swap(2) & RXCHARISvalid_swap(0);
834
 
835
upper_symbol_type  <= SYMBOL_IDLE       when RXCHARISK_u = "1111" and RXCHARISvalid_u = "1111" else
836
                      SYMBOL_CONTROL    when RXCHARISK_u = "1000" and RXCHARISvalid_u = "1111" and (RXDATA_u(31 downto 24) = SC or RXDATA_u(31 downto 24) = PD) else
837
                      SYMBOL_DATA       when RXCHARISK_u = "0000" and RXCHARISvalid_u = "1111" else
838
                      SYMBOL_ERROR;
839
 
840
lower_symbol_type  <= SYMBOL_IDLE       when RXCHARISK_l = "1111" and RXCHARISvalid_l = "1111" else
841
                      SYMBOL_CONTROL    when RXCHARISK_l = "1000" and RXCHARISvalid_l = "1111" and (RXDATA_l(31 downto 24) = SC or RXDATA_l(31 downto 24) = PD) else
842
                      SYMBOL_DATA       when RXCHARISK_l = "0000" and RXCHARISvalid_l = "1111" else
843
                      SYMBOL_ERROR;
844
 
845
-- 
846
upper_symbol_not_idle   <= '0' when upper_symbol_type = SYMBOL_IDLE  else '1';
847
lower_symbol_not_idle   <= '0' when lower_symbol_type = SYMBOL_IDLE  else '1';
848
upper_symbol_not_error  <= '0' when upper_symbol_type = SYMBOL_ERROR else '1';
849
lower_symbol_not_error  <= '0' when lower_symbol_type = SYMBOL_ERROR else '1';
850
 
851
upper_symbol_valid      <= upper_symbol_not_idle and upper_symbol_not_error;
852
lower_symbol_valid      <= lower_symbol_not_idle and lower_symbol_not_error;
853
 
854
 
855
end RTL;
856
---------------------------------------------------------------------------------------
857
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
858
-- 
859
-- RapidIO IP Library Core
860
-- 
861
-- This file is part of the RapidIO IP library project
862
-- http://www.opencores.org/cores/rio/
863
-- 
864
-- To Do:
865
-- -
866
-- 
867
-- Author(s): 
868
-- - A. Demirezen, azdem@opencores.org 
869
-- 
870
-------------------------------------------------------------------------------
871
-- 
872
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
873
-- 
874
-- This source file may be used and distributed without 
875
-- restriction provided that this copyright statement is not 
876
-- removed from the file and that any derivative work contains 
877
-- the original copyright notice and the associated disclaimer. 
878
-- 
879
-- This source file is free software; you can redistribute it 
880
-- and/or modify it under the terms of the GNU Lesser General 
881
-- Public License as published by the Free Software Foundation; 
882
-- either version 2.1 of the License, or (at your option) any 
883
-- later version. 
884
-- 
885
-- This source is distributed in the hope that it will be 
886
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
887
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
888
-- PURPOSE. See the GNU Lesser General Public License for more 
889
-- details. 
890
-- 
891
-- You should have received a copy of the GNU Lesser General 
892
-- Public License along with this source; if not, download it 
893
-- from http://www.opencores.org/lgpl.shtml 
894
-- 
895
------------------------------------------------------------------------------
896
------------------------------------------------------------------------------
897
--
898
-- File name:    pcs_tx_controller.vhd
899
-- Rev:          0.0
900
-- Description:  This entity controls the TX stream 
901
--               
902
-- 
903
------------------------------------------------------------------------------
904
------------------------------------------------------------------------------
905
library ieee;
906
use ieee.std_logic_1164.all;
907
use ieee.numeric_std.all;
908
use ieee.std_logic_unsigned.all;
909
use work.rio_common.all;
910
 
911
entity pcs_tx_controller is
912
  generic (
913
    TCQ         : time      := 100 ps
914
  );
915
  port (
916
    rst_n                   : in  std_logic;
917
    rio_clk                 : in  std_logic;  -- ~150 MHz
918
    UCLK_x2                 : in  std_logic;  --  312,5 MHz
919
    UCLK                    : in  std_logic;  --  156,25 MHz 
920
    UCLK_x2_DV2             : in  std_logic;  --  312,5 MHz @ x4 mode / 78,125 @ x1 (fallback mode) 
921
    UCLK_or_DV4             : in  std_logic;  --  156,25 MHz @ x4 mode / 39,0625 @ x1 (fallback mode)
922
    --
923
    -- Interface to the RioSerial
924
    outboundWrite_i         : in  std_logic;
925
    outboundFull_o          : out std_logic;
926
    outboundSymbol_i        : in  std_logic_vector(33 downto 0);
927
    -- outboundSymbolEmpty_i   : in  std_logic;
928
    -- outboundSymbolRead_o    : out std_logic;
929
    -- outboundSymbol_i        : in  std_logic_vector(33 downto 0);
930
    --
931
    -- Interface to the GTX transceivers
932
    TXDATA_o                : out std_logic_vector(63 downto 0);  -- N = 4
933
    TXCHARISK_o             : out std_logic_vector(7 downto 0);
934
    --
935
    -- Interface to the other blocks
936
    send_ccs_i              : in  std_logic;
937
    ccs_timer_rst_o         : out std_logic;
938
    send_idle_o             : out std_logic_vector(1 downto 0);
939
    send_K_i                : in  std_logic_vector(1 downto 0);
940
    send_A_i                : in  std_logic_vector(1 downto 0);
941
    send_R_i                : in  std_logic_vector(1 downto 0);
942
    --
943
    -- Interface to the port init
944
    TXINHIBIT_02            : in  std_logic;
945
    TXINHIBIT_others        : in  std_logic;
946
    port_initalized_i       : in  std_logic;
947
    mode_sel_i              : in  std_logic;
948
    mode_0_lane_sel_i       : in  std_logic
949
 
950
  );
951
end pcs_tx_controller;
952
 
953
architecture RTL of pcs_tx_controller is
954
 
955
-------------------------------------------------------------------------------
956
COMPONENT pcs_tx_boudary_32b_in_64b_out
957
    PORT (
958
    rst          : IN STD_LOGIC;
959
    wr_clk       : IN STD_LOGIC;
960
    rd_clk       : IN STD_LOGIC;
961
    din          : IN STD_LOGIC_VECTOR(33 DOWNTO 0);
962
    wr_en        : IN STD_LOGIC;
963
    rd_en        : IN STD_LOGIC;
964
    dout         : OUT STD_LOGIC_VECTOR(67 DOWNTO 0);
965
    full         : OUT STD_LOGIC;
966
    empty        : OUT STD_LOGIC;
967
    almost_empty : out STD_LOGIC;
968
    almost_full  : out STD_LOGIC;
969
    valid        : OUT STD_LOGIC
970
  );
971
END COMPONENT;
972
-------------------------------------------------------------------------------
973
-- COMPONENT pcs_tx_boudary_32b_v2
974
--     PORT (
975
--     rst            : IN STD_LOGIC;
976
--     wr_clk         : IN STD_LOGIC;
977
--     rd_clk         : IN STD_LOGIC;
978
--     din            : IN STD_LOGIC_VECTOR(33 DOWNTO 0);
979
--     wr_en          : IN STD_LOGIC;
980
--     rd_en          : IN STD_LOGIC;
981
--     dout           : OUT STD_LOGIC_VECTOR(33 DOWNTO 0);
982
--     full           : OUT STD_LOGIC;
983
--     empty          : OUT STD_LOGIC;
984
--     almost_empty   : OUT STD_LOGIC;
985
--     valid          : OUT STD_LOGIC
986
--   );
987
-- END COMPONENT;
988
-------------------------------------------------------------------------------
989
signal rst                  : std_logic:= '0';
990
signal fragment_counter     : std_logic_vector(9 downto 0)  := (others => '0');
991
signal outboundSymbolType   : std_logic_vector(1 downto 0)  := (others => '0');
992
signal outboundSymbol       : std_logic_vector(33 downto 0) := (others => '0');
993
signal outboundSymbolRead   : std_logic:= '0';
994
signal non_idle             : std_logic:= '0';
995
signal decrement_frag_cntr  : std_logic:= '0';
996
 
997
signal tx_fifo_full         : std_logic:= '0';
998
signal symbol_empty         : std_logic:= '0';
999
signal symbol_almost_empty  : std_logic:= '0';
1000
signal symbol_read          : std_logic:= '0';
1001
signal symbol_valid         : std_logic:= '0';
1002
-- signal symbol               : std_logic_vector(33 downto 0) := (others => '0');
1003
signal symbol               : std_logic_vector(67 downto 0) := (others => '0');
1004
signal symbol_u             : std_logic_vector(33 downto 0) := (others => '0');
1005
signal symbol_l             : std_logic_vector(33 downto 0) := (others => '0');
1006
-- signal symbol_type          : std_logic_vector(1  downto 0) := (others => '0');
1007
signal symbol_type          : std_logic_vector(3  downto 0) := (others => '0');
1008
signal symbol_type_u        : std_logic_vector(1  downto 0) := (others => '0');
1009
signal symbol_type_l        : std_logic_vector(1  downto 0) := (others => '0');
1010
 
1011
signal TXDATA               : std_logic_vector(63 downto 0);  -- N = 4
1012
signal TXCHARISK            : std_logic_vector(7 downto 0);
1013
signal TXDATA_u             : std_logic_vector(31 downto 0);
1014
signal TXCHARISK_u          : std_logic_vector(3 downto 0);
1015
signal TXDATA_l             : std_logic_vector(31 downto 0);
1016
signal TXCHARISK_l          : std_logic_vector(3 downto 0);
1017
 
1018
signal TXDATA_u_idle        : std_logic_vector(31 downto 0);
1019
signal TXDATA_l_idle        : std_logic_vector(31 downto 0);
1020
 
1021
signal word_switch          : std_logic:= '0';
1022
signal lane_switch          : std_logic_vector(1  downto 0) := (others => '0');
1023
signal cycle_switch         : std_logic_vector(1  downto 0) := (others => '0');
1024
signal read_switch          : std_logic_vector(1  downto 0) := (others => '0');
1025
 
1026
signal send_idle_q          : std_logic:= '0';
1027
signal send_idle_reg        : std_logic_vector(1 downto 0)  := (others => '0');
1028
signal send_idle            : std_logic_vector(1 downto 0)  := (others => '0');
1029
signal idle_char_type_0     : std_logic_vector(2  downto 0) := (others => '0');
1030
signal idle_char_type_1     : std_logic_vector(2  downto 0) := (others => '0');
1031
 
1032
signal send_ccs_cntr        : std_logic_vector(1  downto 0) := (others => '0');
1033
signal send_K               : std_logic_vector(1 downto 0)  := (others => '0');
1034
signal send_A               : std_logic_vector(1 downto 0)  := (others => '0');
1035
signal send_R               : std_logic_vector(1 downto 0)  := (others => '0');
1036
signal send_ccs             : std_logic:= '0';
1037
signal send_ccs_q           : std_logic:= '0';
1038
signal do_not_interrupt     : std_logic:= '0';
1039
 
1040
signal be_silent              : std_logic:= '0';
1041
signal fifo_wr_selective      : std_logic:= '0';
1042
signal fifo_wr_selective_q    : std_logic:= '0';
1043
signal fifo_wr_always_even    : std_logic:= '0';
1044
signal fifo_wr_odd_or_even    : std_logic:= '0';
1045
signal fifo_wr_evenly         : std_logic:= '0';
1046
signal outboundSymbolisData   : std_logic:= '0';
1047
signal outboundSymbolisData_q : std_logic:= '0';
1048
 
1049
signal outboundSymbol_q       : std_logic_vector(33 downto 0) := (others => '0');
1050
signal fifo_wr_evenly_q       : std_logic:= '0';
1051
-- signal send_K_ccs           : std_logic:= '0';
1052
-- signal send_R_ccs           : std_logic:= '0';
1053
-- signal send_K_q             : std_logic:= '0';
1054
-- signal send_A_q             : std_logic:= '0';
1055
-- signal send_R_q             : std_logic:= '0';
1056
----------------------------------------------------------------------------------
1057
begin
1058
-- 
1059
rst                  <= not(rst_n);
1060
 
1061
outboundSymbolType  <= outboundSymbol_i(33 downto 32);
1062
-- Filtering the ERROR symbol out
1063
outboundSymbol      <= outboundSymbol_i when (outboundSymbolType = SYMBOL_DATA or outboundSymbolType = SYMBOL_CONTROL) else
1064
                       SYMBOL_IDLE & outboundSymbol_i(31 downto 0);
1065
 
1066
fifo_wr_selective   <= outboundWrite_i when (outboundSymbolType = SYMBOL_DATA or outboundSymbolType = SYMBOL_CONTROL) else '0';
1067
 
1068
fifo_wr_always_even <= fifo_wr_selective or (fifo_wr_selective_q and fifo_wr_odd_or_even);
1069
 
1070
outboundSymbolisData <= '1' when outboundSymbolType = SYMBOL_DATA else '0';
1071
 
1072
fifo_wr_evenly  <= fifo_wr_selective or (fifo_wr_selective_q and fifo_wr_odd_or_even and not(outboundSymbolisData_q));
1073
 
1074
-- Writing to the FIFO
1075
process(rio_clk)
1076
    begin
1077
    if rising_edge(rio_clk) then
1078
        fifo_wr_selective_q     <= fifo_wr_selective;
1079
        outboundSymbolisData_q  <= outboundSymbolisData;
1080
        if fifo_wr_selective    = '1' then
1081
            fifo_wr_odd_or_even <= not(fifo_wr_odd_or_even);
1082
        elsif fifo_wr_selective_q = '1' then
1083
            fifo_wr_odd_or_even <= fifo_wr_odd_or_even and outboundSymbolisData_q; -- '0';
1084
        end if;
1085
 
1086
        outboundSymbol_q <= outboundSymbol;
1087
        fifo_wr_evenly_q <= fifo_wr_evenly;
1088
    end if;
1089
end process;
1090
 
1091
send_K <= send_K_i;
1092
send_A <= send_A_i;
1093
send_R <= send_R_i;
1094
 
1095
-- idle_char_type  <= send_K & send_A & send_R;
1096
idle_char_type_0  <= send_K(0) & send_A(0) & send_R(0);
1097
idle_char_type_1  <= send_K(1) & send_A(1) & send_R(1);
1098
 
1099
be_silent   <= '1' when TXINHIBIT_02 = '1' and TXINHIBIT_others = '1' else '0';
1100
 
1101
-- symbol_type <= symbol(33 downto 32);  
1102
symbol_type_u <= symbol_u(33 downto 32);
1103
symbol_type_l <= symbol_l(33 downto 32);
1104
 
1105
symbol_u      <= symbol(67 downto 34);
1106
symbol_l      <= symbol(33 downto 0);
1107
 
1108
send_idle(1)   <= '1'  when (send_ccs = '0')  and
1109
                         ((symbol_read = '1' and symbol_type_u = SYMBOL_IDLE) or
1110
                          (symbol_read = '0') or
1111
                          (port_initalized_i = '0'))
1112
                        else
1113
                  '0';
1114
 
1115
send_idle(0)   <= '1'  when (send_ccs = '0')  and
1116
                         ((symbol_read = '1' and symbol_type_l = SYMBOL_IDLE) or
1117
                          (symbol_read = '0') or
1118
                          (port_initalized_i = '0'))
1119
                       else
1120
                  '0';
1121
 
1122
send_idle_o <= send_idle; -- _reg; 
1123
 
1124
-- symbol_read <= not(symbol_empty) and not(send_ccs) and not(send_ccs_q);
1125
 
1126
-- Pipelining
1127
process(UCLK) -- _x2
1128
    begin
1129
    if rising_edge(UCLK) then
1130
        send_ccs        <= not(do_not_interrupt) and send_ccs_i;  -- will be high only during real CCS transmission 
1131
        -- send_idle_reg   <= send_idle;        
1132
    end if;
1133
end process;
1134
 
1135
-- Reading from the FIFO
1136
process(UCLK_or_DV4) -- UCLK_x2_DV2
1137
    begin
1138
    if rising_edge(UCLK_or_DV4) then
1139
      --   case symbol_read is
1140
      --       when '0' => 
1141
      --           symbol_read <= not(symbol_empty) and not(send_ccs) and not(send_ccs_q); -- after TCQ;                
1142
      --       when '1' => 
1143
      --           symbol_read <= not(symbol_almost_empty); -- after TCQ; -- and not(send_ccs) and not(send_ccs_q);                
1144
      --       when others => 
1145
      --           symbol_read <= '0'; -- after TCQ;
1146
      --   end case;        
1147
 
1148
    end if;
1149
end process;
1150
 
1151
tx_boundary_fifo : pcs_tx_boudary_32b_in_64b_out   -- FWFT FIFO
1152
  PORT MAP (
1153
    rst             => rst,
1154
 
1155
    wr_clk          => rio_clk,
1156
    wr_en           => fifo_wr_evenly_q, --fifo_wr_always_even, --outboundWrite_i,
1157
    din             => outboundSymbol_q,
1158
    full            => open, -- outboundFull_o,
1159
    almost_full     => outboundFull_o,
1160
 
1161
    rd_clk          => UCLK_or_DV4,
1162
    rd_en           => symbol_read,
1163
    dout            => symbol,
1164
    empty           => symbol_empty,
1165
    almost_empty    => symbol_almost_empty,
1166
    valid           => symbol_valid
1167
  );
1168
 
1169
-- FIFO read / TX output process
1170
process(rst_n, UCLK) -- UCLK_x2
1171
    begin
1172
    if rst_n = '0'  then
1173
 
1174
        ccs_timer_rst_o  <= '0';
1175
        do_not_interrupt <= '0';
1176
        TXDATA_u         <= (others => '0');
1177
        TXCHARISK_u      <= (others => '0');
1178
        TXDATA_l         <= (others => '0');
1179
        TXCHARISK_l      <= (others => '0');
1180
        cycle_switch     <= (others => '0');
1181
        read_switch      <= (others => '0');
1182
        symbol_read      <= '0';
1183
 
1184
    elsif rising_edge(UCLK) then
1185
 
1186
      if be_silent = '0' then -- Transmitters are NOT inhibitied
1187
        if send_ccs = '1' or send_ccs_q = '1' then -- Transmitting the clock compensation sequence (ccs) = |K|,|R|,|R|,|R|
1188
            symbol_read      <= '0';
1189
            if send_ccs_q = '0' then
1190
                TXDATA_u        <= K_column;
1191
                TXCHARISK_u     <= (others => '1');
1192
                TXDATA_l        <= R_column;
1193
                TXCHARISK_l     <= (others => '1');
1194
                ccs_timer_rst_o <= '1';
1195
            else
1196
                TXDATA_u        <= R_column;
1197
                TXCHARISK_u     <= (others => '1');
1198
                TXDATA_l        <= R_column;
1199
                TXCHARISK_l     <= (others => '1');
1200
            end if;
1201
        else  -- Transmitting the IDLE sequence or the CONTROL/DATA symbols 
1202
 
1203
            read_switch  <= read_switch + '1';
1204
            if read_switch = "00" then
1205
                case symbol_read is
1206
                    when '0' =>
1207
                        symbol_read         <= not(symbol_empty); -- and not(send_ccs) and not(send_ccs_q); -- after TCQ; 
1208
                        do_not_interrupt    <= not(symbol_empty);
1209
                    when '1' =>
1210
                        symbol_read         <= not(symbol_almost_empty); -- after TCQ; -- and not(send_ccs) and not(send_ccs_q);        
1211
                        do_not_interrupt    <= not(symbol_almost_empty);
1212
                    when others =>
1213
                        symbol_read         <= '0'; -- after TCQ;
1214
                        do_not_interrupt    <= '0';
1215
                end case;
1216
            end if;
1217
 
1218
            ccs_timer_rst_o <= '0';
1219
            if symbol_read = '1' then -- two symbols have been read, at least one of them is non-idle, they should be forwarded in 1 or 4 cycles
1220
                case mode_sel_i is
1221
                    when '1' => -- Lane stripping (x4 mode: rd_clk = UCLK)     
1222
                        case symbol_type_u is
1223
                            when SYMBOL_DATA =>
1224
                                TXDATA_u      <= symbol_u(31 downto 24) & symbol_u(23 downto 16) & symbol_u(15 downto 8) & symbol_u(7 downto 0);
1225
                                TXCHARISK_u   <= (others => '0');
1226
                            when SYMBOL_CONTROL =>
1227
                                TXDATA_u      <= symbol_u(31 downto 24) & symbol_u(23 downto 16) & symbol_u(15 downto 8) & symbol_u(7 downto 0);
1228
                                TXCHARISK_u   <= "1000";
1229
                            when SYMBOL_IDLE =>
1230
                                TXDATA_u      <= TXDATA_u_idle;
1231
                                TXCHARISK_u   <= (others => '1');
1232
                            when others =>
1233
                                -- dummy
1234
                                TXDATA_u      <= TXDATA_u_idle;
1235
                                TXCHARISK_u   <= (others => '1');
1236
                        end case;
1237
                        case symbol_type_l is
1238
                            when SYMBOL_DATA =>
1239
                                TXDATA_l      <= symbol_l(31 downto 24) & symbol_l(23 downto 16) & symbol_l(15 downto 8) & symbol_l(7 downto 0);
1240
                                TXCHARISK_l   <= (others => '0');
1241
                            when SYMBOL_CONTROL =>
1242
                                TXDATA_l      <= symbol_l(31 downto 24) & symbol_l(23 downto 16) & symbol_l(15 downto 8) & symbol_l(7 downto 0);
1243
                                TXCHARISK_l   <= "1000";
1244
                            when SYMBOL_IDLE =>
1245
                                TXDATA_l      <= TXDATA_l_idle;
1246
                                TXCHARISK_l   <= (others => '1');
1247
                            when others =>
1248
                                -- dummy
1249
                                TXDATA_l      <= TXDATA_l_idle;
1250
                                TXCHARISK_l   <= (others => '1');
1251
                        end case;
1252
                    when '0' => -- Slow motion read (x1 mode: rd_clk = UCLK_DV4)
1253
                        cycle_switch    <= cycle_switch + '1';
1254
                        -- Cycle | Symbol part to be sent  
1255
                        ---------|----------------------
1256
                        --   00  | symbol_u(31 downto 16)
1257
                        --   01  | symbol_u(15 downto 0)
1258
                        --   10  | symbol_l(31 downto 16)
1259
                        --   11  | symbol_l(15 downto 0)
1260
                        case cycle_switch(1) is
1261
                            when '0' =>
1262
                                case cycle_switch(0) is
1263
                                    when '0' => --   00 
1264
                                        if symbol_type_u /= SYMBOL_IDLE then
1265
                                            TXDATA_u        <= symbol_u(31 downto 24) & symbol_u(31 downto 24) & symbol_u(31 downto 24) & symbol_u(31 downto 24);
1266
                                            if symbol_type_u = SYMBOL_DATA then
1267
                                                TXCHARISK_u     <= (others => '0');
1268
                                            else -- if symbol_type_u = SYMBOL_CONTROL then 
1269
                                                TXCHARISK_u     <= (others => '1');
1270
                                            end if;
1271
                                            TXDATA_l        <= symbol_u(23 downto 16) & symbol_u(23 downto 16) & symbol_u(23 downto 16) & symbol_u(23 downto 16);
1272
                                            TXCHARISK_l     <= (others => '0');
1273
                                        else -- if symbol_type_u = SYMBOL_IDLE then                                         
1274
                                            TXDATA_u      <= TXDATA_u_idle;
1275
                                            TXCHARISK_u   <= (others => '1');
1276
                                            TXDATA_l      <= TXDATA_l_idle;
1277
                                            TXCHARISK_l   <= (others => '1');
1278
                                        end if;
1279
                                    when '1' => --   01  
1280
                                        if symbol_type_u /= SYMBOL_IDLE then
1281
                                            TXDATA_u        <= symbol_u(15 downto 8) & symbol_u(15 downto 8) & symbol_u(15 downto 8) & symbol_u(15 downto 8);
1282
                                            TXCHARISK_u     <= (others => '0'); -- This is the second part: does not matter control or data
1283
                                            TXDATA_l        <= symbol_u(7 downto 0) & symbol_u(7 downto 0) & symbol_u(7 downto 0) & symbol_u(7 downto 0);
1284
                                            TXCHARISK_l     <= (others => '0');
1285
                                        else -- if symbol_type_u = SYMBOL_IDLE then                                         
1286
                                            TXDATA_u      <= TXDATA_u_idle;
1287
                                            TXCHARISK_u   <= (others => '1');
1288
                                            TXDATA_l      <= TXDATA_l_idle;
1289
                                            TXCHARISK_l   <= (others => '1');
1290
                                        end if;
1291
                                    when others =>
1292
                                    -- dummy
1293
                                end case;
1294
                            when '1' =>
1295
                                case cycle_switch(0) is
1296
                                    when '0' =>
1297
                                        if symbol_type_l /= SYMBOL_IDLE then
1298
                                            TXDATA_u        <= symbol_l(31 downto 24) & symbol_l(31 downto 24) & symbol_l(31 downto 24) & symbol_l(31 downto 24);
1299
                                            if symbol_type_l = SYMBOL_DATA then
1300
                                                TXCHARISK_u     <= (others => '0');
1301
                                            else -- if symbol_type_l = SYMBOL_CONTROL then 
1302
                                                TXCHARISK_u     <= (others => '1');
1303
                                            end if;
1304
                                            TXDATA_l        <= symbol_l(23 downto 16) & symbol_l(23 downto 16) & symbol_l(23 downto 16) & symbol_l(23 downto 16);
1305
                                            TXCHARISK_l     <= (others => '0');
1306
                                        else -- if symbol_type_l = SYMBOL_IDLE then                                         
1307
                                            TXDATA_u      <= TXDATA_u_idle;
1308
                                            TXCHARISK_u   <= (others => '1');
1309
                                            TXDATA_l      <= TXDATA_l_idle;
1310
                                            TXCHARISK_l   <= (others => '1');
1311
                                        end if;
1312
                                    when '1' =>
1313
                                        if symbol_type_l /= SYMBOL_IDLE then
1314
                                            TXDATA_u        <= symbol_l(15 downto 8) & symbol_l(15 downto 8) & symbol_l(15 downto 8) & symbol_l(15 downto 8);
1315
                                            TXCHARISK_u     <= (others => '0'); -- This is the second part: does not matter control or data
1316
                                            TXDATA_l        <= symbol_l(7 downto 0) & symbol_l(7 downto 0) & symbol_l(7 downto 0) & symbol_l(7 downto 0);
1317
                                            TXCHARISK_l     <= (others => '0');
1318
                                        else -- if symbol_type_l = SYMBOL_IDLE then                                         
1319
                                            TXDATA_u      <= TXDATA_u_idle;
1320
                                            TXCHARISK_u   <= (others => '1');
1321
                                            TXDATA_l      <= TXDATA_l_idle;
1322
                                            TXCHARISK_l   <= (others => '1');
1323
                                        end if;
1324
                                    when others =>
1325
                                    -- dummy
1326
                                end case;
1327
                            when others =>
1328
                                -- dummy
1329
                        end case;
1330
 
1331
                    when others =>
1332
                        -- dummy
1333
                end case;
1334
            -----------------------------------------------------------------------------
1335
            else -- No Symbols are present at the FIFO output: Transmitting an idle sequence: |K| or |A| or |R|
1336
                TXDATA_u         <= TXDATA_u_idle;
1337
                TXCHARISK_u      <= (others => '1');
1338
                TXDATA_l         <= TXDATA_l_idle;
1339
                TXCHARISK_l      <= (others => '1');
1340
            end if;
1341
        end if;
1342
      else -- Transmitters are inhibitied
1343
        TXDATA_u         <= x"BCBCBCBC"    ;
1344
        TXCHARISK_u      <= (others => '1');
1345
        TXDATA_l         <= x"FDFDFDFD"    ;
1346
        TXCHARISK_l      <= (others => '1');
1347
      end if;
1348
    end if;
1349
end process;
1350
 
1351
-- Combinational idle drive process
1352
process(idle_char_type_0, idle_char_type_1)
1353
    begin
1354
    case idle_char_type_1 is
1355
        when "100" =>  -- |K| (~%50)
1356
            TXDATA_u_idle      <= K_column;
1357
 
1358
        when "010" => -- |A| (1/16 .. 1/32)
1359
            TXDATA_u_idle      <= A_column;
1360
 
1361
        when "001" => -- |R| (~%50)
1362
            TXDATA_u_idle      <= R_column;
1363
 
1364
        when others =>
1365
            -- dummy
1366
            TXDATA_u_idle      <= K_column;
1367
    end case;
1368
    case idle_char_type_0 is
1369
        when "100" =>  -- |K| (~%50)
1370
            TXDATA_l_idle      <= K_column;
1371
 
1372
        when "010" => -- |A| (1/16 .. 1/32)
1373
            TXDATA_l_idle      <= A_column;
1374
 
1375
        when "001" => -- |R| (~%50)
1376
            TXDATA_l_idle      <= R_column;
1377
 
1378
        when others =>
1379
            -- dummy
1380
            TXDATA_l_idle      <= R_column;
1381
    end case;
1382
end process;
1383
 
1384
-- TXDATA buffering by UCLK
1385
process(UCLK)
1386
    begin
1387
    if rising_edge(UCLK) then
1388
        ------------------
1389
        -- MUST BE SWAPPED
1390
        TXDATA_o    <=   TXDATA_u( 7 downto  0) & TXDATA_l( 7 downto  0) & TXDATA_u(15 downto  8) & TXDATA_l(15 downto  8)
1391
                       & TXDATA_u(23 downto 16) & TXDATA_l(23 downto 16) & TXDATA_u(31 downto 24) & TXDATA_l(31 downto 24);
1392
        TXCHARISK_o <= TXCHARISK_u(0) & TXCHARISK_l(0) & TXCHARISK_u(1) & TXCHARISK_l(1) & TXCHARISK_u(2) & TXCHARISK_l(2) & TXCHARISK_u(3) & TXCHARISK_l(3);
1393
        ------------------
1394
    end if;
1395
end process;
1396
 
1397
-- Delaying send_ccs  
1398
process(UCLK)
1399
    begin
1400
    if rising_edge(UCLK) then
1401
        if be_silent = '0' then
1402
            send_ccs_q <= send_ccs; ---  
1403
        else
1404
            send_ccs_q <= '0';
1405
        end if;
1406
    end if;
1407
end process;
1408
 
1409
end RTL;
1410
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
1411
-- 
1412
-- RapidIO IP Library Core
1413
-- 
1414
-- This file is part of the RapidIO IP library project
1415
-- http://www.opencores.org/cores/rio/
1416
-- 
1417
-- To Do:
1418
-- -
1419
-- 
1420
-- Author(s): 
1421
-- - A. Demirezen, azdem@opencores.org 
1422
-- 
1423
-------------------------------------------------------------------------------
1424
-- 
1425
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
1426
-- 
1427
-- This source file may be used and distributed without 
1428
-- restriction provided that this copyright statement is not 
1429
-- removed from the file and that any derivative work contains 
1430
-- the original copyright notice and the associated disclaimer. 
1431
-- 
1432
-- This source file is free software; you can redistribute it 
1433
-- and/or modify it under the terms of the GNU Lesser General 
1434
-- Public License as published by the Free Software Foundation; 
1435
-- either version 2.1 of the License, or (at your option) any 
1436
-- later version. 
1437
-- 
1438
-- This source is distributed in the hope that it will be 
1439
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
1440
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
1441
-- PURPOSE. See the GNU Lesser General Public License for more 
1442
-- details. 
1443
-- 
1444
-- You should have received a copy of the GNU Lesser General 
1445
-- Public License along with this source; if not, download it 
1446
-- from http://www.opencores.org/lgpl.shtml 
1447
-- 
1448
------------------------------------------------------------------------------
1449
------------------------------------------------------------------------------
1450
--
1451
-- File name:    port_init_fsms.vhd
1452
-- Rev:          0.0
1453
-- Description:  This entity does the 1x/Nx port init according to the 
1454
--               RIO Sepec. Part-6, subchapter 4.2
1455
-- 
1456
------------------------------------------------------------------------------
1457
library ieee;
1458
use ieee.std_logic_1164.all;
1459
use ieee.numeric_std.all;
1460
use ieee.std_logic_unsigned.all;
1461
use work.rio_common.all;
1462
--use work.rio_common_sim.all;
1463
 
1464
entity port_init_fsms is
1465
  generic (
1466
    TCQ         : time      := 100 ps
1467
  );
1468
  port (
1469
    rst_n               : in  std_logic;
1470
    UCLK_x2             : in  std_logic;
1471
    UCLK                : in  std_logic;
1472
    UCLK_DV4            : in  std_logic;
1473
    UCLK_DV_1024        : in  std_logic;
1474
 
1475
    force_reinit        : in  std_logic:='0';   -- force retraining
1476
    mode_sel            : out std_logic;        -- 0: x1 fallback mode / 1: xN Mode
1477
    mode_0_lane_sel     : out std_logic;        -- If mode_sel = 0 then 0: Lane 0 is active(R), 1: Lane 2 is active else don't care
1478
    port_initalized     : out std_logic;        -- 1: Port initialization is successfully complete
1479
    lane_sync           : out std_logic_vector(N-1 downto 0); -- Lane is synchoronised
1480
    RXCHARISvalid       : out std_logic_vector(N*2-1 downto 0);
1481
 
1482
    -- GTXRESET            : out std_logic;
1483
    TXINHIBIT_02        : out std_logic;
1484
    TXINHIBIT_others    : out std_logic;
1485
    ENCHANSYNC          : out std_logic;
1486
    -- TXDATA              : out std_logic_vector(N*16-1 downto 0);
1487
    -- TXCHARISK           : out std_logic_vector(N*2-1 downto 0);
1488
    PLLLKDET            : in  std_logic;
1489
    RXDATA              : in  std_logic_vector(N*16-1 downto 0);
1490
    RXCHARISK           : in  std_logic_vector(N*2-1 downto 0);
1491
    RXCHARISCOMMA       : in  std_logic_vector(N*2-1 downto 0);
1492
    RXBYTEISALIGNED     : in  std_logic_vector(N-1 downto 0);
1493
    RXBYTEREALIGN       : in  std_logic_vector(N-1 downto 0);
1494
    RXELECIDLE          : in  std_logic_vector(N-1 downto 0);
1495
    RXDISPERR           : in  std_logic_vector(N*2-1 downto 0);
1496
    RXNOTINTABLE        : in  std_logic_vector(N*2-1 downto 0);
1497
    RXBUFERR            : in  std_logic;
1498
    RXBUFRST            : out std_logic;
1499
    CHBONDDONE          : in  std_logic_vector(N-1 downto 0)
1500
  );
1501
end port_init_fsms;
1502
 
1503
architecture rtl of port_init_fsms is
1504
-------------------------------------------------------------------------------------------------------------------------------------------
1505
-- Lane_Synchronization State Machine 
1506
type lane_sync_states is (NO_SYNC, NO_SYNC_1, NO_SYNC_2, NO_SYNC_2a, NO_SYNC_2b, NO_SYNC_3, SYNC, SYNCa, SYNCb, SYNC_1, SYNC_2, SYNC_2a, SYNC_2b, SYNC_3, SYNC_4);
1507
type lane_sync_states_array is array (N-1 downto 0) of lane_sync_states;
1508
 
1509
signal lane_sync_state_n : lane_sync_states_array           := (others => NO_SYNC);
1510
signal lane_sync_n       : std_logic_vector(N-1 downto 0)   := (others => '0');
1511
signal Kcounter_n        : Kcounter_array_type              := (others => (others => '0'));
1512
signal Vcounter_n        : Vcounter_array_type              := (others => (others => '0'));
1513
signal Icounter_n        : Icounter_array_type              := (others => (others => '0'));
1514
signal code_group_valid  : std_logic_vector(N*2-1 downto 0) := (others => '0');
1515
-------------------------------------------------------------------------------------------------------------------------------------------
1516
-- Lane_Alignment State Machine
1517
type lane_alignment_states is (NOT_ALIGNED, NOT_ALIGNED_1, NOT_ALIGNED_2, ALIGNED, ALIGNED_1, ALIGNED_2, ALIGNED_3);
1518
 
1519
signal lane_alignment_state : lane_alignment_states          := NOT_ALIGNED;
1520
signal N_lanes_aligned      : std_logic                      := '0';
1521
signal Acounter             : std_logic_vector(2 downto 0)   := (others => '0');
1522
signal Mcounter             : Mcounter_type                  := (others => '0');
1523
signal lane_alignment_reset : std_logic                      := '0';
1524
signal N_lane_sync          : std_logic                      := '0';
1525
constant N_lanes_all_high   : std_logic_vector(N-1 downto 0) := (others => '1');
1526
constant N_lanes_all_low    : std_logic_vector(N-1 downto 0) := (others => '0');
1527
 
1528
signal A_column_valid       : std_logic := '0';
1529
signal align_error          : std_logic := '0';
1530
signal A_column_valid_upper : std_logic := '0';
1531
signal align_error_upper    : std_logic := '0';
1532
signal A_column_valid_lower : std_logic := '0';
1533
signal align_error_lower    : std_logic := '0';
1534
 
1535
signal RXCHARIS_A_upper     : std_logic_vector(N-1 downto 0) := (others => '0');
1536
signal RXCHARIS_A_lower     : std_logic_vector(N-1 downto 0) := (others => '0');
1537
-------------------------------------------------------------------------------------------------------------------------------------------
1538
-- begin --dummy   
1539
-- 1x/Nx Mode Init State Machine
1540
type mode_init_states is (SILENT, SEEK, DISCOVERY, x1_RECOVERY, Nx_MODE, x1_MODE_LANE0, x1_MODE_LANE2);
1541
 
1542
signal mode_init_state      : mode_init_states          := SILENT;
1543
signal lanes02_drvr_oe      : std_logic := '0';
1544
signal N_lanes_drvr_oe      : std_logic := '0';
1545
signal Nx_mode_active       : std_logic := '0';
1546
signal receive_lane2        : std_logic := '0';
1547
signal force_reinit_reg     : std_logic := '0';
1548
signal force_reinit_clear   : std_logic := '0';
1549
 
1550
signal silence_timer_en     : std_logic := '0';
1551
signal silence_timer_done   : std_logic := '0';
1552
signal silence_timer        : std_logic_vector(4 downto 0)   := (others => '0');
1553
 
1554
signal disc_tmr_en          : std_logic := '0';
1555
signal disc_tmr_done        : std_logic := '0';
1556
signal disc_tmr             : std_logic_vector(15 downto 0)   := (others => '0');
1557
 
1558
signal port_initalized_reg  : std_logic := '0';
1559
 
1560
signal idle_selected        : std_logic := '1'; -- Only IDLE1 is to be used
1561
signal Nx_mode_enabled      : std_logic := '1'; -- Nx mode is to be always enabled
1562
signal force_1x_mode        : std_logic := '0'; -- don't force 1x mode
1563
signal force_laneR          : std_logic := '0'; -- don't care, when force_1x_mode = 0
1564
 
1565
signal lane_ready_n         : std_logic_vector(N-1 downto 0)   := (others => '0');
1566
signal rcvr_trained_n       : std_logic_vector(N-1 downto 0)   := (others => '0');
1567
signal N_lanes_ready        : std_logic := '0';
1568
 
1569
signal rxbufrst_cntr        : std_logic_vector(2 downto 0)   := (others => '0');
1570
signal rxbuferr_reg         : std_logic := '0';
1571
-------------------------------------------------------------------------------------------------------------------------------------------
1572
begin
1573
 
1574
lane_sync <= lane_sync_n;
1575
----------------------------------------------------------------
1576
-- Figure 4-14. Lane_Synchronization State Machine for N Lanes
1577
GEN_LANE_SYNC_FSM: for i in 0 to N-1 generate
1578
 
1579
code_group_valid(i*2)   <= not(RXNOTINTABLE(i*2)  ) and not(RXDISPERR(i*2)  );
1580
code_group_valid(i*2+1) <= not(RXNOTINTABLE(i*2+1)) and not(RXDISPERR(i*2+1));
1581
 
1582
RXCHARISvalid(i*2)    <= code_group_valid(i*2)  ;
1583
RXCHARISvalid(i*2+1)  <= code_group_valid(i*2+1);
1584
 
1585
process(rst_n, UCLK)  -- (UCLK_x2) -- 
1586
    begin
1587
 
1588
    if rst_n = '0'  then
1589
 
1590
        lane_sync_state_n(i) <= NO_SYNC;
1591
        lane_sync_n(i)       <= '0';
1592
        Kcounter_n(i)        <= (others => '0');
1593
        Vcounter_n(i)        <= (others => '0');
1594
 
1595
    elsif rising_edge(UCLK) then
1596
 
1597
        case lane_sync_state_n(i) is
1598
            when NO_SYNC =>
1599
                -- change(signal_detect[n])
1600
                if RXELECIDLE(i) = '1' then
1601
                    lane_sync_n(i)       <= '0';
1602
                    Kcounter_n(i)        <= (others => '0');
1603
                    Vcounter_n(i)        <= (others => '0');
1604
                -- signal_detect[n] & /COMMA/   [ KK-- ] : /K/ is being detected at the upper half
1605
                elsif (code_group_valid(i*2+1) = '1' and RXCHARISCOMMA(i*2+1) = '1') then
1606
                    -- signal_detect[n] & /COMMA/   [ --KK ] :  /K/ is being detected also at the lower half
1607
                    if (code_group_valid(i*2) = '1' and RXCHARISCOMMA(i*2) = '1') then
1608
                        lane_sync_state_n(i) <= NO_SYNC_2;
1609
                        Kcounter_n(i)        <= Kcounter_n(i) + "10";
1610
                        Vcounter_n(i)        <= Vcounter_n(i) + "10";
1611
                    -- signal_detect[n]         [ --VV ] :  At the lower half: no comma, but valid 
1612
                    elsif (code_group_valid(i*2) = '1') then
1613
                        lane_sync_state_n(i) <= NO_SYNC_2;
1614
                        Kcounter_n(i)        <= Kcounter_n(i) + '1';
1615
                        Vcounter_n(i)        <= Vcounter_n(i) + "10";
1616
                    -- do nothing                     
1617
                    else
1618
                        lane_sync_n(i)       <= '0';
1619
                        Kcounter_n(i)        <= (others => '0');
1620
                        Vcounter_n(i)        <= (others => '0');
1621
                    end if;
1622
                ----------------------------------------------------------------------------------------------    
1623
                -- signal_detect[n] & /COMMA/   [ --KK ] :  /K/ is being detected only at the lower half
1624
                elsif (code_group_valid(i*2) = '1' and RXCHARISCOMMA(i*2) = '1') then
1625
                    lane_sync_state_n(i) <= NO_SYNC_2;
1626
                    Kcounter_n(i)        <= Kcounter_n(i) + '1';
1627
                    Vcounter_n(i)        <= Vcounter_n(i) + '1';
1628
                ----------------------------------------------------------------------------------------------    
1629
                -- !signal_detect[n] | !/COMMA/ 
1630
                else
1631
                    lane_sync_n(i)       <= '0';
1632
                    Kcounter_n(i)        <= (others => '0');
1633
                    Vcounter_n(i)        <= (others => '0');
1634
                end if;
1635
                -- -- change(signal_detect[n])
1636
                -- if RXELECIDLE(i) = '1' then
1637
                --     lane_sync_n(i)       <= '0';      
1638
                --     Kcounter_n(i)        <= (others => '0');       
1639
                --     Vcounter_n(i)        <= (others => '0'); 
1640
                -- -- signal_detect[n] & /COMMA/   [ KK-- ] : /K/ is being detected at the upper half
1641
                -- elsif (code_group_valid(i*2+1) = '1' and RXCHARISCOMMA(i*2+1) = '1') then
1642
                --     lane_sync_state_n(i) <= NO_SYNC_2a;               
1643
                --     Kcounter_n(i)        <= Kcounter_n(i) + '1';       
1644
                --     Vcounter_n(i)        <= Vcounter_n(i) + '1';                    
1645
                -- -- signal_detect[n] & /COMMA/   [ --KK ] :  /K/ is being detected at the lower half
1646
                -- elsif (code_group_valid(i*2) = '1' and RXCHARISCOMMA(i*2) = '1') then 
1647
                --     lane_sync_state_n(i) <= NO_SYNC_2b;               
1648
                --     Kcounter_n(i)        <= Kcounter_n(i) + '1';       
1649
                --     Vcounter_n(i)        <= Vcounter_n(i) + '1';                       
1650
                -- -- !signal_detect[n] | !/COMMA/ 
1651
                -- else
1652
                --     lane_sync_n(i)       <= '0';      
1653
                --     Kcounter_n(i)        <= (others => '0');       
1654
                --     Vcounter_n(i)        <= (others => '0');                     
1655
                -- end if;
1656
 
1657
            -- when NO_SYNC_1 =>           
1658
 
1659
            when NO_SYNC_2 =>
1660
                -- [ IIXX or XXII ] -- One of both /INVALID/  
1661
                if (code_group_valid(i*2) = '0' or code_group_valid(i*2+1) = '0') then
1662
                    lane_sync_state_n(i) <= NO_SYNC;
1663
                    lane_sync_n(i)       <= '0';
1664
                    Kcounter_n(i)        <= (others => '0');
1665
                    Vcounter_n(i)        <= (others => '0');
1666
                -- [ KKKK ]         -- Both /COMMA/  
1667
                elsif (RXCHARISCOMMA(i*2) = '1' and RXCHARISCOMMA(i*2+1) = '1') then
1668
                    -- (Kcounter[n] > 126) & (Vcounter[n] > Vmin-1) 
1669
                    if Kcounter_n(i) >= Kmin and Vcounter_n(i) >= Vmin then
1670
                        lane_sync_state_n(i) <= SYNC;
1671
                    -- (Kcounter[n] < 127) | (Vcounter[n] < Vmin) 
1672
                    else
1673
                        Kcounter_n(i)        <= Kcounter_n(i) + "10";
1674
                        Vcounter_n(i)        <= Vcounter_n(i) + "10";
1675
                    end if;
1676
                -- [ KKVV or VVKK ] -- One of both /COMMA/  
1677
                elsif (RXCHARISCOMMA(i*2) = '1' or RXCHARISCOMMA(i*2+1) = '1') then
1678
                    -- (Kcounter[n] > 126) & (Vcounter[n] > Vmin-1) 
1679
                    if Kcounter_n(i) >= Kmin and Vcounter_n(i) >= Vmin then
1680
                        lane_sync_state_n(i) <= SYNC;
1681
                    -- (Kcounter[n] < 127) | (Vcounter[n] < Vmin) 
1682
                    else
1683
                        Kcounter_n(i)        <= Kcounter_n(i) + '1' ;
1684
                        Vcounter_n(i)        <= Vcounter_n(i) + "10";
1685
                    end if;
1686
 
1687
                -- [ VVVV ]         -- None of both /COMMA/, but both /VALID/  
1688
                else -- if RXCHARISCOMMA(i*2) = '0') and RXCHARISCOMMA(i*2+1) = '0') then    
1689
                    -- (Kcounter[n] > 126) & (Vcounter[n] > Vmin-1) 
1690
                    if Kcounter_n(i) >= Kmin and Vcounter_n(i) >= Vmin then
1691
                        lane_sync_state_n(i) <= SYNC;
1692
                    -- (Kcounter[n] < 127) | (Vcounter[n] < Vmin) 
1693
                    else
1694
                        Vcounter_n(i)        <= Vcounter_n(i) + "10";
1695
                    end if;
1696
                end if;
1697
 
1698
            -- when NO_SYNC_2a =>             
1699
            --     -- !(/COMMA/|/INVALID/)
1700
            --     if (code_group_valid(i*2) = '1' and not(RXCHARISCOMMA(i*2) = '1')) then --RXCHARISK(i*2) = '1' and RXDATA(i*16+7 downto i*16) = x"BC")) then
1701
            --         lane_sync_state_n(i) <= NO_SYNC_2b;                
1702
            --         Vcounter_n(i)        <= Vcounter_n(i) + '1';                      
1703
            --     -- /COMMA/  
1704
            --     elsif (code_group_valid(i*2) = '1' and RXCHARISCOMMA(i*2) = '1') then --RXCHARISK(i*2) = '1' and RXDATA(i*16+7 downto i*16) = x"BC") then
1705
            --         -- (Kcounter[n] > 126) & (Vcounter[n] > Vmin-1) 
1706
            --         if Kcounter_n(i) >= Kmin and Vcounter_n(i) >= Vmin then 
1707
            --             lane_sync_state_n(i) <= SYNCb;                              
1708
            --         -- (Kcounter[n] < 127) | (Vcounter[n] < Vmin) 
1709
            --         else                                  
1710
            --             lane_sync_state_n(i) <= NO_SYNC_2b;               
1711
            --             Kcounter_n(i)        <= Kcounter_n(i) + '1';       
1712
            --             Vcounter_n(i)        <= Vcounter_n(i) + '1';                               
1713
            --         end if;                           
1714
            --     -- /INVALID/  
1715
            --     elsif (code_group_valid(i*2) = '0') then
1716
            --         lane_sync_state_n(i) <= NO_SYNC;                           
1717
            --         lane_sync_n(i)       <= '0';      
1718
            --         Kcounter_n(i)        <= (others => '0');       
1719
            --         Vcounter_n(i)        <= (others => '0');                     
1720
            --     end if;                
1721
            -- 
1722
            -- when NO_SYNC_2b =>              
1723
            --     -- !(/COMMA/|/INVALID/)
1724
            --     if (code_group_valid(i*2+1) = '1' and not(RXCHARISCOMMA(i*2+1) = '1')) then --RXCHARISK(i*2+1) = '1' and RXDATA(i*16+15 downto i*16+8) = x"BC")) then
1725
            --         lane_sync_state_n(i) <= NO_SYNC_2a;                
1726
            --         Vcounter_n(i)        <= Vcounter_n(i) + '1';                                          
1727
            --     -- /COMMA/  
1728
            --     elsif (code_group_valid(i*2+1) = '1' and RXCHARISCOMMA(i*2+1) = '1') then --RXCHARISK(i*2+1) = '1' and RXDATA(i*16+15 downto i*16+8) = x"BC") then
1729
            --         -- (Kcounter[n] > 126) & (Vcounter[n] > Vmin-1) 
1730
            --         if Kcounter_n(i) >= Kmin and Vcounter_n(i) >= Vmin then 
1731
            --             lane_sync_state_n(i) <= SYNCa;                              
1732
            --         -- (Kcounter[n] < 127) | (Vcounter[n] < Vmin) 
1733
            --         else                                  
1734
            --             lane_sync_state_n(i) <= NO_SYNC_2a;               
1735
            --             Kcounter_n(i)        <= Kcounter_n(i) + '1';       
1736
            --             Vcounter_n(i)        <= Vcounter_n(i) + '1';                               
1737
            --         end if;                           
1738
            --     -- /INVALID/  
1739
            --     elsif (code_group_valid(i*2+1) = '0') then
1740
            --         lane_sync_state_n(i) <= NO_SYNC;                           
1741
            --         lane_sync_n(i)       <= '0';      
1742
            --         Kcounter_n(i)        <= (others => '0');       
1743
            --         Vcounter_n(i)        <= (others => '0');                       
1744
            --     end if;
1745
 
1746
            -- when NO_SYNC_3 => 
1747
 
1748
            when SYNC =>
1749
                -- Both /VALID/  
1750
                if (code_group_valid(i*2) = '1' and code_group_valid(i*2+1) = '1') then
1751
                    lane_sync_n(i)       <= '1';
1752
                    Icounter_n(i)        <= (others => '0');
1753
                -- One of both /INVALID/  
1754
                elsif (code_group_valid(i*2) = '1' or code_group_valid(i*2+1) = '1') then
1755
                    Icounter_n(i)        <= Icounter_n(i) + '1';
1756
                    lane_sync_state_n(i) <= SYNC_2;
1757
                -- Both /INVALID/        
1758
                else
1759
                    Icounter_n(i)        <= Icounter_n(i) + "10";
1760
                    lane_sync_state_n(i) <= SYNC_2;
1761
                end if;
1762
            -- 
1763
            -- when SYNCa =>                      
1764
            --     -- /INVALID/  
1765
            --     if (code_group_valid(i*2) = '0') then      
1766
            --         Icounter_n(i)        <= Icounter_n(i) + '1';                      
1767
            --         lane_sync_state_n(i) <= SYNC_2b;                         
1768
            --     -- /VALID/      
1769
            --     else 
1770
            --         lane_sync_state_n(i) <= SYNCb;                           
1771
            --         lane_sync_n(i)       <= '1';        
1772
            --         Icounter_n(i)        <= (others => '0');                       
1773
            --     end if;
1774
            --     
1775
            -- when SYNCb =>                      
1776
            --     -- /INVALID/  
1777
            --     if (code_group_valid(i*2+1) = '0') then
1778
            --         Icounter_n(i)        <= Icounter_n(i) + '1';        
1779
            --         lane_sync_state_n(i) <= SYNC_2a;     
1780
            --     -- /VALID/    
1781
            --     else 
1782
            --         lane_sync_state_n(i) <= SYNCa;                              
1783
            --         lane_sync_n(i)       <= '1';        
1784
            --         Icounter_n(i)        <= (others => '0');                      
1785
            --     end if;
1786
 
1787
            -- when SYNC_1 => 
1788
 
1789
            when SYNC_2 =>
1790
                -- Both /VALID/  
1791
                if (code_group_valid(i*2) = '1' and code_group_valid(i*2+1) = '1') then
1792
                    Vcounter_n(i)  <= Vcounter_n(i) + "10";
1793
                    -- (Vcounter[n] < 255) 
1794
                    if Vcounter_n(i) < x"FF" then
1795
                        -- do nothing
1796
                        lane_sync_state_n(i) <= SYNC_2;
1797
                    -- (Vcounter[n] = 255) 
1798
                    else
1799
                        Icounter_n(i)   <= Icounter_n(i) - '1';
1800
                        Vcounter_n(i)   <= (others => '0');
1801
                        -- (Icounter[n] > 0) 
1802
                        if Icounter_n(i) > Ione then
1803
                            -- do nothing
1804
                            lane_sync_state_n(i) <= SYNC_2;
1805
                        -- (Icounter[n] = 0) 
1806
                        else
1807
                            lane_sync_state_n(i) <= SYNC;
1808
                        end if;
1809
                    end if;
1810
                -- One of both /INVALID/  
1811
                elsif (code_group_valid(i*2) = '1' or code_group_valid(i*2+1) = '1') then
1812
                    Icounter_n(i)        <= Icounter_n(i) + '1';
1813
                    Vcounter_n(i)        <= (others => '0');
1814
                    -- (Icounter[n] = Imax) 
1815
                    if Icounter_n(i) = Imax then
1816
                        lane_sync_state_n(i) <= NO_SYNC;
1817
                        lane_sync_n(i)       <= '0';
1818
                        Kcounter_n(i)        <= (others => '0');
1819
                    -- (Icounter[n] < Imax) 
1820
                    else
1821
                        -- do nothing
1822
                        lane_sync_state_n(i) <= SYNC_2;
1823
                    end if;
1824
                -- Both /INVALID/        
1825
                else
1826
                    Icounter_n(i)        <= Icounter_n(i) + "10";
1827
                    Vcounter_n(i)        <= (others => '0');
1828
                    -- (Icounter[n] = Imax) 
1829
                    if Icounter_n(i) = Imax then
1830
                        lane_sync_state_n(i) <= NO_SYNC;
1831
                        lane_sync_n(i)       <= '0';
1832
                        Kcounter_n(i)        <= (others => '0');
1833
                    -- (Icounter[n] < Imax) 
1834
                    else
1835
                        -- do nothing
1836
                        lane_sync_state_n(i) <= SYNC_2;
1837
                    end if;
1838
                end if;
1839
                ----------------------------------------------
1840
 
1841
            -- when SYNC_2a =>                  
1842
            --     -- /INVALID/  
1843
            --     if (code_group_valid(i*2+1) = '0') then
1844
            --         Icounter_n(i)        <= Icounter_n(i) + '1';      
1845
            --         Vcounter_n(i)        <= (others => '0');                     
1846
            --         -- (Icounter[n] = Imax) 
1847
            --         if Icounter_n(i) = Imax then 
1848
            --             lane_sync_state_n(i) <= NO_SYNC;                           
1849
            --             lane_sync_n(i)       <= '0';      
1850
            --             Kcounter_n(i)        <= (others => '0');     
1851
            --         -- (Icounter[n] < Imax) 
1852
            --         else      
1853
            --             lane_sync_state_n(i) <= SYNC_2b;       
1854
            --         end if;                             
1855
            --     -- /VALID/    
1856
            --     else     
1857
            --         Vcounter_n(i)  <= Vcounter_n(i) + '1';  
1858
            --         -- (Vcounter[n] < 255) 
1859
            --         if Vcounter_n(i) < x"FF" then
1860
            --             lane_sync_state_n(i) <= SYNC_2b;  
1861
            --         -- (Vcounter[n] = 255) 
1862
            --         else
1863
            --             Icounter_n(i)   <= Icounter_n(i) - '1';
1864
            --             Vcounter_n(i)   <= (others => '0'); 
1865
            --             -- (Icounter[n] > 0) 
1866
            --             if Icounter_n(i) > Izero then
1867
            --                 lane_sync_state_n(i) <= SYNC_2b;  
1868
            --             -- (Icounter[n] = 0) 
1869
            --             else
1870
            --                 lane_sync_state_n(i) <= SYNCb;        
1871
            --             end if;  
1872
            --         end if;                                 
1873
            --     end if;
1874
            -- 
1875
            -- when SYNC_2b =>                 
1876
            --     -- /INVALID/  
1877
            --     if (code_group_valid(i*2+1) = '0') then
1878
            --         Icounter_n(i)        <= Icounter_n(i) + '1';      
1879
            --         Vcounter_n(i)        <= (others => '0');                     
1880
            --         -- (Icounter[n] = Imax) 
1881
            --         if Icounter_n(i) = Imax then 
1882
            --             lane_sync_state_n(i) <= NO_SYNC;                           
1883
            --             lane_sync_n(i)       <= '0';      
1884
            --             Kcounter_n(i)        <= (others => '0');     
1885
            --         -- (Icounter[n] < Imax) 
1886
            --         else      
1887
            --             lane_sync_state_n(i) <= SYNC_2a;       
1888
            --         end if;                             
1889
            --     -- /VALID/    
1890
            --     else     
1891
            --         Vcounter_n(i)  <= Vcounter_n(i) + '1';  
1892
            --         -- (Vcounter[n] < 255) 
1893
            --         if Vcounter_n(i) < x"FF" then
1894
            --             lane_sync_state_n(i) <= SYNC_2a;  
1895
            --         -- (Vcounter[n] = 255) 
1896
            --         else
1897
            --             Icounter_n(i)   <= Icounter_n(i) - '1';
1898
            --             Vcounter_n(i)   <= (others => '0'); 
1899
            --             -- (Icounter[n] > 0) 
1900
            --             if Icounter_n(i) > Izero then
1901
            --                 lane_sync_state_n(i) <= SYNC_2a;  
1902
            --             -- (Icounter[n] = 0) 
1903
            --             else
1904
            --                 lane_sync_state_n(i) <= SYNCa;        
1905
            --             end if;  
1906
            --         end if;                                 
1907
            --     end if; 
1908
 
1909
            -- when SYNC_3 => 
1910
 
1911
            -- when SYNC_4 =>  
1912
 
1913
            when others =>
1914
                lane_sync_state_n(i) <= NO_SYNC;
1915
                lane_sync_n(i)       <= '0';
1916
                Kcounter_n(i)        <= (others => '0');
1917
                Vcounter_n(i)        <= (others => '0');
1918
 
1919
        end case;
1920
    end if;
1921
end process;
1922
 
1923
end generate GEN_LANE_SYNC_FSM;
1924
----------------------------------------------------------------
1925
-- Figure 4-15. Lane_Alignment State Machine (for N lanes)
1926
 
1927
N_lane_sync           <= '1' when lane_sync_n = N_lanes_all_high else '0';
1928
lane_alignment_reset  <= N_lane_sync and rst_n;
1929
A_column_valid_upper  <= '1' when (RXCHARIS_A_upper = N_lanes_all_high) else '0';
1930
A_column_valid_lower  <= '1' when (RXCHARIS_A_lower = N_lanes_all_high) else '0';
1931
A_column_valid        <= A_column_valid_upper or A_column_valid_lower;
1932
align_error_upper     <= '1' when (RXCHARIS_A_upper /= N_lanes_all_low) and (RXCHARIS_A_upper /= N_lanes_all_high) else '0';
1933
align_error_lower     <= '1' when (RXCHARIS_A_lower /= N_lanes_all_low) and (RXCHARIS_A_lower /= N_lanes_all_high) else '0';
1934
align_error           <= align_error_upper or align_error_lower;
1935
GEN_CHAR_A_CHECKER: for i in 0 to N-1 generate
1936
RXCHARIS_A_upper(i)    <=  '1' when (code_group_valid(i*2+1) = '1') and (RXCHARISK(i*2+1) = '1') and (RXDATA(i*16+15 downto i*16+8) = A_align) else '0';
1937
RXCHARIS_A_lower(i)    <=  '1' when (code_group_valid(i*2) = '1'  ) and (RXCHARISK(i*2) = '1'  ) and (RXDATA(i*16+7 downto i*16   ) = A_align) else '0';
1938
end generate GEN_CHAR_A_CHECKER;
1939
 
1940
process(lane_alignment_reset, UCLK)
1941
    begin
1942
 
1943
    if lane_alignment_reset = '0'  then
1944
 
1945
        lane_alignment_state <= NOT_ALIGNED;
1946
        N_lanes_aligned      <= '0';
1947
        Acounter             <= (others => '0');
1948
        -- Mcounter             <= (others => '0');    
1949
 
1950
    elsif rising_edge(UCLK) then
1951
 
1952
    -- if lane_alignment_reset = '1'  then
1953
 
1954
        case lane_alignment_state is
1955
            when NOT_ALIGNED =>
1956
                -- N_lane_sync & ||A||
1957
                if N_lane_sync = '1' and A_column_valid = '1' then
1958
                    Acounter  <= Acounter + '1';
1959
                    lane_alignment_state <= NOT_ALIGNED_2;
1960
                end if;
1961
 
1962
            -- when NOT_ALIGNED_1 =>
1963
 
1964
            when NOT_ALIGNED_2 =>
1965
                -- align_error
1966
                if align_error = '1' then
1967
                    lane_alignment_state <= NOT_ALIGNED;
1968
                    N_lanes_aligned      <= '0';
1969
                    Acounter             <= (others => '0');
1970
                -- ||A||    
1971
                elsif A_column_valid = '1' then
1972
                    Acounter  <= Acounter + '1';
1973
                    -- Acounter = 4 
1974
                    if Acounter = "100" then
1975
                        lane_alignment_state <= ALIGNED;
1976
                    -- Acounter < 4
1977
                    else
1978
                        lane_alignment_state <= NOT_ALIGNED_2;
1979
                    end if;
1980
                -- !align_error & !||A||    
1981
                else
1982
                    -- Do nothing: Wait for the next column
1983
                end if;
1984
 
1985
            when ALIGNED =>
1986
                N_lanes_aligned      <= '1';
1987
                Mcounter             <= (others => '0');
1988
                -- align_error
1989
                if align_error = '1' then
1990
                    Acounter    <= (others => '0');
1991
                    Mcounter    <= Mcounter + '1';
1992
                    lane_alignment_state <= ALIGNED_2;
1993
                -- !(align_error)
1994
                else
1995
                    -- Do nothing extra: Wait for the next column
1996
                end if;
1997
 
1998
            -- when ALIGNED_1 =>
1999
 
2000
            when ALIGNED_2 =>
2001
                -- align_error
2002
                if align_error = '1' then
2003
                    Acounter             <= (others => '0');
2004
                    Mcounter             <= Mcounter + '1';
2005
                    -- Mcounter = Mmax
2006
                    if Mcounter = Mmax then
2007
                        lane_alignment_state <= NOT_ALIGNED;
2008
                        N_lanes_aligned      <= '0';
2009
                    -- Mcounter < Mmax
2010
                    else
2011
                        -- Do nothing extra: Wait for the next column                    
2012
                    end if;
2013
                -- ||A||    
2014
                elsif A_column_valid = '1' then
2015
                    Acounter  <= Acounter + '1';
2016
                    -- Acounter = 4 
2017
                    if Acounter = "100" then
2018
                        lane_alignment_state <= ALIGNED;
2019
                    -- Acounter < 4
2020
                    else
2021
                        -- Do nothing extra: Wait for the next column                          
2022
                    end if;
2023
                -- !align_error & !||A||    
2024
                else
2025
                    -- Do nothing: Wait for the next column
2026
                end if;
2027
 
2028
            -- when ALIGNED_3 =>
2029
 
2030
            when others =>
2031
                lane_alignment_state <= NOT_ALIGNED;
2032
                N_lanes_aligned      <= '0';
2033
                Acounter             <= (others => '0');
2034
                Mcounter             <= (others => '0');
2035
 
2036
        end case;
2037
    -- else
2038
    --     lane_alignment_state <= NOT_ALIGNED;
2039
    --     N_lanes_aligned      <= '0';      
2040
    --     Acounter             <= (others => '0'); 
2041
    -- end if;
2042
    end if;
2043
end process;
2044
 
2045
-- Figure 4-18. 1x/Nx_Initialization State Machine for N = 4
2046
TXINHIBIT_02        <= not(lanes02_drvr_oe);
2047
TXINHIBIT_others    <= not(N_lanes_drvr_oe);
2048
rcvr_trained_n      <= CHBONDDONE; -- TBD
2049
lane_ready_n        <= lane_sync_n and rcvr_trained_n;
2050
-- lane_ready_n        <= lane_sync_n; -- and rcvr_trained_n;
2051
N_lanes_ready       <= '1' when N_lanes_aligned = '1' and lane_ready_n = N_lanes_all_high else '0';
2052
 
2053
-- process(UCLK)
2054
--     begin    
2055
--     if rising_edge(UCLK) then  
2056
--         mode_sel         <= Nx_mode_active;
2057
--         mode_0_lane_sel  <= receive_lane2;
2058
--         port_initalized  <= port_initalized_reg;
2059
--     end if;
2060
-- end process;
2061
mode_sel         <= Nx_mode_active;
2062
mode_0_lane_sel  <= receive_lane2;
2063
port_initalized  <= port_initalized_reg;
2064
 
2065
process(rst_n, UCLK)
2066
    begin
2067
    if rst_n = '0'  then
2068
 
2069
        mode_init_state     <= SILENT;
2070
        disc_tmr_en         <= '0';
2071
        lanes02_drvr_oe     <= '0';
2072
        N_lanes_drvr_oe     <= '0';
2073
        port_initalized_reg <= '0';
2074
        Nx_mode_active      <= '0';
2075
        receive_lane2       <= '0';
2076
        force_reinit_clear  <= '0';
2077
        silence_timer_en    <= '0';
2078
        idle_selected       <= '1';
2079
 
2080
    elsif rising_edge(UCLK) then
2081
        case mode_init_state is
2082
 
2083
            when SILENT =>
2084
                disc_tmr_en         <= '0';
2085
                lanes02_drvr_oe     <= '0';
2086
                N_lanes_drvr_oe     <= '0';
2087
                port_initalized_reg <= '0';
2088
                Nx_mode_active      <= '0';
2089
                receive_lane2       <= '0';
2090
                force_reinit_clear  <= '1'; -- = force_reinit <= '0';
2091
                silence_timer_en    <= '1';
2092
                -- force_reinit
2093
                if force_reinit_reg = '1' then
2094
                    mode_init_state     <= SILENT;
2095
                -- silence_timer_done
2096
                elsif silence_timer_done = '1' then
2097
                    mode_init_state     <= SEEK;
2098
                end if;
2099
 
2100
            when SEEK =>
2101
                lanes02_drvr_oe     <= '1';
2102
                silence_timer_en    <= '0';
2103
                -- (lane_sync_0 | lane_sync_2) & idle_selected
2104
                if (lane_sync_n(0) = '1' or lane_sync_n(2) = '1') and idle_selected = '1' then
2105
                    mode_init_state     <= DISCOVERY;
2106
                end if;
2107
 
2108
            when DISCOVERY =>
2109
                port_initalized_reg <= '0';
2110
                Nx_mode_active      <= '0';
2111
                N_lanes_drvr_oe     <= Nx_mode_enabled;
2112
                disc_tmr_en         <= '1';
2113
                -- Nx_mode_enabled & N_lanes_ready
2114
                if Nx_mode_enabled = '1' and N_lanes_ready = '1' then
2115
 
2116
                    mode_init_state     <= Nx_MODE;
2117
 
2118
                -- lane_ready[0] & (force_1x_mode & (!force_laneR | force_laneR & disc_tmr_done & !lane_ready[2]) 
2119
                --               | !force_1x_mode & disc_tmr_done & !N_lanes_ready)
2120
                elsif lane_ready_n(0) = '1' and ((force_1x_mode = '1' and (force_laneR = '0' or (force_laneR = '1' and disc_tmr_done = '1' and lane_ready_n(2) = '0')))
2121
                                             or  (force_1x_mode = '0' and disc_tmr_done = '1' and N_lanes_ready = '0')) then
2122
 
2123
                    mode_init_state     <= x1_MODE_LANE0;
2124
 
2125
                -- lane_ready[2] & (force_1x_mode & force_laneR | disc_tmr_done & !lane_ready[0] 
2126
                --               & (force_1x_mode & !force_laneR | !force_1x_mode & !N_lanes_ready))
2127
                elsif lane_ready_n(2) = '1' and ((force_1x_mode = '1' and force_laneR = '1') or
2128
                                                 (disc_tmr_done = '1' and lane_ready_n(0) = '0' and
2129
                                                  ((force_1x_mode = '1' and force_laneR = '0') or (force_1x_mode = '0' and N_lanes_ready = '0')))) then
2130
 
2131
                    mode_init_state     <= x1_MODE_LANE2;
2132
 
2133
                ---- -- !lane_sync[0] & !lane_sync[2] | disc_tmr_done & !lane_ready[0] & !lane_ready[2]    
2134
                ---- elsif (lane_sync_n(0) = '0' and lane_sync_n(2) = '0') or (disc_tmr_done = '1' and lane_ready_n(0) = '0' and lane_ready_n(2) = '0')  then   
2135
                -- disc_tmr_done & !lane_ready[0] & !lane_ready[2]    
2136
                elsif (disc_tmr_done = '1' and lane_ready_n(0) = '0' and lane_ready_n(2) = '0')  then
2137
 
2138
                    mode_init_state     <= SILENT;
2139
 
2140
                end if;
2141
 
2142
            when Nx_MODE =>
2143
                disc_tmr_en         <= '0';
2144
                port_initalized_reg <= '1';
2145
                Nx_mode_active      <= '1';
2146
                -- !N_lanes_ready & (lane_sync[0] | lane_sync[2])                
2147
                if N_lanes_ready = '0' and (lane_sync_n(0) = '1' or lane_sync_n(2) = '1') then
2148
                    mode_init_state     <= DISCOVERY;
2149
                -- !N_lanes_ready & !lane_sync[0] & !lane_sync[2]
2150
                elsif N_lanes_ready = '0' and lane_sync_n(0) = '0' and lane_sync_n(2) = '0' then
2151
                    mode_init_state     <= SILENT;
2152
                end if;
2153
 
2154
            when x1_MODE_LANE0 =>
2155
                disc_tmr_en         <= '0';
2156
                N_lanes_drvr_oe     <= '0';
2157
                port_initalized_reg <= '1';
2158
                -- !lane_sync[0]               
2159
                if lane_sync_n(0) = '0' then
2160
                    mode_init_state     <= SILENT;
2161
                -- !lane_ready[0] & lane_sync[0]
2162
                elsif lane_ready_n(0) = '0' and lane_sync_n(0) = '1' then
2163
                    mode_init_state     <= x1_RECOVERY;
2164
                end if;
2165
 
2166
            when x1_MODE_LANE2 =>
2167
                disc_tmr_en         <= '0';
2168
                receive_lane2       <= '1';
2169
                N_lanes_drvr_oe     <= '0';
2170
                port_initalized_reg <= '1';
2171
                -- !lane_sync[2]               
2172
                if lane_sync_n(2) = '0' then
2173
                    mode_init_state     <= SILENT;
2174
                -- !lane_ready[2] & lane_sync[2]
2175
                elsif lane_ready_n(2) = '0' and lane_sync_n(2) = '1' then
2176
                    mode_init_state     <= x1_RECOVERY;
2177
                end if;
2178
 
2179
            when x1_RECOVERY =>
2180
                port_initalized_reg <= '0';
2181
                disc_tmr_en         <= '1';
2182
                -- !lane_sync[0] & !lane_sync[2] & disc_tmr_done   (!!!)
2183
                if lane_sync_n(0) = '0' and lane_sync_n(2) = '0' and disc_tmr_done = '1' then
2184
 
2185
                    mode_init_state     <= SILENT;
2186
 
2187
                -- lane_ready[0] & !receive_lane2 & !disc_tmr_done
2188
                elsif lane_sync_n(0) = '1' and receive_lane2 = '0' and disc_tmr_done = '0' then
2189
 
2190
                    mode_init_state     <= x1_MODE_LANE0;
2191
 
2192
                -- lane_ready[2] & receive_lane2 & !disc_tmr_done
2193
                elsif lane_sync_n(2) = '1' and receive_lane2 = '1' and disc_tmr_done = '0' then
2194
 
2195
                    mode_init_state     <= x1_MODE_LANE2;
2196
 
2197
                end if;
2198
 
2199
            when others =>
2200
                port_initalized_reg <= '0';
2201
                mode_init_state     <= SILENT;
2202
 
2203
        end case;
2204
 
2205
    end if;
2206
 
2207
end process;
2208
 
2209
-- Sticky force_reinit set-reset register
2210
process(rst_n, UCLK)
2211
    begin
2212
    if rst_n = '0'  then
2213
        force_reinit_reg       <= '0';
2214
    elsif rising_edge(UCLK) then
2215
        case force_reinit_reg is
2216
            when '0' =>
2217
                force_reinit_reg <= force_reinit or rxbuferr_reg;
2218
            when '1' =>
2219
                -- force_reinit_reg <= not(force_reinit_clear) and not(force_reinit);
2220
                force_reinit_reg <= not(force_reinit_clear and not(force_reinit) and not(rxbuferr_reg));
2221
            when others =>
2222
                force_reinit_reg <= '0';
2223
        end case;
2224
    end if;
2225
end process;
2226
 
2227
-- RXBUFRST handler
2228
process(rst_n, UCLK)
2229
    begin
2230
    if rst_n = '0'  then
2231
        rxbufrst_cntr    <= (others => '0');
2232
        rxbuferr_reg     <= '0';
2233
        RXBUFRST         <= '0';
2234
 
2235
    elsif rising_edge(UCLK) then
2236
        case rxbuferr_reg is
2237
            when '0' =>
2238
                rxbuferr_reg     <= RXBUFERR;
2239
                RXBUFRST         <= '0';
2240
            when '1' =>
2241
                if rxbufrst_cntr = "111" then
2242
                    rxbuferr_reg     <= '0';
2243
                    rxbufrst_cntr    <= (others => '0');
2244
                else
2245
                    RXBUFRST         <= '1';
2246
                    rxbufrst_cntr    <= rxbufrst_cntr + '1';
2247
                end if;
2248
            when others =>
2249
                rxbuferr_reg     <= '0';
2250
        end case;
2251
    end if;
2252
end process;
2253
 
2254
 
2255
-- Silence Timer Process
2256
-- silence_timer_done: Asserted when silence_timer_en has been continuously asserted
2257
-- for 120 +/- 40 µs and the state machine is in the SILENT state. The assertion of
2258
-- silence_timer_done causes silence_timer_en to be de-asserted. When the state
2259
-- machine is not in the SILENT state, silence_timer_done is de-asserted.
2260
process(rst_n, UCLK_DV_1024)
2261
    begin
2262
    if rst_n = '0'  then
2263
        silence_timer_done  <= '0';
2264
        silence_timer       <= (others => '0');
2265
    elsif rising_edge(UCLK_DV_1024) then
2266
 
2267
        case silence_timer_en is
2268
            when '0' =>
2269
                silence_timer       <= (others => '0');
2270
                silence_timer_done  <= '0';
2271
            when '1' =>
2272
                if silence_timer = SILENT_ENOUGH then
2273
                    if mode_init_state = SILENT then
2274
                        silence_timer_done  <= '1';
2275
                    else
2276
                        silence_timer_done  <= '0';
2277
                    end if;
2278
                else
2279
                    silence_timer   <= silence_timer + '1';
2280
                end if;
2281
            when others =>
2282
                silence_timer   <= (others => '0');
2283
        end case;
2284
    end if;
2285
end process;
2286
 
2287
-- Discovery Timer Process
2288
-- disc_tmr_done: Asserted when disc_tmr_en has been continuously asserted for 28 +/- 4 ms
2289
-- and the state machine is in the DISCOVERY or a RECOVERY state. The assertion of 
2290
-- disc_tmr_done causes disc_tmr_en to be de-asserted. When the state machine is in
2291
-- a state other than the DISCOVERY or a RECOVERY state, disc_tmr_done is de-asserted.
2292
process(rst_n, UCLK_DV_1024)
2293
    begin
2294
    if rst_n = '0'  then
2295
        disc_tmr_done  <= '0';
2296
        disc_tmr       <= (others => '0');
2297
    elsif rising_edge(UCLK_DV_1024) then
2298
 
2299
        case disc_tmr_en is
2300
            when '0' =>
2301
                disc_tmr       <= (others => '0');
2302
                disc_tmr_done  <= '0';
2303
            when '1' =>
2304
                if disc_tmr = DISCOVERY_ENDS then
2305
                    if mode_init_state = DISCOVERY or mode_init_state = x1_RECOVERY then
2306
                        disc_tmr_done  <= '1';
2307
                    else
2308
                        disc_tmr_done  <= '0';
2309
                    end if;
2310
                else
2311
                    disc_tmr   <= disc_tmr + '1';
2312
                end if;
2313
            when others =>
2314
                disc_tmr   <= (others => '0');
2315
        end case;
2316
    end if;
2317
end process;
2318
 
2319
ENCHANSYNC <= '0';
2320
 
2321
end rtl;
2322
-------------------------------------------------------------------------------
2323
-- 
2324
-- RapidIO IP Library Core
2325
-- 
2326
-- This file is part of the RapidIO IP library project
2327
-- http://www.opencores.org/cores/rio/
2328
-- 
2329
-- To Do:
2330
-- -
2331
-- 
2332
-- Author(s): 
2333
-- - A. Demirezen, azdem@opencores.org 
2334
-- 
2335
-------------------------------------------------------------------------------
2336
-- 
2337
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
2338
-- 
2339
-- This source file may be used and distributed without 
2340
-- restriction provided that this copyright statement is not 
2341
-- removed from the file and that any derivative work contains 
2342
-- the original copyright notice and the associated disclaimer. 
2343
-- 
2344
-- This source file is free software; you can redistribute it 
2345
-- and/or modify it under the terms of the GNU Lesser General 
2346
-- Public License as published by the Free Software Foundation; 
2347
-- either version 2.1 of the License, or (at your option) any 
2348
-- later version. 
2349
-- 
2350
-- This source is distributed in the hope that it will be 
2351
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
2352
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
2353
-- PURPOSE. See the GNU Lesser General Public License for more 
2354
-- details. 
2355
-- 
2356
-- You should have received a copy of the GNU Lesser General 
2357
-- Public License along with this source; if not, download it 
2358
-- from http://www.opencores.org/lgpl.shtml 
2359
-- 
2360
------------------------------------------------------------------------------
2361
----------------------------------------------------------------------------------
2362
library IEEE;
2363
use IEEE.STD_LOGIC_1164.ALL;
2364
use IEEE.NUMERIC_STD.ALL;
2365
 
2366
entity pseudo_random_number_generator is
2367
    Generic (
2368
            lfsr_init   : std_logic_vector(7 downto 0) := x"01"
2369
           );
2370
    Port    (
2371
            clk      : in  STD_LOGIC;
2372
            rst_n    : in  STD_LOGIC;
2373
            -- Pseudo random number
2374
            q        : out STD_LOGIC_VECTOR(7 downto 0)
2375
           );
2376
end pseudo_random_number_generator;
2377
 
2378
architecture Behavioral of pseudo_random_number_generator is
2379
 
2380
signal lfsr   : std_logic_vector(7 downto 0) := x"01";
2381
signal q0     : std_logic;
2382
 
2383
 begin
2384
 
2385
q  <= lfsr;
2386
 
2387
-- Polynomial: x^7 + x^6 + 1
2388
q0 <= lfsr(7) xnor lfsr(6) xnor lfsr(0) ;
2389
 
2390
process (clk, rst_n) begin
2391
 
2392
  if rst_n = '0' then
2393
 
2394
    lfsr <= lfsr_init; -- x"01"; --(others => '0');
2395
 
2396
  elsif rising_edge(clk) then
2397
 
2398
    lfsr <= lfsr(6 downto 0) & q0;
2399
 
2400
  end if;
2401
 
2402
end process;
2403
 
2404
end Behavioral;
2405
 
2406
-------------------------------------------------------------------------------
2407
-- 
2408
-- RapidIO IP Library Core
2409
-- 
2410
-- This file is part of the RapidIO IP library project
2411
-- http://www.opencores.org/cores/rio/
2412
-- 
2413
-- To Do:
2414
-- -
2415
-- 
2416
-- Author(s): 
2417
-- - A. Demirezen, azdem@opencores.org 
2418
-- 
2419
-------------------------------------------------------------------------------
2420
-- 
2421
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
2422
-- 
2423
-- This source file may be used and distributed without 
2424
-- restriction provided that this copyright statement is not 
2425
-- removed from the file and that any derivative work contains 
2426
-- the original copyright notice and the associated disclaimer. 
2427
-- 
2428
-- This source file is free software; you can redistribute it 
2429
-- and/or modify it under the terms of the GNU Lesser General 
2430
-- Public License as published by the Free Software Foundation; 
2431
-- either version 2.1 of the License, or (at your option) any 
2432
-- later version. 
2433
-- 
2434
-- This source is distributed in the hope that it will be 
2435
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
2436
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
2437
-- PURPOSE. See the GNU Lesser General Public License for more 
2438
-- details. 
2439
-- 
2440
-- You should have received a copy of the GNU Lesser General 
2441
-- Public License along with this source; if not, download it 
2442
-- from http://www.opencores.org/lgpl.shtml 
2443
-- 
2444
------------------------------------------------------------------------------
2445
------------------------------------------------------------------------------
2446
--
2447
-- File name:    serdes_wrapper_v0.vhd
2448
-- Rev:          0.0
2449
-- Description:  This entity instantiates 4-Lane SerDes (GTX-Quad) of Virtex-6
2450
-- 
2451
------------------------------------------------------------------------------
2452
------------------------------------------------------------------------------
2453
 
2454
library ieee;
2455
use ieee.std_logic_1164.all;
2456
use ieee.numeric_std.all;
2457
use work.rio_common.all;
2458
 
2459
entity serdes_wrapper_v0 is
2460
  port (
2461
         REFCLK              : in std_logic;
2462
         RXUSRCLK            : in std_logic;
2463
         RXUSRCLK2           : in std_logic;
2464
         TXUSRCLK            : in std_logic;
2465
         TXUSRCLK2           : in std_logic;
2466
         GTXRESET            : in std_logic;
2467
         RXBUFRST            : in std_logic;
2468
 
2469
         -- RXN                 : in  std_logic_vector(N-1 downto 0);
2470
         -- RXP                 : in  std_logic_vector(N-1 downto 0);
2471
         RXN                 : in  std_logic_vector(0 to N-1);
2472
         RXP                 : in  std_logic_vector(0 to N-1);
2473
         TXINHIBIT_02        : in  std_logic;
2474
         TXINHIBIT_others    : in  std_logic;
2475
         ENCHANSYNC          : in  std_logic;
2476
         TXDATA              : in  std_logic_vector(N*16-1 downto 0);
2477
         TXCHARISK           : in  std_logic_vector(N*2-1 downto 0);
2478
         -- TXN                 : out std_logic_vector(N-1 downto 0);
2479
         -- TXP                 : out std_logic_vector(N-1 downto 0);
2480
         TXN                 : out std_logic_vector(0 to N-1);
2481
         TXP                 : out std_logic_vector(0 to N-1);
2482
         PLLLKDET            : out std_logic;
2483
         RXDATA              : out std_logic_vector(N*16-1 downto 0);
2484
         RXCHARISK           : out std_logic_vector(N*2-1 downto 0);
2485
         RXCHARISCOMMA       : out std_logic_vector(N*2-1 downto 0);
2486
         RXBYTEISALIGNED     : out std_logic_vector(N-1 downto 0);
2487
         RXBYTEREALIGN       : out std_logic_vector(N-1 downto 0);
2488
         RXELECIDLE          : out std_logic_vector(N-1 downto 0);
2489
         RXDISPERR           : out std_logic_vector(N*2-1 downto 0);
2490
         RXNOTINTABLE        : out std_logic_vector(N*2-1 downto 0);
2491
         RXBUFERR            : out std_logic;
2492
         CHBONDDONE          : out std_logic_vector(N-1 downto 0)
2493
  );
2494
end serdes_wrapper_v0;
2495
 
2496
architecture struct of serdes_wrapper_v0 is
2497
 
2498
        COMPONENT srio_gt_wrapper_v6_4x
2499
        PORT(
2500
                REFCLK : IN std_logic;
2501
                RXUSRCLK : IN std_logic;
2502
                RXUSRCLK2 : IN std_logic;
2503
                TXUSRCLK : IN std_logic;
2504
                TXUSRCLK2 : IN std_logic;
2505
                GTXRESET : IN std_logic;
2506
                RXBUFRST : IN std_logic;
2507
                RXN0 : IN std_logic;
2508
                RXN1 : IN std_logic;
2509
                RXN2 : IN std_logic;
2510
                RXN3 : IN std_logic;
2511
                RXP0 : IN std_logic;
2512
                RXP1 : IN std_logic;
2513
                RXP2 : IN std_logic;
2514
                RXP3 : IN std_logic;
2515
                TXINHIBIT_02 : IN std_logic;
2516
                TXINHIBIT_13 : IN std_logic;
2517
                ENCHANSYNC : IN std_logic;
2518
                TXDATA0 : IN std_logic_vector(15 downto 0);
2519
                TXDATA1 : IN std_logic_vector(15 downto 0);
2520
                TXDATA2 : IN std_logic_vector(15 downto 0);
2521
                TXDATA3 : IN std_logic_vector(15 downto 0);
2522
                TXCHARISK0 : IN std_logic_vector(1 downto 0);
2523
                TXCHARISK1 : IN std_logic_vector(1 downto 0);
2524
                TXCHARISK2 : IN std_logic_vector(1 downto 0);
2525
                TXCHARISK3 : IN std_logic_vector(1 downto 0);
2526
                TXN0 : OUT std_logic;
2527
                TXN1 : OUT std_logic;
2528
                TXN2 : OUT std_logic;
2529
                TXN3 : OUT std_logic;
2530
                TXP0 : OUT std_logic;
2531
                TXP1 : OUT std_logic;
2532
                TXP2 : OUT std_logic;
2533
                TXP3 : OUT std_logic;
2534
                PLLLKDET : OUT std_logic;
2535
                RXDATA0 : OUT std_logic_vector(15 downto 0);
2536
                RXDATA1 : OUT std_logic_vector(15 downto 0);
2537
                RXDATA2 : OUT std_logic_vector(15 downto 0);
2538
                RXDATA3 : OUT std_logic_vector(15 downto 0);
2539
                RXCHARISK0 : OUT std_logic_vector(1 downto 0);
2540
                RXCHARISK1 : OUT std_logic_vector(1 downto 0);
2541
                RXCHARISK2 : OUT std_logic_vector(1 downto 0);
2542
                RXCHARISK3 : OUT std_logic_vector(1 downto 0);
2543
                RXCHARISCOMMA0 : OUT std_logic_vector(1 downto 0);
2544
                RXCHARISCOMMA1 : OUT std_logic_vector(1 downto 0);
2545
                RXCHARISCOMMA2 : OUT std_logic_vector(1 downto 0);
2546
                RXCHARISCOMMA3 : OUT std_logic_vector(1 downto 0);
2547
        RXBYTEISALIGNED: OUT  std_logic_vector(3 downto 0);
2548
        RXBYTEREALIGN  : OUT  std_logic_vector(3 downto 0);
2549
        RXELECIDLE     : OUT std_logic_vector(3 downto 0);
2550
                RXDISPERR0 : OUT std_logic_vector(1 downto 0);
2551
                RXDISPERR1 : OUT std_logic_vector(1 downto 0);
2552
                RXDISPERR2 : OUT std_logic_vector(1 downto 0);
2553
                RXDISPERR3 : OUT std_logic_vector(1 downto 0);
2554
                RXNOTINTABLE0 : OUT std_logic_vector(1 downto 0);
2555
                RXNOTINTABLE1 : OUT std_logic_vector(1 downto 0);
2556
                RXNOTINTABLE2 : OUT std_logic_vector(1 downto 0);
2557
                RXNOTINTABLE3 : OUT std_logic_vector(1 downto 0);
2558
                RXBUFERR : OUT std_logic;
2559
                CHBONDDONE0 : OUT std_logic;
2560
                CHBONDDONE1 : OUT std_logic;
2561
                CHBONDDONE2 : OUT std_logic;
2562
                CHBONDDONE3 : OUT std_logic
2563
                );
2564
        END COMPONENT;
2565
 
2566
begin
2567
 
2568
        Inst_srio_gt_wrapper_v6_4x: srio_gt_wrapper_v6_4x PORT MAP(
2569
                REFCLK              => REFCLK                       ,
2570
                RXUSRCLK            => RXUSRCLK                     ,
2571
                RXUSRCLK2           => RXUSRCLK2                    ,
2572
                TXUSRCLK            => TXUSRCLK                     ,
2573
                TXUSRCLK2           => TXUSRCLK2                    ,
2574
                GTXRESET            => GTXRESET                     ,
2575
                RXBUFRST            => RXBUFRST                     ,
2576
                RXN0                => RXN(0)                       ,
2577
                RXN1                => RXN(1)                       ,
2578
                RXN2                => RXN(2)                       ,
2579
                RXN3                => RXN(3)                       ,
2580
                RXP0                => RXP(0)                       ,
2581
                RXP1                => RXP(1)                       ,
2582
                RXP2                => RXP(2)                       ,
2583
                RXP3                => RXP(3)                       ,
2584
                TXINHIBIT_02        => TXINHIBIT_02                 ,
2585
                TXINHIBIT_13        => TXINHIBIT_others             ,
2586
                ENCHANSYNC          => ENCHANSYNC                   ,
2587
                TXDATA0             => TXDATA(15 downto 0)          ,
2588
                TXDATA1             => TXDATA(31 downto 16)         ,
2589
                TXDATA2             => TXDATA(47 downto 32)         ,
2590
                TXDATA3             => TXDATA(63 downto 48)         ,
2591
                TXCHARISK0          => TXCHARISK(1 downto 0)        ,
2592
                TXCHARISK1          => TXCHARISK(3 downto 2)        ,
2593
                TXCHARISK2          => TXCHARISK(5 downto 4)        ,
2594
                TXCHARISK3          => TXCHARISK(7 downto 6)        ,
2595
                TXN0                => TXN(0)                       ,
2596
                TXN1                => TXN(1)                       ,
2597
                TXN2                => TXN(2)                       ,
2598
                TXN3                => TXN(3)                       ,
2599
                TXP0                => TXP(0)                       ,
2600
                TXP1                => TXP(1)                       ,
2601
                TXP2                => TXP(2)                       ,
2602
                TXP3                => TXP(3)                       ,
2603
                PLLLKDET            => PLLLKDET                     ,
2604
                RXDATA0             => RXDATA(15 downto 0)          ,
2605
                RXDATA1             => RXDATA(31 downto 16)         ,
2606
                RXDATA2             => RXDATA(47 downto 32)         ,
2607
                RXDATA3             => RXDATA(63 downto 48)         ,
2608
                RXCHARISK0          => RXCHARISK(1 downto 0)        ,
2609
                RXCHARISK1          => RXCHARISK(3 downto 2)        ,
2610
                RXCHARISK2          => RXCHARISK(5 downto 4)        ,
2611
                RXCHARISK3          => RXCHARISK(7 downto 6)        ,
2612
                RXCHARISCOMMA0      => RXCHARISCOMMA(1 downto 0)    ,
2613
                RXCHARISCOMMA1      => RXCHARISCOMMA(3 downto 2)    ,
2614
                RXCHARISCOMMA2      => RXCHARISCOMMA(5 downto 4)    ,
2615
                RXCHARISCOMMA3      => RXCHARISCOMMA(7 downto 6)    ,
2616
        RXBYTEISALIGNED     => RXBYTEISALIGNED              ,
2617
        RXBYTEREALIGN       => RXBYTEREALIGN                ,
2618
        RXELECIDLE          => RXELECIDLE                   ,
2619
                RXDISPERR0          => RXDISPERR(1 downto 0)        ,
2620
                RXDISPERR1          => RXDISPERR(3 downto 2)        ,
2621
                RXDISPERR2          => RXDISPERR(5 downto 4)        ,
2622
                RXDISPERR3          => RXDISPERR(7 downto 6)        ,
2623
                RXNOTINTABLE0       => RXNOTINTABLE(1 downto 0)     ,
2624
                RXNOTINTABLE1       => RXNOTINTABLE(3 downto 2)     ,
2625
                RXNOTINTABLE2       => RXNOTINTABLE(5 downto 4)     ,
2626
                RXNOTINTABLE3       => RXNOTINTABLE(7 downto 6)     ,
2627
                RXBUFERR            => RXBUFERR                     ,
2628
                CHBONDDONE0         => CHBONDDONE(0)                ,
2629
                CHBONDDONE1         => CHBONDDONE(1)                ,
2630
                CHBONDDONE2         => CHBONDDONE(2)                ,
2631
                CHBONDDONE3         => CHBONDDONE(3)
2632
        );
2633
 
2634
end struct;
2635
-------------------------------------------------------------------------------
2636
-- 
2637
-- RapidIO IP Library Core
2638
-- 
2639
-- This file is part of the RapidIO IP library project
2640
-- http://www.opencores.org/cores/rio/
2641
-- 
2642
-- To Do:
2643
-- -
2644
-- 
2645
-- Author(s): 
2646
-- - A. Demirezen, azdem@opencores.org 
2647
-- 
2648
-------------------------------------------------------------------------------
2649
-- 
2650
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
2651
-- 
2652
-- This source file may be used and distributed without 
2653
-- restriction provided that this copyright statement is not 
2654
-- removed from the file and that any derivative work contains 
2655
-- the original copyright notice and the associated disclaimer. 
2656
-- 
2657
-- This source file is free software; you can redistribute it 
2658
-- and/or modify it under the terms of the GNU Lesser General 
2659
-- Public License as published by the Free Software Foundation; 
2660
-- either version 2.1 of the License, or (at your option) any 
2661
-- later version. 
2662
-- 
2663
-- This source is distributed in the hope that it will be 
2664
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
2665
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
2666
-- PURPOSE. See the GNU Lesser General Public License for more 
2667
-- details. 
2668
-- 
2669
-- You should have received a copy of the GNU Lesser General 
2670
-- Public License along with this source; if not, download it 
2671
-- from http://www.opencores.org/lgpl.shtml 
2672
-- 
2673
------------------------------------------------------------------------------
2674
 
2675
library ieee;
2676
use ieee.std_logic_1164.ALL;
2677
use ieee.numeric_std.ALL;
2678
library UNISIM;
2679
use UNISIM.Vcomponents.ALL;
2680
 
2681
entity srio_pcs_struct is
2682
   port ( CHBONDDONE         : in    std_logic_vector (3 downto 0);
2683
          force_reinit_i     : in    std_logic;
2684
          inboundRead_i      : in    std_logic;
2685
          outboundSymbol_i   : in    std_logic_vector (33 downto 0);
2686
          outboundWrite_i    : in    std_logic;
2687
          PLLLKDET           : in    std_logic;
2688
          rio_clk            : in    std_logic;
2689
          rst_n              : in    std_logic;
2690
          RXBUFERR           : in    std_logic;
2691
          RXBYTEISALIGNED    : in    std_logic_vector (3 downto 0);
2692
          RXBYTEREALIGN      : in    std_logic_vector (3 downto 0);
2693
          RXCAHRISCOMMA      : in    std_logic_vector (7 downto 0);
2694
          RXCAHRISK          : in    std_logic_vector (7 downto 0);
2695
          RXDATA             : in    std_logic_vector (63 downto 0);
2696
          RXDISPERR          : in    std_logic_vector (7 downto 0);
2697
          RXELECIDLE         : in    std_logic_vector (3 downto 0);
2698
          RXNOTINTABLE       : in    std_logic_vector (7 downto 0);
2699
          UCLK               : in    std_logic;
2700
          UCLK_DV4           : in    std_logic;
2701
          UCLK_DV1024        : in    std_logic;
2702
          UCLK_or_DV4        : in    std_logic;
2703
          UCLK_x2            : in    std_logic;
2704
          UCLK_x2_DV2        : in    std_logic;
2705
          ENCHANSYNC         : out   std_logic;
2706
          inboundEmpty_o     : out   std_logic;
2707
          inboundSymbol_o    : out   std_logic_vector (33 downto 0);
2708
          lane_sync_o        : out   std_logic_vector (3 downto 0);
2709
          mode_sel_o         : out   std_logic;
2710
          mode_0_lane_sel_o  : out   std_logic;
2711
          outboundFull_o     : out   std_logic;
2712
          port_initialized_o : out   std_logic;
2713
          RXBUFRST           : out   std_logic;
2714
          TXCAHRISK          : out   std_logic_vector (7 downto 0);
2715
          TXDATA             : out   std_logic_vector (63 downto 0);
2716
          TXINHIBIT_others   : out   std_logic;
2717
          TXINHIBIT_02       : out   std_logic);
2718
end srio_pcs_struct;
2719
 
2720
architecture BEHAVIORAL of srio_pcs_struct is
2721
   signal ccs_timer_rst            : std_logic;
2722
   signal RXCAHRISvalid            : std_logic_vector (7 downto 0);
2723
   signal send_A                   : std_logic_vector (1 downto 0);
2724
   signal send_ccs                 : std_logic;
2725
   signal send_idle                : std_logic_vector (1 downto 0);
2726
   signal send_K                   : std_logic_vector (1 downto 0);
2727
   signal send_R                   : std_logic_vector (1 downto 0);
2728
   signal mode_0_lane_sel_o_DUMMY  : std_logic;
2729
   signal TXINHIBIT_02_DUMMY       : std_logic;
2730
   signal mode_sel_o_DUMMY         : std_logic;
2731
   signal port_initialized_o_DUMMY : std_logic;
2732
   signal TXINHIBIT_others_DUMMY   : std_logic;
2733
   component ccs_timer
2734
      port ( rst_n         : in    std_logic;
2735
             ccs_timer_rst : in    std_logic;
2736
             send_ccs      : out   std_logic;
2737
             UCLK          : in    std_logic);
2738
   end component;
2739
 
2740
   component idle_generator_dual
2741
      port ( UCLK      : in    std_logic;
2742
             rst_n     : in    std_logic;
2743
             send_K    : out   std_logic_vector (1 downto 0);
2744
             send_A    : out   std_logic_vector (1 downto 0);
2745
             send_R    : out   std_logic_vector (1 downto 0);
2746
             send_idle : in    std_logic_vector (1 downto 0));
2747
   end component;
2748
 
2749
   component port_init_fsms
2750
      port ( rst_n            : in    std_logic;
2751
             UCLK_x2          : in    std_logic;
2752
             UCLK             : in    std_logic;
2753
             UCLK_DV4         : in    std_logic;
2754
             UCLK_DV_1024     : in    std_logic;
2755
             force_reinit     : in    std_logic;
2756
             PLLLKDET         : in    std_logic;
2757
             RXBUFERR         : in    std_logic;
2758
             RXDATA           : in    std_logic_vector (63 downto 0);
2759
             RXCHARISK        : in    std_logic_vector (7 downto 0);
2760
             RXCHARISCOMMA    : in    std_logic_vector (7 downto 0);
2761
             RXBYTEISALIGNED  : in    std_logic_vector (3 downto 0);
2762
             RXBYTEREALIGN    : in    std_logic_vector (3 downto 0);
2763
             RXELECIDLE       : in    std_logic_vector (3 downto 0);
2764
             RXDISPERR        : in    std_logic_vector (7 downto 0);
2765
             RXNOTINTABLE     : in    std_logic_vector (7 downto 0);
2766
             CHBONDDONE       : in    std_logic_vector (3 downto 0);
2767
             mode_sel         : out   std_logic;
2768
             port_initalized  : out   std_logic;
2769
             TXINHIBIT_02     : out   std_logic;
2770
             TXINHIBIT_others : out   std_logic;
2771
             ENCHANSYNC       : out   std_logic;
2772
             RXBUFRST         : out   std_logic;
2773
             lane_sync        : out   std_logic_vector (3 downto 0);
2774
             mode_0_lane_sel  : out   std_logic;
2775
             RXCHARISvalid    : out   std_logic_vector (7 downto 0));
2776
   end component;
2777
 
2778
   component pcs_rx_controller
2779
      port ( rst_n             : in    std_logic;
2780
             rio_clk           : in    std_logic;
2781
             UCLK_x2           : in    std_logic;
2782
             UCLK              : in    std_logic;
2783
             UCLK_x2_DV2       : in    std_logic;
2784
             inboundRead_i     : in    std_logic;
2785
             port_initalized_i : in    std_logic;
2786
             mode_sel_i        : in    std_logic;
2787
             mode_0_lane_sel_i : in    std_logic;
2788
             RXDATA_i          : in    std_logic_vector (63 downto 0);
2789
             RXCHARISK_i       : in    std_logic_vector (7 downto 0);
2790
             RXCHARISvalid_i   : in    std_logic_vector (7 downto 0);
2791
             inboundEmpty_o    : out   std_logic;
2792
             inboundSymbol_o   : out   std_logic_vector (33 downto 0);
2793
             UCLK_or_DV4       : in    std_logic);
2794
   end component;
2795
 
2796
   component pcs_tx_controller
2797
      port ( rst_n             : in    std_logic;
2798
             rio_clk           : in    std_logic;
2799
             UCLK_x2           : in    std_logic;
2800
             UCLK              : in    std_logic;
2801
             UCLK_x2_DV2       : in    std_logic;
2802
             UCLK_or_DV4       : in    std_logic;
2803
             outboundWrite_i   : in    std_logic;
2804
             send_ccs_i        : in    std_logic;
2805
             TXINHIBIT_02      : in    std_logic;
2806
             TXINHIBIT_others  : in    std_logic;
2807
             port_initalized_i : in    std_logic;
2808
             mode_sel_i        : in    std_logic;
2809
             mode_0_lane_sel_i : in    std_logic;
2810
             outboundSymbol_i  : in    std_logic_vector (33 downto 0);
2811
             send_K_i          : in    std_logic_vector (1 downto 0);
2812
             send_A_i          : in    std_logic_vector (1 downto 0);
2813
             send_R_i          : in    std_logic_vector (1 downto 0);
2814
             outboundFull_o    : out   std_logic;
2815
             ccs_timer_rst_o   : out   std_logic;
2816
             TXDATA_o          : out   std_logic_vector (63 downto 0);
2817
             TXCHARISK_o       : out   std_logic_vector (7 downto 0);
2818
             send_idle_o       : out   std_logic_vector (1 downto 0));
2819
   end component;
2820
 
2821
begin
2822
   mode_sel_o <= mode_sel_o_DUMMY;
2823
   mode_0_lane_sel_o <= mode_0_lane_sel_o_DUMMY;
2824
   port_initialized_o <= port_initialized_o_DUMMY;
2825
   TXINHIBIT_others <= TXINHIBIT_others_DUMMY;
2826
   TXINHIBIT_02 <= TXINHIBIT_02_DUMMY;
2827
   ccs_timer_inst : ccs_timer
2828
      port map (ccs_timer_rst=>ccs_timer_rst,
2829
                rst_n=>rst_n,
2830
                UCLK=>UCLK,
2831
                send_ccs=>send_ccs);
2832
 
2833
   dual_idle_generator : idle_generator_dual
2834
      port map (rst_n=>rst_n,
2835
                send_idle(1 downto 0)=>send_idle(1 downto 0),
2836
                UCLK=>UCLK,
2837
                send_A(1 downto 0)=>send_A(1 downto 0),
2838
                send_K(1 downto 0)=>send_K(1 downto 0),
2839
                send_R(1 downto 0)=>send_R(1 downto 0));
2840
 
2841
   port_init_fsms_inst : port_init_fsms
2842
      port map (CHBONDDONE(3 downto 0)=>CHBONDDONE(3 downto 0),
2843
                force_reinit=>force_reinit_i,
2844
                PLLLKDET=>PLLLKDET,
2845
                rst_n=>rst_n,
2846
                RXBUFERR=>RXBUFERR,
2847
                RXBYTEISALIGNED(3 downto 0)=>RXBYTEISALIGNED(3 downto 0),
2848
                RXBYTEREALIGN(3 downto 0)=>RXBYTEREALIGN(3 downto 0),
2849
                RXCHARISCOMMA(7 downto 0)=>RXCAHRISCOMMA(7 downto 0),
2850
                RXCHARISK(7 downto 0)=>RXCAHRISK(7 downto 0),
2851
                RXDATA(63 downto 0)=>RXDATA(63 downto 0),
2852
                RXDISPERR(7 downto 0)=>RXDISPERR(7 downto 0),
2853
                RXELECIDLE(3 downto 0)=>RXELECIDLE(3 downto 0),
2854
                RXNOTINTABLE(7 downto 0)=>RXNOTINTABLE(7 downto 0),
2855
                UCLK=>UCLK,
2856
                UCLK_DV_1024=>UCLK_DV1024,
2857
                UCLK_DV4=>UCLK_DV4,
2858
                UCLK_x2=>UCLK_x2,
2859
                ENCHANSYNC=>ENCHANSYNC,
2860
                lane_sync(3 downto 0)=>lane_sync_o(3 downto 0),
2861
                mode_sel=>mode_sel_o_DUMMY,
2862
                mode_0_lane_sel=>mode_0_lane_sel_o_DUMMY,
2863
                port_initalized=>port_initialized_o_DUMMY,
2864
                RXBUFRST=>RXBUFRST,
2865
                RXCHARISvalid(7 downto 0)=>RXCAHRISvalid(7 downto 0),
2866
                TXINHIBIT_others=>TXINHIBIT_others_DUMMY,
2867
                TXINHIBIT_02=>TXINHIBIT_02_DUMMY);
2868
 
2869
   rx_controller_inst : pcs_rx_controller
2870
      port map (inboundRead_i=>inboundRead_i,
2871
                mode_sel_i=>mode_sel_o_DUMMY,
2872
                mode_0_lane_sel_i=>mode_0_lane_sel_o_DUMMY,
2873
                port_initalized_i=>port_initialized_o_DUMMY,
2874
                rio_clk=>rio_clk,
2875
                rst_n=>rst_n,
2876
                RXCHARISK_i(7 downto 0)=>RXCAHRISK(7 downto 0),
2877
                RXCHARISvalid_i(7 downto 0)=>RXCAHRISvalid(7 downto 0),
2878
                RXDATA_i(63 downto 0)=>RXDATA(63 downto 0),
2879
                UCLK=>UCLK,
2880
                UCLK_or_DV4=>UCLK_or_DV4,
2881
                UCLK_x2=>UCLK_x2,
2882
                UCLK_x2_DV2=>UCLK_x2_DV2,
2883
                inboundEmpty_o=>inboundEmpty_o,
2884
                inboundSymbol_o(33 downto 0)=>inboundSymbol_o(33 downto 0));
2885
 
2886
   tx_controller_inst : pcs_tx_controller
2887
      port map (mode_sel_i=>mode_sel_o_DUMMY,
2888
                mode_0_lane_sel_i=>mode_0_lane_sel_o_DUMMY,
2889
                outboundSymbol_i(33 downto 0)=>outboundSymbol_i(33 downto 0),
2890
                outboundWrite_i=>outboundWrite_i,
2891
                port_initalized_i=>port_initialized_o_DUMMY,
2892
                rio_clk=>rio_clk,
2893
                rst_n=>rst_n,
2894
                send_A_i(1 downto 0)=>send_A(1 downto 0),
2895
                send_ccs_i=>send_ccs,
2896
                send_K_i(1 downto 0)=>send_K(1 downto 0),
2897
                send_R_i(1 downto 0)=>send_R(1 downto 0),
2898
                TXINHIBIT_others=>TXINHIBIT_others_DUMMY,
2899
                TXINHIBIT_02=>TXINHIBIT_02_DUMMY,
2900
                UCLK=>UCLK,
2901
                UCLK_or_DV4=>UCLK_or_DV4,
2902
                UCLK_x2=>UCLK_x2,
2903
                UCLK_x2_DV2=>UCLK_x2_DV2,
2904
                ccs_timer_rst_o=>ccs_timer_rst,
2905
                outboundFull_o=>outboundFull_o,
2906
                send_idle_o(1 downto 0)=>send_idle(1 downto 0),
2907
                TXCHARISK_o(7 downto 0)=>TXCAHRISK(7 downto 0),
2908
                TXDATA_o(63 downto 0)=>TXDATA(63 downto 0));
2909
 
2910
end BEHAVIORAL;
2911
 
2912
 

powered by: WebSVN 2.1.0

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