signal readout_rx : READOUT_RX;
signal readout_tx : readout_tx_array_t(0 to 0);
- signal ctrlbus_rx, bussci_rx, bustools_rx, bustc_rx, bus_master_out : CTRLBUS_RX;
- signal ctrlbus_tx, bussci_tx, bustools_tx, bustc_tx, bus_master_in : CTRLBUS_TX;
+ signal ctrlbus_rx, bussci_rx, bustools_rx, bustc_rx, busrdo_rx, bus_master_out : CTRLBUS_RX;
+ signal ctrlbus_tx, bussci_tx, bustools_tx, bustc_tx, busrdo_tx, bus_master_in : CTRLBUS_TX;
signal common_stat_reg : std_logic_vector(std_COMSTATREG*32-1 downto 0) := (others => '0');
signal common_ctrl_reg : std_logic_vector(std_COMCTRLREG*32-1 downto 0);
attribute syn_preserve of bustools_rx : signal is true;
attribute syn_keep of bustc_rx : signal is true;
attribute syn_preserve of bustc_rx : signal is true;
-
+
+ type state_t is (IDLE, WRITE, FINISH, BUSYEND);
+ signal state : state_t;
+ signal data_counter, data_amount : unsigned(15 downto 0) := (others => '0');
+
+
begin
---------------------------------------------------------------------------
IS_SYNC_SLAVE => c_YES
)
port map(
- CLK_REF_FULL => med2int(0).clk_full,
+ CLK_REF_FULL => clk_full_osc, --med2int(0).clk_full,
CLK_INTERNAL_FULL => clk_full_osc,
SYSCLK => clk_sys,
RESET => reset_i,
TIMING_TRIGGER_RAW => c_YES,
--Configure data handler
DATA_INTERFACE_NUMBER => 1,
- DATA_BUFFER_DEPTH => 10,
+ DATA_BUFFER_DEPTH => 13,
DATA_BUFFER_WIDTH => 32,
- DATA_BUFFER_FULL_THRESH => 2**8,
+ DATA_BUFFER_FULL_THRESH => 2**12+2**11,
TRG_RELEASE_AFTER_DATA => c_YES,
HEADER_BUFFER_DEPTH => 9,
HEADER_BUFFER_FULL_THRESH => 2**8
THE_BUS_HANDLER : entity work.trb_net16_regio_bus_handler_record
generic map(
- PORT_NUMBER => 3,
- PORT_ADDRESSES => (0 => x"d000", 1 => x"b000", 2 => x"d300", others => x"0000"),
- PORT_ADDR_MASK => (0 => 12, 1 => 9, 2 => 1, others => 0),
+ PORT_NUMBER => 4,
+ PORT_ADDRESSES => (0 => x"d000", 1 => x"b000", 2 => x"d300", 3 => x"a000", others => x"0000"),
+ PORT_ADDR_MASK => (0 => 12, 1 => 9, 2 => 1, 3 => 12, others => 0),
PORT_MASK_ENABLE => 1
)
port map(
BUS_RX(0) => bustools_rx, --Flash, SPI, UART, ADC, SED
BUS_RX(1) => bussci_rx, --SCI Serdes
BUS_RX(2) => bustc_rx, --Clock switch
+ BUS_RX(3) => busrdo_rx, --User config
BUS_TX(0) => bustools_tx,
BUS_TX(1) => bussci_tx,
BUS_TX(2) => bustc_tx,
+ BUS_TX(3) => busrdo_tx,
STAT_DEBUG => open
);
ADC_MISO => ADC_DOUT,
ADC_CLK => ADC_CLK,
--Trigger & Monitor
- MONITOR_INPUTS => (others => '0'),
- TRIG_GEN_INPUTS => (others => '0'),
- TRIG_GEN_OUTPUTS => open,
+ MONITOR_INPUTS => KEL(32 downto 1),--(others => '0'),
+ TRIG_GEN_INPUTS => KEL(32 downto 1),--(others => '0'),
+ TRIG_GEN_OUTPUTS => BACK_GPIO(3 downto 1),--open,
--SED
SED_ERROR_OUT => sed_error_i,
--Slowcontrol
RJ_IO <= "0000";
- BACK_GPIO <= (others => 'Z');
+-- BACK_GPIO <= (others => 'Z');
BACK_LVDS <= (others => '0');
BACK_3V3 <= (others => 'Z');
end process;
-- TEST_LINE <= med_stat_debug(15 downto 0);
+ TEST_LINE(15 downto 0) <= debug_clock_reset(15 downto 14) & med2int(0).stat_op(13) & clear_i & reset_i & debug_clock_reset(10 downto 0);
-
-readout_tx(0).data_finished <= '1';
-readout_tx(0).data_write <= '0';
-readout_tx(0).busy_release <= '1';
-
+-- readout_tx(0).data_finished <= '1';
+-- readout_tx(0).data_write <= '0';
+-- readout_tx(0).busy_release <= '1';
+--
-- gen_chains : for i in 1 to 16 generate
-- process begin
--
-- end generate;
+
+THE_RDO_STAT : process begin
+ wait until rising_edge(clk_sys);
+ busrdo_tx.ack <= '0';
+ busrdo_tx.nack <= '0';
+ busrdo_tx.unknown <= '0';
+
+ if busrdo_rx.write = '1' then
+ if busrdo_rx.addr = x"0000" then
+ busrdo_tx.ack <= '1';
+ data_amount <= unsigned(busrdo_rx.data(15 downto 0));
+ else
+ busrdo_tx.unknown <= '1';
+ end if;
+ elsif busrdo_rx.read = '1' then
+ if busrdo_rx.addr = x"0000" then
+ busrdo_tx.ack <= '1';
+ busrdo_tx.data(15 downto 0) <= std_logic_vector(data_amount);
+ else
+ busrdo_tx.unknown <= '1';
+ end if;
+ end if;
+end process;
+
+THE_RDO : process begin
+ wait until rising_edge(clk_sys);
+ readout_tx(0).busy_release <= '0';
+ readout_tx(0).data_write <= '0';
+ readout_tx(0).data_finished <= '0';
+
+ case state is
+ when IDLE =>
+ if readout_rx.valid_timing_trg = '1' or readout_rx.valid_notiming_trg = '1' then
+ state <= WRITE;
+ end if;
+ if readout_rx.invalid_trg = '1' then
+ state <= FINISH;
+ end if;
+ data_counter <= 0;
+ when WRITE =>
+ readout_tx(0).data <= timer.microsecond;
+ readout_tx(0).data_write <= '1';
+ data_counter <= data_counter + 1;
+ if data_counter = data_amount then
+ state <= FINISH;
+ end if;
+ when FINISH =>
+ state <= BUSYEND;
+ readout_tx(0).data_finished <= '1';
+ when BUSYEND =>
+ state <= IDLE;
+ readout_tx(0).busy_release <= '1';
+ end case;
+end process;
end architecture;