[use]
use work.tdc_core_pkg.all;
[ports]
    ---------------------------------------------------------------------------
    -- FMC slot {n} pins (TDC mezzanine)
    ---------------------------------------------------------------------------

    -- TDC1 PLL AD9516 and DAC AD5662 interface
    fmc{n}_tdc_pll_sclk_o       : out std_logic;
    fmc{n}_tdc_pll_sdi_o        : out std_logic;
    fmc{n}_tdc_pll_cs_n_o       : out std_logic;
    fmc{n}_tdc_pll_dac_sync_n_o : out std_logic;
    fmc{n}_tdc_pll_sdo_i        : in  std_logic;
    fmc{n}_tdc_pll_status_i     : in  std_logic;
    fmc{n}_tdc_125m_clk_p_i     : in  std_logic;
    fmc{n}_tdc_125m_clk_n_i     : in  std_logic;
    fmc{n}_tdc_acam_refclk_p_i  : in  std_logic;
    fmc{n}_tdc_acam_refclk_n_i  : in  std_logic;

    -- TDC1 ACAM timing interface
    fmc{n}_tdc_start_from_fpga_o : out std_logic;
    fmc{n}_tdc_err_flag_i        : in  std_logic;
    fmc{n}_tdc_int_flag_i        : in  std_logic;
    fmc{n}_tdc_start_dis_o       : out std_logic;
    fmc{n}_tdc_stop_dis_o        : out std_logic;

    -- TDC1 ACAM data interface
    fmc{n}_tdc_data_bus_io : inout std_logic_vector(27 downto 0);
    fmc{n}_tdc_address_o   : out   std_logic_vector(3 downto 0);
    fmc{n}_tdc_cs_n_o      : out   std_logic;
    fmc{n}_tdc_oe_n_o      : out   std_logic;
    fmc{n}_tdc_rd_n_o      : out   std_logic;
    fmc{n}_tdc_wr_n_o      : out   std_logic;
    fmc{n}_tdc_ef1_i       : in    std_logic;
    fmc{n}_tdc_ef2_i       : in    std_logic;

    -- TDC1 Input Logic
    fmc{n}_tdc_enable_inputs_o : out std_logic;
    fmc{n}_tdc_term_en_1_o     : out std_logic;
    fmc{n}_tdc_term_en_2_o     : out std_logic;
    fmc{n}_tdc_term_en_3_o     : out std_logic;
    fmc{n}_tdc_term_en_4_o     : out std_logic;
    fmc{n}_tdc_term_en_5_o     : out std_logic;

    -- TDC1 1-wire UniqueID & Thermometer
    fmc{n}_tdc_onewire_b : inout std_logic;

    -- TDC1 EEPROM I2C
    fmc{n}_tdc_scl_b : inout std_logic;
    fmc{n}_tdc_sda_b : inout std_logic;

    -- TDC1 LEDs
    fmc{n}_tdc_led_status_o : out std_logic;
    fmc{n}_tdc_led_trig1_o  : out std_logic;
    fmc{n}_tdc_led_trig2_o  : out std_logic;
    fmc{n}_tdc_led_trig3_o  : out std_logic;
    fmc{n}_tdc_led_trig4_o  : out std_logic;
    fmc{n}_tdc_led_trig5_o  : out std_logic;

    -- TDC1 Input channels
    -- also arriving to the FPGA (not used for the moment)
    fmc{n}_tdc_in_fpga_1_i : in std_logic;
    fmc{n}_tdc_in_fpga_2_i : in std_logic;
    fmc{n}_tdc_in_fpga_3_i : in std_logic;
    fmc{n}_tdc_in_fpga_4_i : in std_logic;
    fmc{n}_tdc_in_fpga_5_i : in std_logic;
[sdb-decl]
  constant c_tdc{n}_bridge_sdb : t_sdb_bridge :=
    f_xwb_bridge_manual_sdb(x"00007FFF", x"00000000");

[sdb-layout]
    c_WB_SLAVE_FMC{n} => f_sdb_embed_bridge(c_tdc{n}_bridge_sdb, x"{addr}"),
[body]
  -----------------------------------------------------------------------------
  -- FMC TDC (SVEC slot #{n})
  -----------------------------------------------------------------------------

  U_TDC_Core : fmc_tdc_wrapper
    generic map (
      g_simulation          => f_int2bool(g_simulation),
      g_with_direct_readout => TRUE)
    port map (
      clk_sys_i            => clk_sys_62m5,
      rst_sys_n_i          => rst_sys_62m5_n,
      rst_n_a_i            => rst_sys_62m5_n,
      pll_sclk_o           => fmc{n}_tdc_pll_sclk_o,
      pll_sdi_o            => fmc{n}_tdc_pll_sdi_o,
      pll_cs_o             => fmc{n}_tdc_pll_cs_n_o,
      pll_dac_sync_o       => fmc{n}_tdc_pll_dac_sync_n_o,
      pll_sdo_i            => fmc{n}_tdc_pll_sdo_i,
      pll_status_i         => fmc{n}_tdc_pll_status_i,
      tdc_clk_125m_p_i     => fmc{n}_tdc_125m_clk_p_i,
      tdc_clk_125m_n_i     => fmc{n}_tdc_125m_clk_n_i,
      acam_refclk_p_i      => fmc{n}_tdc_acam_refclk_p_i,
      acam_refclk_n_i      => fmc{n}_tdc_acam_refclk_n_i,
      start_from_fpga_o    => fmc{n}_tdc_start_from_fpga_o,
      err_flag_i           => fmc{n}_tdc_err_flag_i,
      int_flag_i           => fmc{n}_tdc_int_flag_i,
      start_dis_o          => fmc{n}_tdc_start_dis_o,
      stop_dis_o           => fmc{n}_tdc_stop_dis_o,
      data_bus_io          => fmc{n}_tdc_data_bus_io,
      address_o            => fmc{n}_tdc_address_o,
      cs_n_o               => fmc{n}_tdc_cs_n_o,
      oe_n_o               => fmc{n}_tdc_oe_n_o,
      rd_n_o               => fmc{n}_tdc_rd_n_o,
      wr_n_o               => fmc{n}_tdc_wr_n_o,
      ef1_i                => fmc{n}_tdc_ef1_i,
      ef2_i                => fmc{n}_tdc_ef2_i,
      enable_inputs_o      => fmc{n}_tdc_enable_inputs_o,
      term_en_1_o          => fmc{n}_tdc_term_en_1_o,
      term_en_2_o          => fmc{n}_tdc_term_en_2_o,
      term_en_3_o          => fmc{n}_tdc_term_en_3_o,
      term_en_4_o          => fmc{n}_tdc_term_en_4_o,
      term_en_5_o          => fmc{n}_tdc_term_en_5_o,
      tdc_led_status_o     => fmc{n}_tdc_led_status_o,
      tdc_led_trig1_o      => fmc{n}_tdc_led_trig1_o,
      tdc_led_trig2_o      => fmc{n}_tdc_led_trig2_o,
      tdc_led_trig3_o      => fmc{n}_tdc_led_trig3_o,
      tdc_led_trig4_o      => fmc{n}_tdc_led_trig4_o,
      tdc_led_trig5_o      => fmc{n}_tdc_led_trig5_o,
      tdc_in_fpga_1_i      => fmc{n}_tdc_in_fpga_1_i,
      tdc_in_fpga_2_i      => fmc{n}_tdc_in_fpga_2_i,
      tdc_in_fpga_3_i      => fmc{n}_tdc_in_fpga_3_i,
      tdc_in_fpga_4_i      => fmc{n}_tdc_in_fpga_4_i,
      tdc_in_fpga_5_i      => fmc{n}_tdc_in_fpga_5_i,
      mezz_scl_i           => fmc{n}_scl_b,
      mezz_sda_i           => fmc{n}_sda_b,
      mezz_scl_o           => fmc{n}_scl_out,
      mezz_sda_o           => fmc{n}_sda_out,
      mezz_one_wire_b      => fmc{n}_tdc_onewire_b,
      tm_link_up_i         => tm_link_up,
      tm_time_valid_i      => tm_time_valid,
      tm_cycles_i          => tm_cycles,
      tm_tai_i             => tm_tai,
      tm_clk_aux_lock_en_o => tm_clk_aux_lock_en({n}),
      tm_clk_aux_locked_i  => tm_clk_aux_locked({n}),
      tm_clk_dmtd_locked_i => '1',
      tm_dac_value_i       => tm_dac_value,
      tm_dac_wr_i          => tm_dac_wr({n}),
      direct_slave_i       => fmc_dp_wb_out({n}),
      direct_slave_o       => fmc_dp_wb_in({n}),
      slave_i              => cnx_slave_in(c_WB_SLAVE_FMC{n}),
      slave_o              => cnx_slave_out(c_WB_SLAVE_FMC{n}),
      irq_o                => fmc_host_irq({n}),
      clk_125m_tdc_o       => fmc{n}_clk_125m);
