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_tx.vhd,v $
00015 --* $Revision: 1.4.2.5 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:48 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023 -------------------------------------------------------------------------------
00024 --$Date: 2008/11/03 17:57:48 $
00025 --$RCSfile: gt11_init_tx.vhd,v $
00026 --$Revision: 1.4.2.5 $
00027 --------------------------------------------------------------------------------
00028 -- ____ ____
00029 -- / /\/ /
00030 -- /___/ \ / Vendor: Xilinx
00031 -- \ \ \/ Version : 1.4
00032 -- \ \ Application : RocketIO Wizard
00033 -- / / Filename : gt11_init_tx.vhd
00034 -- /___/ /\ Timestamp :
00035 -- \ \ / \
00036 -- \___\/\___\
00037 --
00038 --
00039 -- Module GT11_INIT_TX
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_TX 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_TX;
00074
00075
00076 architecture rtl of GT11_INIT_TX 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 lock2sync_ready_i : ;
00134 signal sync_done_i : ;
00135 signal pcs_reset_done_i : ;
00136 signal wait_pcs_done_i : ;
00137 signal pcs_error_count_done_i : ;
00138 signal wait_ready_done_i : ;
00139 signal tied_to_ground_i : ;
00140 signal tied_to_vcc_i : ;
00141 signal lock_pulse_i : ;
00142 signal shift_register_0_q_i : ;
00143 signal shift_register_0_d_i : ;
00144 signal shift_register_1_q_i : ;
00145 signal shift_register_1_d_i : ;
00146 signal shift_register_2_q_i : ;
00147 signal shift_register_2_d_i : ;
00148 signal shift_register_3_q_i : ;
00149 signal shift_register_3_d_i : ;
00150 signal stage_1_enable_i : ;
00151 signal stage_2_enable_i : ;
00152 signal stage_3_enable_i : ;
00153 signal shift_register_1_enable_i : ;
00154 signal shift_register_2_enable_i : ;
00155 signal shift_register_3_enable_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
00210 --**************************** Function Declaration ************************
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 -- Static Assignments
00230 tied_to_ground_i <= '0';
00231 tied_to_vcc_i <= '1';
00232
00233
00234 process (CLK, START_INIT)
00235 begin
00236 if (START_INIT = '1') then
00237 reset_r <= "11";
00238 elsif (rising_edge(CLK)) then
00239 reset_r <= '0' & reset_r(1);
00240 end if;
00241 end process;
00242
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
00258 process(CLK)
00259 begin
00260 if(CLK'event and CLK = '1') then
00261 if(reset_r(0) = '1') then
00262 pcs_error_r1 <= '0';
00263 else
00264 pcs_error_r1 <= PCS_ERROR;
00265 end if;
00266 end if;
00267 end process;
00268
00269 -- Ready, PMA and PCS reset signals
00270 PMA_RESET <= '1' when (init_state_r = C_PMA_RESET) else '0';
00271 SYNC <= '1' when (init_state_r = C_SYNC) else '0';
00272 PCS_RESET <= '1' when (init_state_r = C_PCS_RESET) else '0';
00273 READY <= '1' when (init_state_r = C_READY) else '0';
00274
00275
00276
00277 process(CLK)
00278 begin
00279 if(CLK'event and CLK = '1') then
00280 if(init_state_r /= C_PMA_RESET) then
00281 pma_reset_count_r <= C_DELAY_PMA_RESET;
00282 else
00283 pma_reset_count_r <= pma_reset_count_r - 1;
00284 end if;
00285 end if;
00286 end process;
00287
00288 pma_reset_done_i <= '1' when (pma_reset_count_r = 1) else '0';
00289
00290 for_simulation : if (C_SIMULATION /= 0) generate
00291 begin
00292 lock2sync_ready_i <= tied_to_vcc_i;
00293 end generate for_simulation;
00294
00295 for_hardware : if (C_SIMULATION = 0) generate
00296 begin
00297
00298
00299
00300 process(CLK)
00301 begin
00302 if(CLK'event and CLK = '1') then
00303 if (reset_r(0) = '1') then
00304 lock_r2 <= '0';
00305 else
00306 lock_r2 <= lock_r;
00307 end if;
00308 end if;
00309 end process;
00310
00311 lock_pulse_i <= lock_r and not lock_r2;
00312
00313 -- SRL16 Stage Zero - First stage of shifting
00314 shift_register_0_d_i <= lock_r and (lock_pulse_i or stage_1_enable_i);
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 shift_register_0 : SRL16E
00325 port map
00326 (
00327 Q => shift_register_0_q_i,
00328 A0 => tied_to_ground_i,
00329 A1 => tied_to_vcc_i,
00330 A2 => tied_to_vcc_i,
00331 A3 => tied_to_vcc_i,
00332 CE => tied_to_vcc_i,
00333 CLK => CLK ,
00334 D => shift_register_0_d_i
00335 );
00336
00337
00338 flop_stage_0 : FDE
00339 port map
00340 (
00341 Q => stage_1_enable_i,
00342 C => CLK ,
00343 CE => tied_to_vcc_i,
00344 D => shift_register_0_q_i
00345 );
00346
00347 shift_register_1_d_i <= lock_r and (lock_pulse_i or
00348 (stage_1_enable_i and stage_2_enable_i));
00349 shift_register_1_enable_i <= not lock_r2 or stage_1_enable_i;
00350
00351
00352 shift_register_1 : SRL16E
00353 port map
00354 (
00355 Q => shift_register_1_q_i,
00356 A0 => tied_to_ground_i,
00357 A1 => tied_to_vcc_i,
00358 A2 => tied_to_vcc_i,
00359 A3 => tied_to_vcc_i,
00360 CE => shift_register_1_enable_i,
00361 CLK => CLK ,
00362 D => shift_register_1_d_i
00363 );
00364
00365
00366 flop_stage_1 : FDE
00367 port map
00368 (
00369 Q => stage_2_enable_i,
00370 C => CLK ,
00371 CE => shift_register_1_enable_i,
00372 D => shift_register_1_q_i
00373 );
00374
00375 shift_register_2_d_i <= lock_r and (lock_pulse_i or
00376 (stage_1_enable_i and stage_2_enable_i and
00377 stage_3_enable_i));
00378
00379 shift_register_2_enable_i <= not lock_r2 or
00380 (stage_1_enable_i and stage_2_enable_i);
00381
00382
00383 shift_register_2 : SRL16E
00384 port map
00385 (
00386 Q => shift_register_2_q_i,
00387 A0 => tied_to_ground_i,
00388 A1 => tied_to_vcc_i,
00389 A2 => tied_to_vcc_i,
00390 A3 => tied_to_vcc_i,
00391 CE => shift_register_2_enable_i,
00392 CLK => CLK ,
00393 D => shift_register_2_d_i
00394 );
00395
00396
00397 flop_stage_2 : FDE
00398 port map
00399 (
00400 Q => stage_3_enable_i,
00401 C => CLK ,
00402 CE => shift_register_2_enable_i,
00403 D => shift_register_2_q_i
00404 );
00405
00406 shift_register_3_d_i <= lock_r and (lock_pulse_i or
00407 (stage_1_enable_i and stage_2_enable_i and
00408 stage_3_enable_i and lock2sync_ready_i));
00409
00410 shift_register_3_enable_i <= not lock_r2 or
00411 (stage_1_enable_i and stage_2_enable_i and
00412 stage_3_enable_i and not lock2sync_ready_i);
00413
00414
00415 shift_register_3 : SRL16E
00416 port map
00417 (
00418 Q => shift_register_3_q_i,
00419 A0 => tied_to_ground_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 => lock2sync_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
00444 process(CLK)
00445 begin
00446 if(CLK'event and CLK = '1') then
00447 if(init_state_r /= C_SYNC) then
00448 sync_count_r <= C_DELAY_SYNC;
00449 else
00450 sync_count_r <= sync_count_r - 1;
00451 end if;
00452 end if;
00453 end process;
00454
00455 sync_done_i <= '1' when (sync_count_r = 1) else '0';
00456
00457
00458 process(CLK)
00459 begin
00460 if(CLK'event and CLK = '1') then
00461 if(init_state_r /= C_PCS_RESET) then
00462 pcs_reset_count_r <= C_DELAY_PCS_RESET;
00463 else
00464 pcs_reset_count_r <= pcs_reset_count_r - 1;
00465 end if;
00466 end if;
00467 end process;
00468
00469 pcs_reset_done_i <= '1' when (pcs_reset_count_r = 1) else '0';
00470
00471
00472 process(CLK)
00473 begin
00474 if(CLK'event and CLK = '1') then
00475 if(init_state_r /= C_WAIT_PCS) then
00476 wait_pcs_count_r <= C_DELAY_WAIT_PCS;
00477 else
00478 wait_pcs_count_r <= wait_pcs_count_r - 1;
00479 end if;
00480 end if;
00481 end process;
00482
00483 wait_pcs_done_i <= '1' when (wait_pcs_count_r = 1) else '0';
00484
00485
00486 process(CLK)
00487 begin
00488 if(CLK'event and CLK = '1') then
00489 if(init_state_r = C_PMA_RESET) then
00490 pcs_error_count_r <= C_PCS_ERROR_COUNT;
00491 elsif (((init_state_r = C_ALMOST_READY) or (init_state_r = C_READY)) and (pcs_error_r1 and lock_r) = '1') then
00492 pcs_error_count_r <= pcs_error_count_r - 1;
00493 end if;
00494 end if;
00495 end process;
00496
00497 pcs_error_count_done_i <= '1' when (pcs_error_count_r = 1) else '0';
00498
00499
00500 process(CLK)
00501 begin
00502 if(CLK'event and CLK = '1') then
00503 if((init_state_r /= C_ALMOST_READY) or (pcs_error_r1 = '1')) then
00504 wait_ready_count_r <= C_DELAY_WAIT_READY;
00505 elsif(pcs_error_r1 = '0') then
00506 wait_ready_count_r <= wait_ready_count_r - 1;
00507 end if;
00508 end if;
00509 end process;
00510
00511 wait_ready_done_i <= '1' when (wait_ready_count_r = 1) else '0';
00512
00513
00514 process (CLK)
00515 begin
00516 if (rising_edge(CLK)) then
00517 if (reset_r(0) = '1') then
00518 init_state_r <= C_RESET;
00519 else
00520 init_state_r <= init_next_state_r;
00521 end if;
00522 end if;
00523 end process;
00524
00525 init_fsm_wait_lock_check <= lock_r and USRCLK_STABLE and lock2sync_ready_i;
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
00558 process (reset_r(0), pma_reset_done_i, init_fsm_wait_lock_check, lock_r,
00559 sync_done_i, pcs_reset_done_i, wait_pcs_done_i, pcs_error_r1,
00560 pcs_error_count_done_i, wait_ready_done_i)
00561 variable init_fsm_name : (1 to 25);
00562 begin
00563 case init_state_r is
00564
00565 when C_RESET =>
00566
00567 if (reset_r(0) = '1') then
00568 init_next_state_r <= C_RESET;
00569 else
00570 init_next_state_r <= C_PMA_RESET;
00571 end if;
00572 init_fsm_name := ExtendString("C_RESET", 25);
00573
00574 when C_PMA_RESET =>
00575
00576 if (pma_reset_done_i = '1') then
00577 init_next_state_r <= C_WAIT_LOCK;
00578 else
00579 init_next_state_r <= C_PMA_RESET;
00580 end if;
00581 init_fsm_name := ExtendString("C_PMA_RESET", 25);
00582
00583 when C_WAIT_LOCK =>
00584
00585 if(init_fsm_wait_lock_check = '1') then
00586 init_next_state_r <= C_SYNC;
00587 else
00588 init_next_state_r <= C_WAIT_LOCK;
00589 end if;
00590 init_fsm_name := ExtendString("C_WAIT_LOCK", 25);
00591
00592 when C_SYNC =>
00593 if (lock_r = '1') then
00594 if (sync_done_i = '1') then
00595 init_next_state_r <= C_PCS_RESET;
00596 else
00597 init_next_state_r <= C_SYNC;
00598 end if;
00599 else
00600 init_next_state_r <= C_WAIT_LOCK;
00601 end if;
00602 init_fsm_name := ExtendString("C_SYNC", 25);
00603
00604 when C_PCS_RESET =>
00605 if (lock_r = '1') then
00606 if (pcs_reset_done_i = '1') then
00607 init_next_state_r <= C_WAIT_PCS;
00608 else
00609 init_next_state_r <= C_PCS_RESET;
00610 end if;
00611 else
00612 init_next_state_r <= C_WAIT_LOCK;
00613 end if;
00614 init_fsm_name := ExtendString("C_PCS_RESET", 25);
00615
00616 when C_WAIT_PCS =>
00617 if (lock_r = '1') then
00618 if (wait_pcs_done_i = '1') then
00619 init_next_state_r <= C_ALMOST_READY;
00620 else
00621 init_next_state_r <= C_WAIT_PCS;
00622 end if;
00623 else
00624 init_next_state_r <= C_WAIT_LOCK;
00625 end if;
00626 init_fsm_name := ExtendString("C_WAIT_PCS", 25);
00627
00628 when C_ALMOST_READY =>
00629 if (lock_r = '0') then
00630 init_next_state_r <= C_WAIT_LOCK;
00631 elsif ((pcs_error_r1 = '1') and (pcs_error_count_done_i = '0')) then
00632 init_next_state_r <= C_SYNC;
00633 elsif ((pcs_error_r1 = '1') and (pcs_error_count_done_i = '1')) then
00634 init_next_state_r <= C_PMA_RESET;
00635 elsif (wait_ready_done_i = '1') then
00636 init_next_state_r <= C_READY;
00637 else
00638 init_next_state_r <= C_ALMOST_READY;
00639 end if;
00640 init_fsm_name := ExtendString("C_ALMOST_READY", 25);
00641
00642 when C_READY =>
00643 if ((lock_r = '1') and (pcs_error_r1 = '0')) then
00644 init_next_state_r <= C_READY;
00645 elsif ((lock_r = '1') and (pcs_error_r1 = '1')) then
00646 init_next_state_r <= C_PCS_RESET;
00647 else
00648 init_next_state_r <= C_WAIT_LOCK;
00649 end if;
00650 init_fsm_name := ExtendString("C_READY", 25);
00651
00652 when others =>
00653 init_next_state_r <= C_RESET;
00654 init_fsm_name := ExtendString("C_RESET", 25);
00655
00656 end case;
00657 end process;
00658
00659 end rtl;
00660