des: Improve header synchronization

This commit is contained in:
Markus Koch 2022-01-30 18:03:09 +01:00
parent 075f935e12
commit a5142f9abb

View File

@ -129,6 +129,8 @@ begin
-- Bit recovery -- Bit recovery
type demanchestization_state_t is (SYNC, DATA, ERROR); type demanchestization_state_t is (SYNC, DATA, ERROR);
signal demanchestization_state : demanchestization_state_t; signal demanchestization_state : demanchestization_state_t;
constant DEMANCHESTIZATION_MIN_SYNC_CNT_MAX : integer := (4 * 8) - 1; -- 4 good sync bytes
signal demanchestization_min_sync_cnt : integer range 0 to DEMANCHESTIZATION_MIN_SYNC_CNT_MAX;
begin begin
-- Detects spacing of transitions -- Detects spacing of transitions
transition_detector : process(clk, rst) is transition_detector : process(clk, rst) is
@ -204,18 +206,27 @@ begin
bit_stb <= '0'; bit_stb <= '0';
phy_out.rx_active <= '0'; phy_out.rx_active <= '0';
phy_out.rx_error <= '0'; phy_out.rx_error <= '0';
demanchestization_min_sync_cnt <= DEMANCHESTIZATION_MIN_SYNC_CNT_MAX;
elsif rising_edge(clk) then elsif rising_edge(clk) then
bit_stb <= '0'; bit_stb <= '0';
phy_out.rx_error <= '0'; phy_out.rx_error <= '0';
if (bit_ev = TOGGLE) and (demanchestization_min_sync_cnt /= 0) then
demanchestization_min_sync_cnt <= demanchestization_min_sync_cnt - 1;
elsif (bit_ev = KEEP) or (bit_ev = ERROR) then
demanchestization_min_sync_cnt <= DEMANCHESTIZATION_MIN_SYNC_CNT_MAX;
end if;
if (bit_ev /= NONE) then if (bit_ev /= NONE) then
case demanchestization_state is case demanchestization_state is
when SYNC => when SYNC =>
if (bit_ev = KEEP) then if (bit_ev = KEEP) then
if demanchestization_min_sync_cnt = 0 then
bit_value <= '1'; bit_value <= '1';
demanchestization_state <= DATA; demanchestization_state <= DATA;
phy_out.rx_active <= '1'; phy_out.rx_active <= '1';
end if; end if;
end if;
when DATA => -- @suppress: Condition outside of case allows to exit this state when DATA => -- @suppress: Condition outside of case allows to exit this state
bit_value <= not bit_value when bit_ev = TOGGLE else bit_value; bit_value <= not bit_value when bit_ev = TOGGLE else bit_value;
bit_stb <= '1'; bit_stb <= '1';
@ -225,7 +236,7 @@ begin
end if; end if;
if (bit_ev = ERROR) then if (bit_ev = ERROR) then
phy_out.rx_error <= '1'; phy_out.rx_error <= '1' when (demanchestization_state = DATA) else '0';
demanchestization_state <= ERROR; demanchestization_state <= ERROR;
end if; end if;