-- (c) Copyright 2008 Xilinx, Inc. All rights reserved.
--
-- This file contains confidential and proprietary information
-- of Xilinx, Inc. and is protected under U.S. and
-- international copyright and other intellectual property
-- laws.
--
-- DISCLAIMER
-- This disclaimer is not a license and does not grant any
-- rights to the materials distributed herewith. Except as
-- otherwise provided in a valid license issued to you by
-- Xilinx, and to the maximum extent permitted by applicable
-- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
-- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
-- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
-- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
-- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
-- (2) Xilinx shall not be liable (whether in contract or tort,
-- including negligence, or under any other theory of
-- liability) for any loss or damage of any kind or nature
-- related to, arising under or in connection with these
-- materials, including for any direct, or any indirect,
-- special, incidental, or consequential loss or damage
-- (including loss of data, profits, goodwill, or any type of
-- loss or damage suffered as a result of any action brought
-- by a third party) even if such damage or loss was
-- reasonably foreseeable or Xilinx had been advised of the
-- possibility of the same.
--
-- CRITICAL APPLICATIONS
-- Xilinx products are not designed or intended to be fail-
-- safe, or for use in any application requiring fail-safe
-- performance, such as life-support or safety devices or
-- systems, Class III medical devices, nuclear facilities,
-- applications related to the deployment of airbags, or any
-- other applications that could lead to death, personal
-- injury, or severe property or environmental damage
-- (individually and collectively, "Critical
-- Applications"). Customer assumes the sole risk and
-- liability of any use of Xilinx products in Critical
-- Applications, subject only to applicable laws and
-- regulations governing limitations on product liability.
--
-- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
-- PART OF THIS FILE AT ALL TIMES.
--
--

--
--  RX_AURORA_LANE_SIMPLEX_V5
--
--
--
--  Description: The AURORA_LANE module provides a simplex 2-byte aurora
--               lane connection using a single V5.  The module handles lane
--               initialization, symbol decoding as well as error detection.
--               It also decodes some of the channel bonding indicator signals
--               needed by the Global logic.
--               The parameter USE_NFC is expected to be FALSE for simplex since
--               Native Flow Control is not supported in Simplex mode
--
--               * Supports V5
--

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity aurora_rx_4l_64b_RX_AURORA_LANE_SIMPLEX_V5 is
    generic (
            EXAMPLE_SIMULATION       : integer :=  0     
         );
    port (

    -- V5 Interface

            RX_DATA           : in std_logic_vector(15 downto 0);  -- 2-byte data bus from the V5.
            RX_NOT_IN_TABLE   : in std_logic_vector(1 downto 0);   -- Invalid 10-bit code was recieved.
            RX_DISP_ERR       : in std_logic_vector(1 downto 0);   -- Disparity error detected on RX interface.
            RX_CHAR_IS_K      : in std_logic_vector(1 downto 0);   -- Indicates which bytes of RX_DATA are control.
            RX_CHAR_IS_COMMA  : in std_logic_vector(1 downto 0);   -- Comma received on given byte.
            RX_STATUS         : in std_logic_vector(5 downto 0);                      -- V5 Status and Event bus.
            RX_BUF_ERR        : in std_logic;                      -- Provides one bit of V5 Status and Event bus.
            RX_REALIGN        : in std_logic;                      -- SERDES was realigned because of a new comma.
            RX_POLARITY       : out std_logic;                     -- Controls interpreted polarity of serial data inputs.
            V5_RX_RESET       : out std_logic;                     -- Reset RX side of V5 logic.
            LINK_RESET_OUT    : out std_logic;                     -- Link reset for hotplug scenerio.
            HPCNT_RESET       : in  std_logic;                     -- Hotplug count reset input.
            INIT_CLK          : in  std_logic;

            ENA_COMMA_ALIGN   : out std_logic;                     -- Request comma alignment.


    -- RX_LL Interface

            RX_PAD            : out std_logic;                     -- Indicates lane received PAD.
            RX_PE_DATA        : out std_logic_vector(0 to 15);     -- RX data from lane to RX_LL.
            RX_PE_DATA_V      : out std_logic;                     -- RX_PE_DATA is data, not control symbol.
            RX_SCP            : out std_logic;                     -- Indicates lane received SCP.
            RX_ECP            : out std_logic;                     -- Indicates lane received ECP.
            RX_SUF            : out std_logic;                     -- Indicates lane received SUF.
            RX_FC_NB          : out std_logic_vector(0 to 3);      -- Size code for SNF or SUF.

    -- Global Logic Interface

            CHANNEL_UP        : in  std_logic;                     -- Channel is verified and ready
            LANE_UP           : out std_logic;                     -- Lane is ready for bonding and verification.
            SOFT_ERR        : out std_logic;                     -- Soft error detected.
            HARD_ERR        : out std_logic;                     -- Hard error detected.
            CHANNEL_BOND_LOAD : out std_logic;                     -- Channel Bonding done code received.
            GOT_A             : out std_logic_vector(0 to 1);      -- Indicates lane recieved 'A character' bytes.
            GOT_V             : out std_logic;                     -- Verification symbols received.

    -- System Interface

            USER_CLK          : in std_logic;                      -- System clock for all non-V5 Aurora Logic.
            RESET             : in std_logic                       -- Reset the lane.

         );

end aurora_rx_4l_64b_RX_AURORA_LANE_SIMPLEX_V5;

architecture MAPPED of aurora_rx_4l_64b_RX_AURORA_LANE_SIMPLEX_V5 is
-- External Register Declarations --

    signal RX_POLARITY_Buffer       : std_logic;
    signal V5_RX_RESET_Buffer       : std_logic;
    signal RX_PAD_Buffer            : std_logic;
    signal RX_PE_DATA_Buffer        : std_logic_vector(0 to 15);
    signal RX_PE_DATA_V_Buffer      : std_logic;
    signal RX_SCP_Buffer            : std_logic;
    signal RX_ECP_Buffer            : std_logic;
    signal RX_SUF_Buffer            : std_logic;
    signal RX_FC_NB_Buffer          : std_logic_vector(0 to 3);
    signal LANE_UP_Buffer           : std_logic;
    signal SOFT_ERR_Buffer        : std_logic;
    signal HARD_ERR_Buffer        : std_logic;
    signal CHANNEL_BOND_LOAD_Buffer : std_logic;
    signal GOT_A_Buffer             : std_logic_vector(0 to 1);
    signal GOT_V_Buffer             : std_logic;

-- Wire Declarations --

    signal rx_cc_i                  : std_logic;
    signal rx_sp_i                  : std_logic;
    signal rx_spa_i                 : std_logic;
    signal rx_neg_i                 : std_logic;
    signal enable_err_detect_i    : std_logic;
    signal do_word_align_i          : std_logic;
    signal hard_err_reset_i       : std_logic;

    signal rx_data_r                : std_logic_vector(15 downto 0);
    signal rx_char_is_k_r           : std_logic_vector(1 downto 0);
    signal rx_char_is_comma_r       : std_logic_vector(1 downto 0);
    signal rx_disp_err_r            : std_logic_vector(1 downto 0);
    signal rx_not_in_table_r        : std_logic_vector(1 downto 0);


-- Component Declarations --

    component aurora_rx_4l_64b_RX_LANE_INIT_SM_SIMPLEX

        port (

        -- V5 Interface

                RX_NOT_IN_TABLE     : in std_logic_vector(1 downto 0);  -- V5 received invalid 10b code.
                RX_DISP_ERR         : in std_logic_vector(1 downto 0);  -- V5 received 10b code w/ wrong disparity.
                RX_CHAR_IS_COMMA    : in std_logic_vector(1 downto 0);  -- V5 received a Comma.
                RX_REALIGN          : in std_logic;                     -- V5 had to change alignment due to new comma.
                V5_RX_RESET         : out std_logic;                    -- Reset the RX side of the V5.
                RX_POLARITY         : out std_logic;                    -- Sets polarity used to interpet rx'ed symbols.

        -- Comma Detect Phase Alignment Interface

                ENA_COMMA_ALIGN     : out std_logic;                    -- Turn on SERDES Alignment in V5.

        -- Symbol Decoder Interface

                RX_SP               : in std_logic;                     -- Lane rx'ed SP sequence w/ + or - data.
                RX_NEG              : in std_logic;                     -- Lane rx'ed inverted SP data.
                DO_WORD_ALIGN       : out std_logic;                    -- Enable word alignment.

        -- Error Detection Logic Interface

                ENABLE_ERR_DETECT : out std_logic;                    -- Turn on Soft Error detection.
                HARD_ERR_RESET    : in  std_logic;                    -- Reset lane due to hard error.


        -- Global Logic Interface

                LANE_UP             : out std_logic;                    -- Lane is initialized.
                CHANNEL_UP          : in  std_logic;                    -- Channels are bonded and verified

        -- System Interface

                USER_CLK            : in std_logic;                     -- Clock for all non-V5 Aurora logic.
                RESET               : in std_logic                      -- Reset Aurora Lane.

             );

    end component;


    component aurora_rx_4l_64b_CHBOND_COUNT_DEC

        port (

                RX_STATUS         : in  std_logic_vector(5 downto 0);
                CHANNEL_BOND_LOAD : out std_logic;
                USER_CLK          : in  std_logic

             );

    end component;


    component aurora_rx_4l_64b_SYM_DEC

        port (

        -- RX_LL Interface

                RX_PAD           : out std_logic;                    -- LSByte is PAD.
                RX_PE_DATA       : out std_logic_vector(0 to 15);    -- Word aligned data from channel partner.
                RX_PE_DATA_V     : out std_logic;                    -- Data is valid data and not a control character.
                RX_SCP           : out std_logic;                    -- SCP symbol received.
                RX_ECP           : out std_logic;                    -- ECP symbol received.
                RX_SUF           : out std_logic;                    -- SUF symbol reveived.
                RX_FC_NB         : out std_logic_vector(0 to 3);     -- Flow Control size code.  Valid with RX_SNF or RX_SUF.

        -- Lane Init SM Interface

                DO_WORD_ALIGN    : in std_logic;                     -- Word alignment is allowed.
                RX_SP            : out std_logic;                    -- SP sequence received with positive or negative data.
                RX_SPA           : out std_logic;                    -- SPA sequence received.
                RX_NEG           : out std_logic;                    -- Intverted data for SP or SPA received.

        -- Global Logic Interface

                GOT_A            : out std_logic_vector(0 to 1);     -- A character received on indicated byte(s).
                GOT_V            : out std_logic;                    -- V sequence received.

        -- V5 Interface

                RX_DATA          : in std_logic_vector(15 downto 0); -- Raw RX data from V5.
                RX_CHAR_IS_K     : in std_logic_vector(1 downto 0);  -- Bits indicating which bytes are control characters.
                RX_CHAR_IS_COMMA : in std_logic_vector(1 downto 0);  -- Rx'ed a comma.
                RX_CC            : out std_logic;                    -- CC sequence received.

        -- System Interface

                USER_CLK         : in std_logic;                     -- System clock for all non-V5 Aurora Logic.
                RESET            : in std_logic

             );

    end component;


    component aurora_rx_4l_64b_RX_ERR_DETECT_SIMPLEX_V5

        port (

        -- Lane Init SM Interface

                ENABLE_ERR_DETECT : in std_logic;
                HARD_ERR_RESET    : out std_logic;

        -- Global Logic Interface

                SOFT_ERR          : out std_logic;
                HARD_ERR          : out std_logic;

        -- V5 Interface

                RX_DISP_ERR         : in std_logic_vector(1 downto 0);
                RX_NOT_IN_TABLE     : in std_logic_vector(1 downto 0);
                RX_BUF_ERR          : in std_logic;
                RX_REALIGN          : in std_logic;

        -- System Interface

                USER_CLK            : in std_logic

             );

    end component;

component aurora_rx_4l_64b_HOTPLUG
generic
(
  ENABLE_HOTPLUG          : integer :=   1;
  EXAMPLE_SIMULATION       : integer :=  0     
);
port
(

  ---------------------- Sym Dec Interface -------------------------------
  RX_CC               : in    std_logic;
  RX_SP               : in    std_logic;
  RX_SPA              : in    std_logic;

  ----------------------  GT Wrapper Interface ----------------------------
  LINK_RESET_OUT      : out   std_logic;
  HPCNT_RESET         : in    std_logic;  

  ----------------------  System Interface ----------------------------
  INIT_CLK            : in    std_logic;
  USER_CLK            : in    std_logic;
  RESET               : in    std_logic

);
end component;


begin

    RX_POLARITY         <= RX_POLARITY_Buffer;
    V5_RX_RESET         <= V5_RX_RESET_Buffer;
    RX_PAD              <= RX_PAD_Buffer;
    RX_PE_DATA          <= RX_PE_DATA_Buffer;
    RX_PE_DATA_V        <= RX_PE_DATA_V_Buffer;
    RX_SCP              <= RX_SCP_Buffer;
    RX_ECP              <= RX_ECP_Buffer;
    RX_SUF              <= RX_SUF_Buffer;
    RX_FC_NB            <= RX_FC_NB_Buffer;
    LANE_UP             <= LANE_UP_Buffer;
    SOFT_ERR          <= SOFT_ERR_Buffer;
    HARD_ERR          <= HARD_ERR_Buffer;
    CHANNEL_BOND_LOAD   <= CHANNEL_BOND_LOAD_Buffer;
    GOT_A               <= GOT_A_Buffer;
    GOT_V               <= GOT_V_Buffer;
    rx_data_r           <= RX_DATA(7 downto 0) & RX_DATA(15 downto 8);
    rx_char_is_k_r      <= RX_CHAR_IS_K(0) & RX_CHAR_IS_K(1);
    rx_char_is_comma_r  <= RX_CHAR_IS_COMMA(0) & RX_CHAR_IS_COMMA(1);
    rx_disp_err_r       <= RX_DISP_ERR(0) & RX_DISP_ERR(1);
    rx_not_in_table_r   <= RX_NOT_IN_TABLE(0) & RX_NOT_IN_TABLE(1);

-- ************************** Main Body of Code **********************************--

    -- Lane Initialization state machine

    rx_lane_init_sm_simplex_i : aurora_rx_4l_64b_RX_LANE_INIT_SM_SIMPLEX

        port map (

        -- V5 Interface

                    RX_NOT_IN_TABLE     => RX_NOT_IN_TABLE,
                    RX_DISP_ERR         => RX_DISP_ERR,
                    RX_CHAR_IS_COMMA    => RX_CHAR_IS_COMMA,
                    RX_REALIGN          => RX_REALIGN,
                    V5_RX_RESET         => V5_RX_RESET_Buffer,
                    RX_POLARITY         => RX_POLARITY_Buffer,

        -- Comma Detect Phase Alignment Interface

                    ENA_COMMA_ALIGN     => ENA_COMMA_ALIGN,

        -- Symbol Decoder Interface

                    RX_SP               => rx_sp_i,
                    RX_NEG              => rx_neg_i,
                    DO_WORD_ALIGN       => do_word_align_i,

        -- Error Detection Logic Interface

                    HARD_ERR_RESET    => hard_err_reset_i,
                    ENABLE_ERR_DETECT => enable_err_detect_i,


        -- Global Logic Interface

                    LANE_UP             => LANE_UP_Buffer,
                    CHANNEL_UP          => CHANNEL_UP,
        -- System Interface

                    USER_CLK            => USER_CLK,
                    RESET               => RESET

                 );


    -- Channel Bonding Count Decode module

    chbond_count_dec_i : aurora_rx_4l_64b_CHBOND_COUNT_DEC

        port map (

                    RX_STATUS         => RX_STATUS,
                    CHANNEL_BOND_LOAD => CHANNEL_BOND_LOAD_Buffer,
                    USER_CLK          => USER_CLK

                 );


    -- Symbol Decode module

    sym_dec_i : aurora_rx_4l_64b_SYM_DEC

        port map (

        -- RX_LL Interface

                    RX_PAD           => RX_PAD_Buffer,
                    RX_PE_DATA       => RX_PE_DATA_Buffer,
                    RX_PE_DATA_V     => RX_PE_DATA_V_Buffer,
                    RX_SCP           => RX_SCP_Buffer,
                    RX_ECP           => RX_ECP_Buffer,
                    RX_SUF           => RX_SUF_Buffer,
                    RX_FC_NB         => RX_FC_NB_Buffer,

        -- Lane Init SM Interface

                    DO_WORD_ALIGN    => do_word_align_i,
                    RX_SP            => rx_sp_i,
                    RX_SPA           => rx_spa_i,
                    RX_NEG           => rx_neg_i,

        -- Global Logic Interface

                    GOT_A            => GOT_A_Buffer,
                    GOT_V            => GOT_V_Buffer,

        -- V5 Interface

                    RX_DATA          => rx_data_r,
                    RX_CHAR_IS_K     => rx_char_is_k_r,
                    RX_CHAR_IS_COMMA => rx_char_is_comma_r,
                    RX_CC            => rx_cc_i,

        -- System Interface

                    USER_CLK         => USER_CLK,
                    RESET            => RESET

                 );


    -- Error Detection module

    rx_err_detect_simplex_gtp_i : aurora_rx_4l_64b_RX_ERR_DETECT_SIMPLEX_V5

        port map (

        -- Lane Init SM Interface

                    ENABLE_ERR_DETECT => enable_err_detect_i,
                    HARD_ERR_RESET    => hard_err_reset_i,

        -- Global Logic Interface

                    SOFT_ERR          => SOFT_ERR_Buffer,
                    HARD_ERR          => HARD_ERR_Buffer,

        -- V5 Interface

                    RX_DISP_ERR         => rx_disp_err_r,
                    RX_NOT_IN_TABLE     => rx_not_in_table_r,
                    RX_BUF_ERR          => RX_BUF_ERR,
                    RX_REALIGN          => RX_REALIGN,

      -- System Interface

                    USER_CLK            => USER_CLK

                 );

    -- Hot Plug module
    aurora_rx_4l_64b_hotplug_i : aurora_rx_4l_64b_HOTPLUG
    generic map
    (
       EXAMPLE_SIMULATION   => EXAMPLE_SIMULATION
    )
    port map
    (
        -- Sym Dec Interface
        RX_CC               => rx_cc_i,
        RX_SP               => rx_sp_i,
        RX_SPA              => rx_spa_i,

        -- GT Wrapper Interface
        LINK_RESET_OUT      => LINK_RESET_OUT,
        HPCNT_RESET         => HPCNT_RESET,

        -- System Interface
	     INIT_CLK            => INIT_CLK,
        USER_CLK            => USER_CLK,
        RESET               => RESET
    );



end MAPPED;
