architecture handler_ipu_arch of handler_ipu is
type cnt10_DAT_t is array (DATA_INTERFACE_NUMBER-1 downto 0) of unsigned(15 downto 0);
- type fsm_state_t is (IDLE, WAIT_FOR_LENGTH, WAITING_FOR_EVENT, SEND_DHDR, READ_DATA, END_READOUT);
+ type fsm_state_t is (IDLE, WAIT_FOR_LENGTH, SEND_DHDR, READ_DATA, END_READOUT, SEND_FAIL);
signal current_state, next_state : fsm_state_t;
signal state_bits : std_logic_vector(3 downto 0);
signal error_sync : std_logic;
signal error_missing, next_error_missing : std_logic;
signal error_not_configured : std_logic;
- signal lvl1_fifo_read, next_lvl1_fifo_read : std_logic;
signal hdr_fifo_read, next_hdr_fifo_read : std_logic;
signal hdr_fifo_valid_read, next_hdr_fifo_valid_read : std_logic;
signal last_hdr_fifo_valid_read : std_logic;
signal first_fifo_read, next_first_fifo_read : std_logic;
+ signal hdr_data_waiting, next_hdr_data_waiting : std_logic;
signal dat_fifo_read : std_logic_vector(DATA_INTERFACE_NUMBER-1 downto 0);
signal dat_fifo_select, next_dat_fifo_select : std_logic_vector(DATA_INTERFACE_NUMBER-1 downto 0);
if rising_edge(CLOCK) then
if RESET = '1' then
current_state <= IDLE;
- lvl1_fifo_read <= '0';
hdr_fifo_read <= '0';
+ hdr_data_waiting <= '0';
else
current_state <= next_state;
error_not_found <= next_error_not_found;
error_missing <= next_error_missing;
error_lvl1 <= next_error_lvl1;
- lvl1_fifo_read <= next_lvl1_fifo_read;
hdr_fifo_read <= next_hdr_fifo_read;
ipu_finished_i <= next_ipu_finished_i;
ipu_dataready_i <= next_ipu_dataready_i;
first_fifo_read <= next_first_fifo_read;
dat_fifo_number <= next_dat_fifo_number;
suppress_output <= next_suppress_output;
+ hdr_data_waiting <= next_hdr_data_waiting;
end if;
end if;
end process;
THE_FSM : process(current_state, error_not_found, IPU_START_READOUT_IN, DAT_HDR_DATA_EMPTY_IN,
DAT_HDR_DATA_IN, last_hdr_fifo_valid_read, ipu_dataready_i, IPU_READ_IN,
error_missing, dat_fifo_valid_read, next_dat_fifo_number, error_lvl1,
- dat_fifo_finished, dat_fifo_number, DAT_DATA_IN, suppress_output)
+ dat_fifo_finished, dat_fifo_number, DAT_DATA_IN, suppress_output, hdr_data_waiting)
begin
next_state <= current_state;
next_error_not_found <= error_not_found;
next_error_missing <= error_missing;
next_error_lvl1 <= error_lvl1;
next_hdr_fifo_read <= '0';
- next_lvl1_fifo_read <= '0';
next_ipu_data_i <= (others => '0');
next_ipu_dataready_i <= '0';
next_ipu_finished_i <= '0';
case current_state is
when IDLE =>
if IPU_START_READOUT_IN = '1' then
- if DAT_HDR_DATA_EMPTY_IN = '0' then
+ if DAT_HDR_DATA_EMPTY_IN = '0' and hdr_data_waiting = '0' then
next_state <= WAIT_FOR_LENGTH;
- next_lvl1_fifo_read <= '1';
next_hdr_fifo_read <= '1';
+ elsif hdr_data_waiting = '1' then
+ next_state <= WAIT_FOR_LENGTH;
end if;
next_error_not_found <= '0';
next_error_missing <= '0';
end if;
when WAIT_FOR_LENGTH =>
- --missing: compare data flags and hdr fifo data
--- next_state <= GOT_LENGTH;
- if last_hdr_fifo_valid_read = '1' then
- next_state <= SEND_DHDR;
- next_suppress_output <= DAT_HDR_DATA_IN(28);
- next_error_lvl1 <= DAT_HDR_DATA_IN(29);
- next_error_missing <= DAT_HDR_DATA_IN(30);
- end if;
-
--- when GOT_LENGTH =>
-
-
+ if last_hdr_fifo_valid_read = '1' or hdr_data_waiting = '1' then
+ if DAT_HDR_DATA_IN(15 downto 0) = IPU_NUMBER_IN then
+ next_state <= SEND_DHDR;
+ next_suppress_output <= DAT_HDR_DATA_IN(28);
+ next_error_lvl1 <= DAT_HDR_DATA_IN(29);
+ next_error_missing <= DAT_HDR_DATA_IN(30);
+ next_hdr_data_waiting<= '0';
+ else
+ next_state <= SEND_FAIL;
+ next_error_not_found <= '1';
+ next_hdr_data_waiting <= '1';
+ end if;
+ end if;
when SEND_DHDR =>
next_ipu_data_i <= x"0" & DAT_HDR_DATA_IN(27 downto 0);
next_ipu_dataready_i <= (dat_fifo_valid_read or (ipu_dataready_i and not IPU_READ_IN));
next_ipu_data_i <= DAT_DATA_IN(dat_fifo_number*32+31 downto dat_fifo_number*32);
-
+ when SEND_FAIL =>
+ next_ipu_dataready_i <= '1';
+ next_ipu_data_i <= x"0" & DAT_HDR_DATA_IN(27 downto 0);
+ if ipu_dataready_i = '1' and IPU_READ_IN = '1' then
+ next_ipu_dataready_i <= '0';
+ next_state <= END_READOUT;
+ end if;
+
when END_READOUT =>
next_ipu_finished_i <= '1';
if IPU_START_READOUT_IN = '0' then
next_state <= IDLE;
end if;
- when WAITING_FOR_EVENT =>
- --CTS request came, but no data in Fifo yet
- next_error_not_found <= '1';
end case;
end process;
next_hdr_fifo_valid_read <= hdr_fifo_read and not DAT_HDR_DATA_EMPTY_IN;
hdr_fifo_valid_read <= next_hdr_fifo_valid_read;
last_hdr_fifo_valid_read <= hdr_fifo_valid_read;
- if last_hdr_fifo_valid_read = '1' then
+ if next_hdr_data_waiting = '1' then
+ total_length <= 0;
+ elsif last_hdr_fifo_valid_read = '1' then
total_length <= next_total_length;
end if;
end if;
STATUS_OUT(31 downto 24) <= (others => '0');
-end architecture;
\ No newline at end of file
+end architecture;