SMB-362 Modified pof_tx_0.vhd to fix the sending of init messages when register toggled too slowly

This commit is contained in:
Damian Smith 2021-05-28 13:30:32 +01:00
commit dd7a69b95b

View file

@ -30,7 +30,7 @@ entity pof_tx_0 is
abs_position : in std_logic_vector(31 downto 0);
tx_data : out std_logic;
-- Avalon MM Interface
avs_address : in std_logic_vector( 2 downto 0);
avs_address : in std_logic_vector(2 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
@ -40,10 +40,10 @@ end entity pof_tx_0;
architecture rtl of pof_tx_0 is
constant CSR : std_logic_vector( 2 downto 0) := b"000";
constant ERROR_INJ_REG : std_logic_vector( 2 downto 0) := b"001";
constant TIMING_REG : std_logic_vector( 2 downto 0) := b"010";
constant FIFO_LEVEL_REG : std_logic_vector( 2 downto 0) := b"011";
constant CSR : std_logic_vector(2 downto 0) := b"000";
constant ERROR_INJ_REG : std_logic_vector(2 downto 0) := b"001";
constant TIMING_REG : std_logic_vector(2 downto 0) := b"010";
constant FIFO_LEVEL_REG : std_logic_vector(2 downto 0) := b"011";
constant KEEPALIVE_PERIOD_DEF : integer := 100;
constant INIT_BLOCKED_PERIOD_DEF : integer := 200;
@ -51,45 +51,45 @@ architecture rtl of pof_tx_0 is
function odd_parity(data : std_logic_vector) return std_logic is
variable parity_bit : std_logic := '1';
begin
for n in 0 to data'length-1 loop
for n in 0 to data'length - 1 loop
parity_bit := parity_bit xor data(n);
end loop; -- n
end loop; -- n
return parity_bit;
end function odd_parity;
function bin2gray(bin : std_logic_vector) return std_logic_vector is
variable gray : std_logic_vector(bin'range);
begin
gray := bin xor ('0' & bin(bin'length-1 downto 1));
gray := bin xor ('0' & bin(bin'length - 1 downto 1));
return gray;
end function bin2gray;
signal rd_event, wr_event, empty, full, tx_ready : std_logic;
signal rd_event_d, wr_event_i, symbol_valid : std_logic;
signal enable, toggle_sync, toggle_pd : std_logic;
signal add_keepalive, ovfl_err, init_d, init_gen : std_logic;
signal clear, pd_in_d, pd_gen, parity_bit : std_logic;
signal inject_error, inject_error_req : std_logic;
signal pd_event, pd_event_d, pd_event_dd : std_logic;
signal init_blocked, pd_event_ddd, delayed_pos : std_logic;
signal clr_fifo_lmax : std_logic;
signal rd_event, wr_event, empty, full, tx_ready : std_logic;
signal rd_event_d, wr_event_i, symbol_valid : std_logic;
signal enable, toggle_sync, toggle_pd : std_logic;
signal add_keepalive, ovfl_err, init_d, init_gen : std_logic;
signal clear, pd_in_d, pd_gen, parity_bit : std_logic;
signal inject_error, inject_error_req : std_logic;
signal pd_event, pd_event_d, pd_event_dd : std_logic;
signal init_blocked, pd_event_ddd, delayed_pos : std_logic;
signal clr_fifo_lmax : std_logic;
--
signal delayed_pos_v : std_logic_vector( 2 downto 0);
signal init_v, gray, bit_div : std_logic_vector( 3 downto 0);
signal latched_pos : std_logic_vector( 3 downto 0);
signal event_in_i : std_logic_vector( 6 downto 0);
signal event_in, event_out : std_logic_vector( 7 downto 0);
signal symbol : std_logic_vector( 7 downto 0);
signal init_blk_cnt : std_logic_vector( 9 downto 0) := (others => '0');
signal keepalive_cnt : std_logic_vector( 9 downto 0);
signal keepalive_period : std_logic_vector( 9 downto 0);
signal init_blocked_period : std_logic_vector( 9 downto 0);
signal fifo_level, fifo_level_max : std_logic_vector( 9 downto 0);
signal delayed_pos_v : std_logic_vector(2 downto 0);
signal init_v, gray, bit_div : std_logic_vector(3 downto 0);
signal latched_pos : std_logic_vector(3 downto 0);
signal event_in_i : std_logic_vector(6 downto 0);
signal event_in, event_out : std_logic_vector(7 downto 0);
signal symbol : std_logic_vector(7 downto 0);
signal init_blk_cnt : std_logic_vector(9 downto 0) := (others => '0');
signal keepalive_cnt : std_logic_vector(9 downto 0);
signal keepalive_period : std_logic_vector(9 downto 0);
signal init_blocked_period : std_logic_vector(9 downto 0);
signal fifo_level, fifo_level_max : std_logic_vector(9 downto 0);
begin
clear <= not enable or init_d;
clear <= (not enable) or init_d;
-----------------------------------------------------------------------------
-- Encode events and queue these in a FIFO
@ -97,60 +97,64 @@ begin
pEVENT_GEN : process(clk)
begin
if(clk = '1' and clk'event) then
if (clk = '1' and clk'event) then
init_d <= init;
if(init = '1' and init_d = '0' and init_blocked = '0') then
init_v <= "1100";
if (init = '0' and init_d = '1') then
-- set up int_v to create 2 packets with the new toggle_sync value when init set low
init_v <= "1100";
-- start timer so this doesn't get triggered again too soon
-- the local clear will still hapen as that depends on init_d
init_blk_cnt <= init_blocked_period;
else
init_v <= '0' & init_v(3 downto 1);
if (init_blocked = '1') then
init_blk_cnt <= std_logic_vector(unsigned(init_blk_cnt) - 1);
end if;
end if;
if(enable = '0') then
if (enable = '0') then
toggle_sync <= '0';
elsif(init_d = '1' and init_blocked = '0') then
elsif (init = '1' and init_d = '0' and init_blocked = '0') then
-- toggle the bit just when init set high.
toggle_sync <= not toggle_sync;
end if;
if(init_gen = '1') then
init_blk_cnt <= init_blocked_period;
elsif(init_blocked = '1') then
init_blk_cnt <= std_logic_vector(unsigned(init_blk_cnt)-1);
end if;
pd_in_d <= pd_in;
pd_in_d <= pd_in;
pd_event_d <= pd_event;
pd_event_dd <= pd_event_d;
pd_event_ddd <= pd_event_dd;
if(pd_event = '1') then
if (pd_event = '1') then
latched_pos <= abs_position(3 downto 0);
end if;
if((dec_pos = '1' or inc_pos = '1') and pd_gen = '1') then
if ((dec_pos = '1' or inc_pos = '1') and pd_gen = '1') then
delayed_pos_v <= "111";
else
delayed_pos_v <= '0' & delayed_pos_v(2 downto 1);
end if;
if(enable = '0') then
if (enable = '0') then
toggle_pd <= '0';
elsif(pd_event = '1') then
elsif (pd_event = '1') then
toggle_pd <= not toggle_pd;
end if;
wr_event <= wr_event_i or add_keepalive;
event_in <= parity_bit & event_in_i;
if(enable = '0' or wr_event_i = '1') then
wr_event <= wr_event_i or add_keepalive;
event_in <= parity_bit & event_in_i;
if (enable = '0' or wr_event_i = '1') then
keepalive_cnt <= keepalive_period;
else
keepalive_cnt <= std_logic_vector(unsigned(keepalive_cnt)-1);
keepalive_cnt <= std_logic_vector(unsigned(keepalive_cnt) - 1);
end if;
if(clear = '1') then
if (clear = '1') then
ovfl_err <= '0';
elsif(wr_event = '1' and full = '1') then
elsif (wr_event = '1' and full = '1') then
ovfl_err <= '1';
end if;
if(clear = '1' or wr_event = '1') then
if (clear = '1' or wr_event = '1') then
inject_error <= '0';
elsif(inject_error_req = '1') then
elsif (inject_error_req = '1') then
inject_error <= '1';
end if;
if(init_gen = '1' or clr_fifo_lmax = '1') then
if (clear = '1' or clr_fifo_lmax = '1') then
fifo_level_max <= (others => '0');
elsif(unsigned(fifo_level) > unsigned(fifo_level_max)) then
elsif (unsigned(fifo_level) > unsigned(fifo_level_max)) then
fifo_level_max <= fifo_level;
end if;
end if;
@ -160,16 +164,17 @@ begin
init_blocked <= '1' when unsigned(init_blk_cnt) /= 0 else '0';
pd_event <= pd_in and not pd_in_d;
pd_gen <= pd_event or pd_event_d or pd_event_dd;
pd_event <= pd_in and not pd_in_d;
pd_gen <= pd_event or pd_event_d or pd_event_dd;
delayed_pos <= delayed_pos_v(0) and pd_event_ddd;
-- FIXME init_gen does nothing here as clear will be high during this and the fifo will lose the two inserted packets.
wr_event_i <= enable and (init_gen or pd_gen or dec_pos or inc_pos or delayed_pos);
add_keepalive <= '1' when wr_event_i = '0' and unsigned(keepalive_cnt) = 0 else '0';
gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else bin2gray(abs_position(3 downto 0));
gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else bin2gray(abs_position(3 downto 0));
-- toggle_pd is repeated twice in the tx word, to improve resiliance against
-- double bit-flips errors
@ -178,10 +183,10 @@ gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else
parity_bit <= odd_parity(event_in_i) xor inject_error;
iQUEUE_EVENT : entity work.sync_fifo
generic map (
generic map(
FIFO_WIDTH => 8,
FIFO_DEPTH => 1024)
port map (
port map(
sclr => clear,
clock => clk,
data => event_in,
@ -195,23 +200,23 @@ gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else
-----------------------------------------------------------------------------
-- Transmit symbols over serial link
-----------------------------------------------------------------------------
pGET_EVENT : process(clk)
begin
if(clk = '1' and clk'event) then
if (clk = '1' and clk'event) then
rd_event_d <= rd_event;
symbol_valid <= rd_event_d;
end if;
end process pGET_EVENT;
rd_event <= '1' when tx_ready = '1' and empty = '0' and rd_event_d = '0' and symbol_valid = '0' else '0';
symbol <= event_out;
symbol <= event_out;
iTX_SYMBOL : entity work.uart_tx_0
generic map (
generic map(
data_width => 8)
port map (
port map(
reset_n => reset_n,
clk => clk,
bit_div => bit_div,
@ -227,36 +232,36 @@ gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else
pCTRL_STATUS : process(reset_n, clk)
begin
if(reset_n = '0') then
if (reset_n = '0') then
avs_readdatavalid <= '0';
enable <= '0';
clr_fifo_lmax <= '0';
bit_div <= "0010";
keepalive_period <= std_logic_vector(to_unsigned(KEEPALIVE_PERIOD_DEF, 10));
init_blocked_period <= std_logic_vector(to_unsigned(INIT_BLOCKED_PERIOD_DEF, 10));
elsif(clk = '1' and clk'event) then
inject_error_req <= '0';
clr_fifo_lmax <= '0';
elsif (clk = '1' and clk'event) then
inject_error_req <= '0';
clr_fifo_lmax <= '0';
-- CTRL registers
if(avs_write = '1') then
if (avs_write = '1') then
case avs_address is
when CSR =>
enable <= avs_writedata(0);
clr_fifo_lmax <= avs_writedata(2);
bit_div <= avs_writedata(7 downto 4);
when ERROR_INJ_REG =>
enable <= avs_writedata(0);
clr_fifo_lmax <= avs_writedata(2);
bit_div <= avs_writedata(7 downto 4);
when ERROR_INJ_REG =>
inject_error_req <= avs_writedata(0);
when TIMING_REG =>
keepalive_period <= avs_writedata( 9 downto 0);
keepalive_period <= avs_writedata(9 downto 0);
init_blocked_period <= avs_writedata(25 downto 16);
when others => null;
end case;
end if;
end if;
-- Read Ctrl & Status registers
avs_readdatavalid <= avs_read;
if(avs_read = '1') then
if (avs_read = '1') then
case avs_address is
when CSR =>
when CSR =>
avs_readdata <= X"000000" & bit_div & b"0" & clr_fifo_lmax & ovfl_err & enable;
when TIMING_REG =>
avs_readdata <= 6x"0" & init_blocked_period & 6x"0" & keepalive_period;
@ -268,5 +273,5 @@ gray <= bin2gray(latched_pos) when (pd_event_d = '1' or pd_event_dd = '1') else
end if;
end if;
end process pCTRL_STATUS;
end architecture rtl;