--******************************************************************************
--* @short   Input FPGA (BRPC version)
--******************************************************************************
--* @author  SAKULIN Hannes  <hsakulin@dsy-srv3.cern.ch>
--* @date    $Date: 2004/12/17 11:24:27 $
--* @version $Revision: 1.10 $
--******************************************************************************
--/
library IEEE;
use IEEE.Std_logic_1164.all;
use WORK.GMTTypes.all;
use WORK.ReadOutBufTypes.all;
use WORK.VMEMux.all;
use WORK.IFVMEAddrMap.all;

-- pragma translate_off
library UNISIM;
use UNISIM.VCOMPONENTS.all;
-- pragma translate_on
use IEEE.NUMERIC_STD.all;

entity InputFPGAbrpc is
  port (
    -- CHIP INPUTS    
    bRPCMu : in TFourInMuons_flat;

    -- out to Logic FPGA and to MIPISO AU
    bRPCMu_LF : out TFourSyncedMu_flat;
    bRPCMu_AU : out TFourSyncedMu_flat;

    -- VME port
    vme_addr       : in    std_logic_vector(19 downto 1);
    vme_data       : inout std_logic_vector(15 downto 0);
    vme_en_INB     : in    std_logic;
    vme_wr_INB     : in    std_logic;
    vme_ndtack_INB : out   std_logic;   -- low active 
    vme_nirq_INB   : out   std_logic;   -- low active 

    -- Readout Data Port
    ro_data_INB    : out std_logic_vector(23 downto 0);
    ro_rdfifo_INB  : in std_logic;
    ro_fetch_INB   : in std_logic;
    l1a_INB        : in std_logic;          -- Level-1 accept
    bcreset_INB    : in std_logic;          -- Bunch Counter reset
    l1reset_INB    : in std_logic;          -- Level-1 reset

    -- Clock and control
    clk_INB        : in  std_logic;
    clk_test_INB   : out std_logic;     -- clock1x from DCM
    clk_out_INB    : out std_logic;     -- clock output for feedback (use optional)
                                        -- same as clk_test
    clk_fb_INB     : in  std_logic;     -- clock feedback input (use optional)
    dcm_locked_INB : out std_logic;     -- DCM is locked => goes to VME chip
    reset_dcm      : in  std_logic;     -- resets DCM
    inactive       : in  std_logic;     -- from front panel button (to GTS)

    status_INB     : out std_logic_vector(1 downto 0);
    test_lemo_INB  : out std_logic;
    test_INB       : out std_logic_vector(3 downto 0);
    reset_INB      : in  std_logic;     -- hard reset from trigger control
                                        --
                                        -- register input
                                        -- same function as level-1 reset
                                        -- or hard reset from trigger control
                                        --
                                        -- generated by VME chip
                                        -- resets only state machines, FFs,
                                        -- counters, error flags
                                        -- but not memories and registers

    test_lemo_clk  : out std_logic;
    
    dummyb_INB : in std_logic);
end;


architecture behavioral of InputFPGAbrpc is

  signal bRPCPhiCOU_dummy : TPhi_vec(0 to 3);
  signal bRPCEtaCOU_dummy : TEtaCOU_vec(0 to 3);
  attribute syn_useioff               : boolean;
  attribute syn_useioff of behavioral : architecture is true;

  signal test_clk : std_logic;
  
begin
  theChip: entity work.InputFPGA
    generic map (
      input_fpga_idx => 2)                --BRPC
    port map (
      iMuons     => bRPCMu,
      oMuonsLF   => bRPCmu_LF,
      oMuonsAU   => bRPCmu_AU,
      
      oPhi       => bRPCPhiCOU_dummy,
      oEta       => bRPCEtaCOU_dummy,
      
      vme_addr   => vme_addr,
      vme_data   => vme_data,
      vme_en     => vme_en_INB,
      vme_wr     => vme_wr_INB,
      vme_ndtack => vme_ndtack_INB,
      vme_nirq   => vme_nirq_INB,

      ro_data    => ro_data_INB,
      ro_rdfifo  => ro_rdfifo_INB,       
      ro_fetch   => ro_fetch_INB,
      l1a        => l1a_INB,
      bcreset    => bcreset_INB,
      l1reset    => l1reset_INB,   

      clk_input  => clk_INB,
      clk_test   => test_clk,
      clk_out    => clk_out_INB,
      clk_fb     => clk_fb_INB,
      dcm_locked => dcm_locked_INB,
      reset_dcm        => reset_dcm,
      inactive   => inactive,
      status     => status_INB,
      test_lemo  => test_lemo_INB,
      test       => test_INB,
      reset_input=> reset_INB,
      dummyb     => dummyb_INB);

  clk_test_INB  <= test_clk;
  test_lemo_clk <= test_clk;
end architecture behavioral;