Commit b440cee9 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Maciej Lipinski

wr_streamers: hopefully fixed all bugs in fixed_latency_ts_match...

parent 6a180959
...@@ -214,7 +214,7 @@ begin ...@@ -214,7 +214,7 @@ begin
tm_tai_i => tm_tai_i, tm_tai_i => tm_tai_i,
tm_cycles_i => tm_cycles_i, tm_cycles_i => tm_cycles_i,
match_o => delay_match, match_o => delay_match,
miss_o => delay_miss); late_o => delay_miss);
p_fsm_comb: process(state, rx_dreq_i, fifo_empty, delay_miss, fifo_last, delay_match, fifo_target_ts_en, fifo_valid) p_fsm_comb: process(state, rx_dreq_i, fifo_empty, delay_miss, fifo_last, delay_match, fifo_target_ts_en, fifo_valid)
begin begin
......
...@@ -29,17 +29,26 @@ entity fixed_latency_ts_match is ...@@ -29,17 +29,26 @@ entity fixed_latency_ts_match is
match_o : out std_logic; match_o : out std_logic;
miss_o : out std_logic late_o : out std_logic
); );
end entity; end entity;
architecture rtl of fixed_latency_ts_match is architecture rtl of fixed_latency_ts_match is
type t_state is (IDLE, WRAP_ADJ_TS, CHECK_LATE, WAIT_TRIG);
impure function f_cycles_counter_range return integer is impure function f_cycles_counter_range return integer is
begin begin
if g_simulation = 1 then if g_simulation = 1 then
return g_sim_cycle_counter_range; if g_clk_ref_rate = 62500000 then
return 2*g_sim_cycle_counter_range;
else
return g_sim_cycle_counter_range;
end if;
else else
return 125000000; return 125000000;
end if; end if;
...@@ -47,16 +56,18 @@ architecture rtl of fixed_latency_ts_match is ...@@ -47,16 +56,18 @@ architecture rtl of fixed_latency_ts_match is
constant c_rollover_threshold_lo : integer := f_cycles_counter_range / 4; constant c_rollover_threshold_lo : integer := f_cycles_counter_range / 4;
constant c_rollover_threshold_hi : integer := f_cycles_counter_range * 3 / 4; constant c_rollover_threshold_hi : integer := f_cycles_counter_range * 3 / 4;
signal ts_adjusted : unsigned(28 downto 0); signal ts_adjusted : unsigned(28 downto 0);
signal target_cycles : unsigned(28 downto 0);
signal arm_d : std_logic_vector(2 downto 0);
signal armed : std_logic; signal armed : std_logic;
signal tm_cycles_scaled : unsigned(28 downto 0); signal tm_cycles_scaled : unsigned(28 downto 0);
signal ts_latency_scaled : unsigned(28 downto 0); signal ts_latency_scaled : unsigned(28 downto 0);
signal match : std_logic;
signal state : t_state;
signal ts_adj_next_cycle, roll_lo, roll_hi : std_logic;
begin begin
process(tm_cycles_i, ts_latency_i) process(tm_cycles_i, ts_latency_i)
...@@ -71,52 +82,80 @@ begin ...@@ -71,52 +82,80 @@ begin
report "Unsupported g_clk_ref_rate (62.5 / 125 MHz)" severity failure; report "Unsupported g_clk_ref_rate (62.5 / 125 MHz)" severity failure;
end if; end if;
end process; end process;
process(clk_i) process(clk_i)
begin begin
if rising_edge(clk_i) then if rising_edge(clk_i) then
if rst_n_i = '0' then if rst_n_i = '0' then
armed <= '0'; armed <= '0';
arm_d <= (others => '0'); late_o <= '0';
miss_o <= '0'; match <= '0';
State <= IDLE;
else else
arm_d <= arm_d(1 downto 0) & arm_i;
case State is
if arm_i = '1' then when IDLE =>
match_o <= '0'; match <= '0';
miss_o <= '0'; late_o <= '0';
ts_adjusted <= resize(unsigned(ts_origin_i) + unsigned(ts_latency_i), 29); armed <= '0';
end if;
if arm_i = '1' then
if ts_adjusted < c_rollover_threshold_lo and tm_cycles_scaled > c_rollover_threshold_hi then ts_adjusted <= resize(unsigned(ts_origin_i) + unsigned(ts_latency_i), 29);
target_cycles <= tm_cycles_scaled + f_cycles_counter_range; State <= WRAP_ADJ_TS;
if arm_d(0) = '1' then armed <= '1';
ts_adjusted <= ts_adjusted + f_cycles_counter_range; end if;
end if;
when WRAP_ADJ_TS =>
else
target_cycles <= tm_cycles_scaled; ts_adj_next_cycle <= '0';
end if; roll_lo <= '0';
roll_hi <= '0';
if (arm_d(1) = '1') then
if ts_adjusted < target_cycles then if ts_adjusted >= f_cycles_counter_range then
miss_o <= '1'; ts_adj_next_cycle <= '1';
else ts_adjusted <= ts_adjusted - f_cycles_counter_range;
armed <= '1'; end if;
end if;
end if; if ts_adjusted < c_rollover_threshold_lo then
roll_lo <= '1';
if armed = '1' and ts_adjusted = tm_cycles_scaled then end if;
match_o <= '1';
armed <= '0'; if tm_cycles_scaled > c_rollover_threshold_hi then
else roll_hi <= '1';
match_o <= '0'; end if;
end if;
State <= CHECK_LATE;
when CHECK_LATE =>
if roll_lo = '1' and roll_hi = '1' then
if ts_adj_next_cycle = '0' then
late_o <= '1';
State <= IDLE;
else
State <= WAIT_TRIG;
end if;
else
State <= WAIT_TRIG;
end if;
when WAIT_TRIG =>
if ts_adjusted = tm_cycles_scaled then
match <= '1';
State <= IDLE;
end if;
end case;
end if; end if;
end if; end if;
end process; end process;
match_o <= match;
end rtl; end rtl;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment