00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/rio/gt11_init_rx.vhd,v $ *
00015 --* $Revision: 1.4.2.6 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:47 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023 -------------------------------------------------------------------------------
00024 --$Date: 2008/11/03 17:57:47 $
00025 --$RCSfile: gt11_init_rx.vhd,v $
00026 --$Revision: 1.4.2.6 $
00027 --------------------------------------------------------------------------------
00028 -- ____ ____
00029 -- / /\/ /
00030 -- /___/ \ / Vendor: Xilinx
00031 -- \ \ \/ Version : 1.4
00032 -- \ \ Application : RocketIO Wizard
00033 -- / / Filename : gt11_init_rx.vhd
00034 -- /___/ /\ Timestamp :
00035 -- \ \ / \
00036 -- \___\/\___\
00037 --
00038 --
00039 -- Module GT11_INIT_RX
00040 -- Generated by Xilinx RocketIO Wizard
00041
00042
00043 library ieee;
00044
00045 use ieee.std_logic_1164.all;
00046
00047 use ieee.numeric_std.all;
00048 -- synopsys translate_off
00049
00050 library unisim;
00051
00052 use unisim.vcomponents.all;
00053 -- synopsys translate_on
00054
00055 --***********************************Entity Declaration*******************************
00056
00057 entity GT11_INIT_RX is
00058 generic (
00059 C_SIMULATION : := 0
00060 );
00061 port
00062 (
00063 CLK : in ;
00064 START_INIT : in ;
00065 LOCK : in ;
00066 USRCLK_STABLE : in ;
00067 PCS_ERROR : in ;
00068 PMA_RESET : out ;
00069 SYNC : out ;
00070 PCS_RESET : out ;
00071 READY : out
00072 );
00073 end GT11_INIT_RX;
00074
00075
00076 architecture rtl of GT11_INIT_RX is
00077
00078 --********************************Parameter Declarations**********************
00079 ------------------------------------------------------------------------------
00080 -- Delays - these numbers are defined by the number of USRCLK needed in each
00081 -- state for each reset. Refer to the User Guide on the block
00082 -- diagrams on the reset and the required delay.
00083 ------------------------------------------------------------------------------
00084
00085 constant C_DELAY_PMA_RESET : (2 downto 0) := "011";
00086
00087 constant C_DELAY_SYNC : (7 downto 0) := "01000000";
00088
00089 constant C_DELAY_PCS_RESET : (2 downto 0) := "011";
00090
00091 constant C_DELAY_LOCK : (4 downto 0) := "10000";
00092
00093 constant C_DELAY_WAIT_PCS : (3 downto 0) := "0101";
00094
00095 constant C_DELAY_WAIT_READY : (7 downto 0) := "01000000";
00096
00097 constant C_PCS_ERROR_COUNT : (4 downto 0) := "10000";
00098
00099 constant C_RESET : (7 downto 0) := "00000001";
00100
00101 constant C_PMA_RESET : (7 downto 0) := "00000010";
00102
00103 constant C_WAIT_LOCK : (7 downto 0) := "00000100";
00104
00105 constant C_SYNC : (7 downto 0) := "00001000";
00106
00107 constant C_PCS_RESET : (7 downto 0) := "00010000";
00108
00109 constant C_WAIT_PCS : (7 downto 0) := "00100000";
00110
00111 constant C_ALMOST_READY : (7 downto 0) := "01000000";
00112
00113 constant C_READY : (7 downto 0) := "10000000";
00114
00115 --*******************************Register Declarations************************
00116 signal reset_r : (1 downto 0);
00117 signal lock_r : ;
00118 signal lock_r2 : ;
00119 signal pcs_error_r1 : ;
00120 signal pcs_error_r2 : ;
00121 signal pma_reset_count_r : (2 downto 0);
00122 signal sync_count_r : (7 downto 0);
00123 signal pcs_reset_count_r : (2 downto 0);
00124 signal wait_pcs_count_r : (3 downto 0);
00125 signal pcs_error_count_r : (4 downto 0);
00126 signal wait_ready_count_r : (7 downto 0);
00127 signal init_state_r : (7 downto 0);
00128 signal init_next_state_r : (7 downto 0);
00129 signal init_fsm_name : (40*7 downto 0);
00130 signal init_fsm_wait_lock_check : ;
00131 --*******************************Wire Declarations****************************
00132 signal pma_reset_done_i : ;
00133 signal lock_pulse_i : ;
00134 signal stage_1_enable_i : ;
00135 signal stage_2_enable_i : ;
00136 signal stage_3_enable_i : ;
00137 signal lockupdate_ready_i : ;
00138 signal shift_register_1_enable_i : ;
00139 signal shift_register_2_enable_i : ;
00140 signal shift_register_3_enable_i : ;
00141 signal shift_register_0_d_i : ;
00142 signal shift_register_1_d_i : ;
00143 signal shift_register_2_d_i : ;
00144 signal shift_register_3_d_i : ;
00145 signal shift_register_0_q_i : ;
00146 signal shift_register_1_q_i : ;
00147 signal shift_register_2_q_i : ;
00148 signal shift_register_3_q_i : ;
00149 signal sync_done_i : ;
00150 signal pcs_reset_done_i : ;
00151 signal wait_pcs_done_i : ;
00152 signal pcs_error_count_done_i : ;
00153 signal wait_ready_done_i : ;
00154 signal tied_to_ground_i : ;
00155 signal tied_to_vcc_i : ;
00156 signal not_lock_i : ;
00157
00158 --**************************** Component Declarations ************************
00159
00160
00161 component FDE
00162 generic
00163 (
00164 INIT : := '0'
00165 );
00166 port
00167 (
00168 Q : out ;
00169 C : in ;
00170 CE : in ;
00171 D : in
00172 );
00173 end component;
00174
00175
00176 component SRL16E
00177 generic
00178 (
00179 INIT : bit_vector := X"0000"
00180 );
00181 port
00182 (
00183 Q : out ;
00184 A0 : in ;
00185 A1 : in ;
00186 A2 : in ;
00187 A3 : in ;
00188 CE : in ;
00189 CLK : in ;
00190 D : in
00191 );
00192 end component;
00193
00194
00195 component FDRE
00196 generic
00197 (
00198 INIT : := '0'
00199 );
00200 port
00201 (
00202 Q : out ;
00203 C : in ;
00204 CE : in ;
00205 D : in ;
00206 R : in
00207 );
00208 end component;
00209 --**************************** Function Declaration ************************
00210
00211
00212 function ExtendString (string_in : ;
00213 string_len : )
00214 return is
00215 variable string_out : (1 to string_len) := (others => ' ');
00216
00217 begin
00218 if string_in'length > string_len then
00219 string_out := string_in(1 to string_len);
00220 else
00221 string_out(1 to string_in'length) := string_in;
00222 end if;
00223 return string_out;
00224 end ExtendString;
00225
00226 --*********************************Main Body of Code**************************
00227
00228 begin
00229
00230 -- Static Assignments
00231 tied_to_ground_i <= '0';
00232 tied_to_vcc_i <= '1';
00233
00234
00235 process (CLK, START_INIT)
00236 begin
00237 if (START_INIT = '1') then
00238 reset_r <= "11";
00239 elsif (rising_edge(CLK)) then
00240 reset_r <= '0' & reset_r(1);
00241 end if;
00242 end process;
00243
00244
00245 process(CLK)
00246 begin
00247 if(CLK'event and CLK = '1') then
00248 if (reset_r(0) = '1') then
00249 lock_r <= '0';
00250 else
00251 lock_r <= LOCK;
00252 end if;
00253 end if;
00254 end process;
00255
00256
00257 process(CLK)
00258 begin
00259 if(CLK'event and CLK = '1') then
00260 if(reset_r(0) = '1') then
00261 pcs_error_r1 <= '0';
00262 else
00263 pcs_error_r1 <= PCS_ERROR;
00264 end if;
00265 end if;
00266 end process;
00267
00268 -- Ready, PMA and PCS reset signals
00269 PMA_RESET <= '1' when (init_state_r = C_PMA_RESET) else '0';
00270 SYNC <= '1' when (init_state_r = C_SYNC) else '0';
00271 PCS_RESET <= '1' when (init_state_r = C_PCS_RESET) else '0';
00272 READY <= '1' when (init_state_r = C_READY) else '0';
00273
00274
00275 process(CLK)
00276 begin
00277 if(CLK'event and CLK = '1') then
00278 if(init_state_r /= C_PMA_RESET) then
00279 pma_reset_count_r <= C_DELAY_PMA_RESET;
00280 else
00281 pma_reset_count_r <= pma_reset_count_r - 1;
00282 end if;
00283 end if;
00284 end process;
00285
00286 pma_reset_done_i <= '1' when (pma_reset_count_r = 1) else '0';
00287
00288 for_simulation : if (C_SIMULATION /= 0) generate
00289 begin
00290 lockupdate_ready_i <= tied_to_vcc_i;
00291 end generate for_simulation;
00292
00293 for_hardware : if (C_SIMULATION = 0) generate
00294 begin
00295
00296
00297
00298
00299 process(CLK)
00300 begin
00301 if(CLK'event and CLK = '1') then
00302 if (reset_r(0) = '1') then
00303 lock_r2 <= '0';
00304 else
00305 lock_r2 <= lock_r;
00306 end if;
00307 end if;
00308 end process;
00309
00310 lock_pulse_i <= lock_r and not lock_r2;
00311
00312 -- SRL16 Stage Zero - First stage of shifting
00313 shift_register_0_d_i <= lock_r and (lock_pulse_i or stage_1_enable_i);
00314
00315
00316
00317
00318
00319
00320
00321
00322 shift_register_0 : SRL16E
00323 port map
00324 (
00325 Q => shift_register_0_q_i,
00326 A0 => tied_to_ground_i,
00327 A1 => tied_to_vcc_i,
00328 A2 => tied_to_vcc_i,
00329 A3 => tied_to_vcc_i,
00330 CE => tied_to_vcc_i,
00331 CLK => CLK ,
00332 D => shift_register_0_d_i
00333 );
00334
00335
00336 flop_stage_0 : FDE
00337 port map
00338 (
00339 Q => stage_1_enable_i,
00340 C => CLK ,
00341 CE => tied_to_vcc_i,
00342 D => shift_register_0_q_i
00343 );
00344
00345 shift_register_1_d_i <= lock_r and (lock_pulse_i or
00346 (stage_1_enable_i and stage_2_enable_i));
00347 shift_register_1_enable_i <= not lock_r2 or stage_1_enable_i;
00348
00349
00350 shift_register_1 : SRL16E
00351 port map
00352 (
00353 Q => shift_register_1_q_i,
00354 A0 => tied_to_ground_i,
00355 A1 => tied_to_vcc_i,
00356 A2 => tied_to_vcc_i,
00357 A3 => tied_to_vcc_i,
00358 CE => shift_register_1_enable_i,
00359 CLK => CLK ,
00360 D => shift_register_1_d_i
00361 );
00362
00363
00364 flop_stage_1 : FDE
00365 port map
00366 (
00367 Q => stage_2_enable_i,
00368 C => CLK ,
00369 CE => shift_register_1_enable_i,
00370 D => shift_register_1_q_i
00371 );
00372
00373 shift_register_2_d_i <= lock_r and (lock_pulse_i or
00374 (stage_1_enable_i and stage_2_enable_i and
00375 stage_3_enable_i));
00376
00377 shift_register_2_enable_i <= not lock_r2 or
00378 (stage_1_enable_i and stage_2_enable_i);
00379
00380
00381 shift_register_2 : SRL16E
00382 port map
00383 (
00384 Q => shift_register_2_q_i,
00385 A0 => tied_to_ground_i,
00386 A1 => tied_to_vcc_i,
00387 A2 => tied_to_vcc_i,
00388 A3 => tied_to_vcc_i,
00389 CE => shift_register_2_enable_i,
00390 CLK => CLK ,
00391 D => shift_register_2_d_i
00392 );
00393
00394
00395 flop_stage_2 : FDE
00396 port map
00397 (
00398 Q => stage_3_enable_i,
00399 C => CLK ,
00400 CE => shift_register_2_enable_i,
00401 D => shift_register_2_q_i
00402 );
00403
00404 shift_register_3_d_i <= lock_r and (lock_pulse_i or
00405 (stage_1_enable_i and stage_2_enable_i and
00406 stage_3_enable_i and lockupdate_ready_i));
00407
00408 shift_register_3_enable_i <= not lock_r2 or
00409 (stage_1_enable_i and stage_2_enable_i and
00410 stage_3_enable_i and not lockupdate_ready_i);
00411
00412
00413
00414
00415 shift_register_3 : SRL16E
00416 port map
00417 (
00418 Q => shift_register_3_q_i,
00419 A0 => tied_to_vcc_i,
00420 A1 => tied_to_vcc_i,
00421 A2 => tied_to_ground_i,
00422 A3 => tied_to_ground_i,
00423 CE => shift_register_3_enable_i,
00424 CLK => CLK ,
00425 D => shift_register_3_d_i
00426 );
00427
00428 not_lock_i <= not lock_r;
00429
00430
00431 flop_stage_3 : FDRE
00432 port map
00433 (
00434 Q => lockupdate_ready_i,
00435 C => CLK ,
00436 CE => shift_register_3_enable_i,
00437 D => shift_register_3_q_i,
00438 R => not_lock_i
00439 );
00440 end generate for_hardware;
00441
00442
00443 process(CLK)
00444 begin
00445 if(CLK'event and CLK = '1') then
00446 if(init_state_r /= C_SYNC) then
00447 sync_count_r <= C_DELAY_SYNC;
00448 else
00449 sync_count_r <= sync_count_r - 1;
00450 end if;
00451 end if;
00452 end process;
00453
00454 sync_done_i <= '1' when (sync_count_r = 1) else '0';
00455
00456
00457 process(CLK)
00458 begin
00459 if(CLK'event and CLK = '1') then
00460 if(init_state_r /= C_PCS_RESET) then
00461 pcs_reset_count_r <= C_DELAY_PCS_RESET;
00462 else
00463 pcs_reset_count_r <= pcs_reset_count_r - 1;
00464 end if;
00465 end if;
00466 end process;
00467
00468 pcs_reset_done_i <= '1' when (pcs_reset_count_r = 1) else '0';
00469
00470
00471 process(CLK)
00472 begin
00473 if(CLK'event and CLK = '1') then
00474 if(init_state_r /= C_WAIT_PCS) then
00475 wait_pcs_count_r <= C_DELAY_WAIT_PCS;
00476 else
00477 wait_pcs_count_r <= wait_pcs_count_r - 1;
00478 end if;
00479 end if;
00480 end process;
00481
00482 wait_pcs_done_i <= '1' when (wait_pcs_count_r = 1) else '0';
00483
00484
00485 process(CLK)
00486 begin
00487 if(CLK'event and CLK = '1') then
00488 if(init_state_r = C_PMA_RESET) then
00489 pcs_error_count_r <= C_PCS_ERROR_COUNT;
00490 elsif (((init_state_r = C_ALMOST_READY) or (init_state_r = C_READY)) and (pcs_error_r1 and lock_r) = '1') then
00491 pcs_error_count_r <= pcs_error_count_r - 1;
00492 end if;
00493 end if;
00494 end process;
00495
00496 pcs_error_count_done_i <= '1' when (pcs_error_count_r = 1) else '0';
00497
00498
00499 process(CLK)
00500 begin
00501 if(CLK'event and CLK = '1') then
00502 if((init_state_r /= C_ALMOST_READY) or (pcs_error_r1 = '1')) then
00503 wait_ready_count_r <= C_DELAY_WAIT_READY;
00504 elsif(pcs_error_r1 = '0') then
00505 wait_ready_count_r <= wait_ready_count_r - 1;
00506 end if;
00507 end if;
00508 end process;
00509
00510 wait_ready_done_i <= '1' when (wait_ready_count_r = 1) else '0';
00511
00512
00513 process (CLK)
00514 begin
00515 if (rising_edge(CLK)) then
00516 if (reset_r(0) = '1') then
00517 init_state_r <= C_RESET;
00518 else
00519 init_state_r <= init_next_state_r;
00520 end if;
00521 end if;
00522 end process;
00523
00524 init_fsm_wait_lock_check <= lock_r and USRCLK_STABLE and lockupdate_ready_i;
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557 process (reset_r(0), pma_reset_done_i, init_fsm_wait_lock_check, lock_r,
00558 sync_done_i, pcs_reset_done_i, wait_pcs_done_i, pcs_error_r1,
00559 pcs_error_count_done_i, wait_ready_done_i)
00560 variable init_fsm_name : (1 to 25);
00561 begin
00562 case init_state_r is
00563
00564 when C_RESET =>
00565
00566 if (reset_r(0) = '1') then
00567 init_next_state_r <= C_RESET;
00568 else
00569 init_next_state_r <= C_PMA_RESET;
00570 end if;
00571 init_fsm_name := ExtendString("C_RESET", 25);
00572
00573 when C_PMA_RESET =>
00574
00575 if (pma_reset_done_i = '1') then
00576 init_next_state_r <= C_WAIT_LOCK;
00577 else
00578 init_next_state_r <= C_PMA_RESET;
00579 end if;
00580 init_fsm_name := ExtendString("C_PMA_RESET", 25);
00581
00582 when C_WAIT_LOCK =>
00583
00584 if(init_fsm_wait_lock_check = '1') then
00585 init_next_state_r <= C_SYNC;
00586 else
00587 init_next_state_r <= C_WAIT_LOCK;
00588 end if;
00589 init_fsm_name := ExtendString("C_WAIT_LOCK", 25);
00590
00591 when C_SYNC =>
00592 if (lock_r = '1') then
00593 if (sync_done_i = '1') then
00594 init_next_state_r <= C_PCS_RESET;
00595 else
00596 init_next_state_r <= C_SYNC;
00597 end if;
00598 else
00599 init_next_state_r <= C_PMA_RESET; --C_WAIT_LOCK;
00600 end if;
00601 init_fsm_name := ExtendString("C_SYNC", 25);
00602
00603 when C_PCS_RESET =>
00604 if (lock_r = '1') then
00605 if (pcs_reset_done_i = '1') then
00606 init_next_state_r <= C_WAIT_PCS;
00607 else
00608 init_next_state_r <= C_PCS_RESET;
00609 end if;
00610 else
00611 init_next_state_r <= C_PMA_RESET; --C_WAIT_LOCK;
00612 end if;
00613 init_fsm_name := ExtendString("C_PCS_RESET", 25);
00614
00615 when C_WAIT_PCS =>
00616 if (lock_r = '1') then
00617 if (wait_pcs_done_i = '1') then
00618 init_next_state_r <= C_ALMOST_READY;
00619 else
00620 init_next_state_r <= C_WAIT_PCS;
00621 end if;
00622 else
00623 init_next_state_r <= C_PMA_RESET; --C_WAIT_LOCK;
00624 end if;
00625 init_fsm_name := ExtendString("C_WAIT_PCS", 25);
00626
00627 when C_ALMOST_READY =>
00628 if (lock_r = '0') then
00629 init_next_state_r <= C_PMA_RESET; --C_WAIT_LOCK;
00630 elsif ((pcs_error_r1 = '1') and (pcs_error_count_done_i = '0')) then
00631 init_next_state_r <= C_SYNC;
00632 elsif ((pcs_error_r1 = '1') and (pcs_error_count_done_i = '1')) then
00633 init_next_state_r <= C_PMA_RESET;
00634 elsif (wait_ready_done_i = '1') then
00635 init_next_state_r <= C_READY;
00636 else
00637 init_next_state_r <= C_ALMOST_READY;
00638 end if;
00639 init_fsm_name := ExtendString("C_ALMOST_READY", 25);
00640
00641 when C_READY =>
00642 if ((lock_r = '1') and (pcs_error_r1 = '0')) then
00643 init_next_state_r <= C_READY;
00644 elsif ((lock_r = '1') and (pcs_error_r1 = '1')) then
00645 init_next_state_r <= C_PCS_RESET;
00646 else
00647 init_next_state_r <= C_PMA_RESET; --C_WAIT_LOCK;
00648 end if;
00649 init_fsm_name := ExtendString("C_READY", 25);
00650
00651 when others =>
00652 init_next_state_r <= C_RESET;
00653 init_fsm_name := ExtendString("C_RESET", 25);
00654
00655 end case;
00656 end process;
00657
00658 end rtl;
00659