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