ELGIP-179 Minor changes of adding signals to reset block

This commit is contained in:
Damian Smith 2022-02-01 15:48:39 +00:00
commit 1eb030d368
7 changed files with 503 additions and 498 deletions

View file

@ -24,31 +24,31 @@ use ieee.numeric_std.all;
entity cs_bus_ift is
generic(
BLK_NUM : integer range 1 to 16 := 1;
READ_TIMEOUT : integer range 16 to 1023 := 64);
BLK_NUM : integer range 1 to 16 := 1;
READ_TIMEOUT : integer range 16 to 1023 := 64);
port(
rstN : in std_logic;
clk : in std_logic;
rstN : in std_logic;
clk : in std_logic;
-- Avalon-MM itf
avs_address : in std_logic_vector(14 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_waitrequest : out std_logic;
avs_readdata : out std_logic_vector(31 downto 0);
avs_address : in std_logic_vector(14 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_waitrequest : out std_logic;
avs_readdata : out std_logic_vector(31 downto 0);
-- C&S bus
cs_addr : out std_logic_vector(10 downto 0);
cs_we : out std_logic_vector(BLK_NUM-1 downto 0);
cs_wr_data : out std_logic_vector(31 downto 0);
cs_re : out std_logic_vector(BLK_NUM-1 downto 0);
cs_rv : in std_logic_vector(BLK_NUM-1 downto 0);
cs_rd_data : in std_logic_vector(32*BLK_NUM-1 downto 0));
cs_addr : out std_logic_vector(10 downto 0);
cs_we : out std_logic_vector(BLK_NUM - 1 downto 0);
cs_wr_data : out std_logic_vector(31 downto 0);
cs_re : out std_logic_vector(BLK_NUM - 1 downto 0);
cs_rv : in std_logic_vector(BLK_NUM - 1 downto 0);
cs_rd_data : in std_logic_vector(32 * BLK_NUM - 1 downto 0));
end cs_bus_ift;
architecture RTL of cs_bus_ift is
-- limit to 16 the maximum number of user blocks
type rd_bus_t is array (0 to BLK_NUM-1) of std_logic_vector(31 downto 0);
type rd_bus_t is array (0 to BLK_NUM - 1) of std_logic_vector(31 downto 0);
signal cs_rd_data_i : rd_bus_t;
signal busy : std_logic;
@ -59,65 +59,66 @@ architecture RTL of cs_bus_ift is
signal sel_read_valid : std_logic;
signal read_valid : std_logic;
signal read_valid_d : std_logic;
signal dummy_rv : std_logic; -- Dummy Read valid: asserted when
-- trying to read from not allocated addresses
signal dummy_rv : std_logic; -- Dummy Read valid: asserted when
-- trying to read from not allocated addresses
signal timeout_flag : std_logic;
signal read_timeout_cnt : std_logic_vector( 9 downto 0);
signal read_timeout_cnt : std_logic_vector(9 downto 0);
signal avs_address_i : std_logic_vector(14 downto 0);
begin
BUS_REMAP: for i in 0 to BLK_NUM-1 generate
cs_rd_data_i(i) <= cs_rd_data((i+1)*32-1 downto i*32);
BUS_REMAP : for i in 0 to BLK_NUM - 1 generate
cs_rd_data_i(i) <= cs_rd_data((i + 1) * 32 - 1 downto i * 32);
end generate BUS_REMAP;
pLatchIO : process(rstN, clk)
begin
if(rstN = '0') then
avs_address_i <= (others => '0');
cs_we <= (others => '0');
cs_wr_data <= (others => '0');
cs_re <= (others => '0');
avs_readdata <= (others => '0');
avs_waitrequest <= '1';
busy <= '0';
avs_wr_en_d <= '0';
avs_read_d <= '0';
read_valid_d <= '0';
dummy_rv <= '0';
elsif(clk = '1' and clk'event) then
if(avs_write = '1' or avs_read = '1') then
if (rstN = '0') then
avs_address_i <= (others => '0');
cs_we <= (others => '0');
cs_wr_data <= (others => '0');
cs_re <= (others => '0');
avs_readdata <= (others => '0');
avs_waitrequest <= '1';
busy <= '0';
avs_wr_en_d <= '0';
avs_read_d <= '0';
read_valid_d <= '0';
dummy_rv <= '0';
read_timeout_cnt <= (others => '0');
elsif (clk = '1' and clk'event) then
if (avs_write = '1' or avs_read = '1') then
avs_address_i <= avs_address;
end if;
avs_wr_en_d <= avs_wr_en;
avs_read_d <= avs_read;
read_valid_d <= read_valid;
for i in 0 to BLK_NUM-1 loop
for i in 0 to BLK_NUM - 1 loop
-- limit to 16 the maximum number of user blocks
if(avs_wr_en = '1' and to_integer(unsigned(avs_address(avs_address'high downto avs_address'high-3))) = i) then
if (avs_wr_en = '1' and to_integer(unsigned(avs_address(avs_address'high downto avs_address'high - 3))) = i) then
cs_we(i) <= '1';
else
cs_we(i) <= '0';
end if;
end loop; -- i
if(avs_wr_en = '1') then
end loop; -- i
if (avs_wr_en = '1') then
cs_wr_data <= avs_writedata;
end if;
for i in 0 to BLK_NUM-1 loop
if(avs_rd_en = '1' and to_integer(unsigned(avs_address(avs_address'high downto avs_address'high-3))) = i) then
for i in 0 to BLK_NUM - 1 loop
if (avs_rd_en = '1' and to_integer(unsigned(avs_address(avs_address'high downto avs_address'high - 3))) = i) then
cs_re(i) <= '1';
else
cs_re(i) <= '0';
end if;
end loop; -- i
if((avs_rd_en = '1' and (to_integer(unsigned(avs_address(avs_address'high downto avs_address'high-3))) >= BLK_NUM)) or timeout_flag = '1') then
end loop; -- i
if ((avs_rd_en = '1' and (to_integer(unsigned(avs_address(avs_address'high downto avs_address'high - 3))) >= BLK_NUM)) or timeout_flag = '1') then
dummy_rv <= '1';
else
dummy_rv <= '0';
end if;
if(sel_read_valid = '1') then
avs_readdata <= cs_rd_data_i(to_integer(unsigned(avs_address_i(avs_address'high downto avs_address'high-3))));
elsif(dummy_rv = '1') then
if (sel_read_valid = '1') then
avs_readdata <= cs_rd_data_i(to_integer(unsigned(avs_address_i(avs_address'high downto avs_address'high - 3))));
elsif (dummy_rv = '1') then
avs_readdata <= X"DEAD_BEEF";
end if;
-- waitrequest can be decoupled from the read and write request signals.
@ -126,29 +127,29 @@ begin
-- deasserted. Decoupling waitrequest from read and write requests may improve
-- system timing. Decoupling eliminates a combinational loop including the read,
-- write, and waitrequest signals.
if(avs_wr_en = '1' or read_valid = '1') then
if (avs_wr_en = '1' or read_valid = '1') then
avs_waitrequest <= '0';
else
avs_waitrequest <= '1';
end if;
if(avs_wr_en = '1' or avs_rd_en = '1') then
if (avs_wr_en = '1' or avs_rd_en = '1') then
busy <= '1';
elsif(avs_wr_en_d = '1' or read_valid_d = '1') then
elsif (avs_wr_en_d = '1' or read_valid_d = '1') then
busy <= '0';
end if;
if(avs_rd_en = '1') then
if (avs_rd_en = '1') then
read_timeout_cnt <= (others => '0');
elsif(avs_read_d = '1') then
read_timeout_cnt <= std_logic_vector(unsigned(read_timeout_cnt)+1);
elsif (avs_read_d = '1') then
read_timeout_cnt <= std_logic_vector(unsigned(read_timeout_cnt) + 1);
end if;
end if;
end process pLatchIO;
sel_read_valid <= cs_rv(to_integer(unsigned(avs_address_i(avs_address'high downto avs_address'high-3))));
read_valid <= dummy_rv or sel_read_valid;
sel_read_valid <= cs_rv(to_integer(unsigned(avs_address_i(avs_address'high downto avs_address'high - 3))));
read_valid <= dummy_rv or sel_read_valid;
avs_rd_en <= avs_read and not busy;
avs_rd_en <= avs_read and not busy;
avs_wr_en <= avs_write and not busy;
cs_addr <= avs_address_i(10 downto 0);

View file

@ -35,33 +35,33 @@ use ieee.numeric_std.all;
entity encoder_multiply_0 is
port(
reset_n : in std_logic;
clk : in std_logic;
init : in std_logic;
enable : in std_logic;
mult_sel : in std_logic_vector( 2 downto 0);
delta_t : in std_logic_vector(31 downto 0);
step_pos_in : in std_logic;
step_neg_in : in std_logic;
step_pos_out : out std_logic;
step_neg_out : out std_logic;
align_error : out std_logic_vector(19 downto 0));
reset_n : in std_logic;
clk : in std_logic;
init : in std_logic;
enable : in std_logic;
mult_sel : in std_logic_vector(2 downto 0);
delta_t : in std_logic_vector(31 downto 0);
step_pos_in : in std_logic;
step_neg_in : in std_logic;
step_pos_out : out std_logic;
step_neg_out : out std_logic;
align_error : out std_logic_vector(19 downto 0));
end encoder_multiply_0;
architecture rtl of encoder_multiply_0 is
-- number of bits to represent the maximum multiplication value (e.g. 8 => M = 128)
constant MULT_W : natural := 8;
constant MULT_W : natural := 8;
-- Number of bits used to represent the encoder pulse count, before the multiplication
constant PULSE_CNT_W : natural := 8+1;
constant PULSE_CNT_W : natural := 8 + 1;
-- Number of bits used to represent the encoder pulse count, after the multiplication
constant M_PULSE_CNT_W : natural := (MULT_W + PULSE_CNT_W);
-- To prevent counter saturation, subtract a fixed amount each time the
-- counters exceed a given value
constant NORM_VALUE : natural := 2**(PULSE_CNT_W-3);
constant NORM_VALUE : natural := 2 ** (PULSE_CNT_W - 3);
subtype shft_left_vec_t is std_logic_vector(M_PULSE_CNT_W-1 downto 0);
subtype shft_left_vec_t is std_logic_vector(M_PULSE_CNT_W - 1 downto 0);
subtype shft_right_vec_t is std_logic_vector(30 downto 0);
function shift_left(operand : shft_left_vec_t; shf_val : natural range 0 to 7) return shft_left_vec_t is
@ -69,10 +69,10 @@ architecture rtl of encoder_multiply_0 is
begin
result := operand;
for n in 1 to 7 loop
if(n <= shf_val) then
result := result(operand'left-1 downto 0) & '0';
if (n <= shf_val) then
result := result(operand'left - 1 downto 0) & '0';
end if;
end loop; -- n
end loop; -- n
return result;
end function shift_left;
@ -81,19 +81,18 @@ architecture rtl of encoder_multiply_0 is
begin
result := operand;
for n in 1 to 7 loop
if(n <= shf_val) then
if (n <= shf_val) then
result := result(operand'left) & result(operand'left downto 1);
end if;
end loop; -- n
end loop; -- n
return result;
end function shift_right;
signal init_d, step_pos, step_neg : std_logic;
signal m_step_pos, m_step_neg : std_logic;
signal sign, sign_i : std_logic;
signal time_cnt_tc : std_logic;
signal norm_pos, norm_neg : std_logic;
signal m_step_pos_d, m_step_neg_d : std_logic;
signal kickoff, pending_kickoff : std_logic;
signal realign_pos, realign_neg : std_logic;
signal realign_pos_d, realign_neg_d : std_logic;
@ -102,98 +101,98 @@ architecture rtl of encoder_multiply_0 is
signal delta_m_pos, delta_m_neg : std_logic;
signal post_m_step_pos : std_logic;
signal post_m_step_neg : std_logic;
signal delay_vect : std_logic_vector( 3 downto 0);
signal time_realign_cnt : std_logic_vector( 7 downto 0);
signal pulse_cnt : std_logic_vector(PULSE_CNT_W-1 downto 0);
signal m_pulse_cnt, m_norm_value : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
signal delay_vect : std_logic_vector(3 downto 0);
signal time_realign_cnt : std_logic_vector(7 downto 0);
signal pulse_cnt : std_logic_vector(PULSE_CNT_W - 1 downto 0);
signal m_pulse_cnt, m_norm_value : std_logic_vector(M_PULSE_CNT_W - 1 downto 0);
signal delta_m : std_logic_vector(M_PULSE_CNT_W downto 0);
signal time_cnt : std_logic_vector(27 downto 0);
signal m_delta_t : std_logic_vector(30 downto 0);
signal delta_t_i : std_logic_vector(30 downto 0);
begin
pSEQ_LOGIC : process(clk)
variable mult_pulse_cnt : std_logic_vector(M_PULSE_CNT_W-1 downto 0);
variable mult_pulse_cnt : std_logic_vector(M_PULSE_CNT_W - 1 downto 0);
begin
if(clk = '1' and clk'event) then
init_d <= init;
if(init = '1') then
if (clk = '1' and clk'event) then
init_d <= init;
if (init = '1') then
pending_kickoff <= '1';
elsif(kickoff = '1') then
elsif (kickoff = '1') then
pending_kickoff <= '0';
end if;
if(init_d = '1') then
if (init_d = '1') then
pulse_cnt <= (others => '0');
elsif(norm_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)-NORM_VALUE+1);
elsif(norm_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)+NORM_VALUE-1);
elsif(step_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)+1);
elsif(step_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt)-1);
elsif (norm_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt) - NORM_VALUE + 1);
elsif (norm_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt) + NORM_VALUE - 1);
elsif (step_pos = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt) + 1);
elsif (step_neg = '1') then
pulse_cnt <= std_logic_vector(signed(pulse_cnt) - 1);
end if;
if(init_d = '1') then
if (init_d = '1') then
m_pulse_cnt <= (others => '0');
elsif(norm_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-signed(m_norm_value));
elsif(norm_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+signed(m_norm_value));
elsif(m_step_pos = '1' or post_m_step_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)+1);
elsif(m_step_neg = '1' or post_m_step_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt)-1);
elsif (norm_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt) - signed(m_norm_value));
elsif (norm_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt) + signed(m_norm_value));
elsif (m_step_pos = '1' or post_m_step_pos = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt) + 1);
elsif (m_step_neg = '1' or post_m_step_neg = '1') then
m_pulse_cnt <= std_logic_vector(signed(m_pulse_cnt) - 1);
end if;
if((norm_pos = '1' or norm_neg = '1') and m_step_pos = '1') then
if ((norm_pos = '1' or norm_neg = '1') and m_step_pos = '1') then
post_m_step_pos <= '1';
else
post_m_step_pos <= '0';
end if;
if((norm_pos = '1' or norm_neg = '1') and m_step_neg = '1') then
if ((norm_pos = '1' or norm_neg = '1') and m_step_neg = '1') then
post_m_step_neg <= '1';
else
post_m_step_neg <= '0';
end if;
if(m_step_pos = '1' or m_step_neg = '1') then
if (m_step_pos = '1' or m_step_neg = '1') then
time_cnt <= m_delta_t(27 downto 0);
elsif(time_cnt_tc = '0') then
time_cnt <= std_logic_vector(unsigned(time_cnt)-1);
elsif (time_cnt_tc = '0') then
time_cnt <= std_logic_vector(unsigned(time_cnt) - 1);
end if;
m_delta_t <= shift_right(std_logic_vector(unsigned(delta_t_i)), to_integer(unsigned(mult_sel)));
sign <= sign_i;
mult_pulse_cnt := shift_left(std_logic_vector(resize(signed(pulse_cnt), M_PULSE_CNT_W)),to_integer(signed('0' & mult_sel)));
delta_m <= std_logic_vector(resize(signed(m_pulse_cnt),delta_m'length) - resize(signed(mult_pulse_cnt),delta_m'length));
if(step_pos = '1' or step_neg = '1' or m_step_pos = '1' or m_step_neg = '1' or realign_pos_i = '1' or realign_neg_i = '1') then
m_delta_t <= shift_right(std_logic_vector(unsigned(delta_t_i)), to_integer(unsigned(mult_sel)));
sign <= sign_i;
mult_pulse_cnt := shift_left(std_logic_vector(resize(signed(pulse_cnt), M_PULSE_CNT_W)), to_integer(signed('0' & mult_sel)));
delta_m <= std_logic_vector(resize(signed(m_pulse_cnt), delta_m'length) - resize(signed(mult_pulse_cnt), delta_m'length));
if (step_pos = '1' or step_neg = '1' or m_step_pos = '1' or m_step_neg = '1' or realign_pos_i = '1' or realign_neg_i = '1') then
delay_vect <= (others => '1');
else
delay_vect <= '0' & delay_vect(3 downto 1);
end if;
if(delay_vect(0) = '0' and (signed(delta_m) <= signed(shift_left(std_logic_vector(to_signed(-4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then
if (delay_vect(0) = '0' and (signed(delta_m) <= signed(shift_left(std_logic_vector(to_signed(-4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then
realign_pos <= '1';
else
realign_pos <= '0';
end if;
if(delay_vect(0) = '0' and (signed(delta_m) >= signed(shift_left(std_logic_vector(to_signed(4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then
if (delay_vect(0) = '0' and (signed(delta_m) >= signed(shift_left(std_logic_vector(to_signed(4, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)))))) then
realign_neg <= '1';
else
realign_neg <= '0';
end if;
realign_pos_d <= realign_pos;
realign_neg_d <= realign_neg;
step_pos_out <= m_step_pos;
step_neg_out <= m_step_neg;
m_norm_value <= shift_left(std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)));
realign_pos_d <= realign_pos;
realign_neg_d <= realign_neg;
step_pos_out <= m_step_pos;
step_neg_out <= m_step_neg;
m_norm_value <= shift_left(std_logic_vector(to_unsigned(NORM_VALUE, M_PULSE_CNT_W)), to_integer(unsigned(mult_sel)));
-- Time based re-alignment
if(m_step_pos = '1' or m_step_neg = '1') then
time_realign_cnt <= std_logic_vector(to_unsigned(50,time_realign_cnt'length));
elsif(time_realign_flag = '0') then
time_realign_cnt <= std_logic_vector(unsigned(time_realign_cnt)-1);
if (m_step_pos = '1' or m_step_neg = '1') then
time_realign_cnt <= std_logic_vector(to_unsigned(50, time_realign_cnt'length));
elsif (time_realign_flag = '0') then
time_realign_cnt <= std_logic_vector(unsigned(time_realign_cnt) - 1);
end if;
align_error <= std_logic_vector(resize(signed(delta_m), 20));
align_error <= std_logic_vector(resize(signed(delta_m), 20));
end if;
end process pSEQ_LOGIC;
time_realign_flag <= '1' when unsigned(time_realign_cnt) = 0 else '0';
realign_pos_i <= realign_pos and not realign_pos_d;
@ -216,8 +215,8 @@ begin
kickoff <= pending_kickoff and (step_pos or step_neg);
norm_pos <= '1' when step_pos = '1' and signed(pulse_cnt)-2*NORM_VALUE >= 0 else '0';
norm_neg <= '1' when step_neg = '1' and signed(pulse_cnt)+2*NORM_VALUE <= 0 else '0';
norm_pos <= '1' when step_pos = '1' and signed(pulse_cnt) - 2 * NORM_VALUE >= 0 else '0';
norm_neg <= '1' when step_neg = '1' and signed(pulse_cnt) + 2 * NORM_VALUE <= 0 else '0';
delta_m_pos <= '1' when signed(delta_m) > 0 else '0';
delta_m_neg <= delta_m(delta_m'left);

View file

@ -65,7 +65,7 @@
"address": "3",
"width": "16",
"type": "c",
"reset": "30000",
"reset": "20000",
"description": "Firmware version first number (default overridden in Jenkins build)"
},
"FW_VER_TWO": {

View file

@ -51,7 +51,7 @@
"minor_number": {
"type": "c",
"bit_len": "8",
"reset": "0x02",
"reset": "0x03",
"description": "Minor number"
},
"major_number": {

View file

@ -159,6 +159,10 @@ begin
begin
if (reset_n = '0') then
avs_readdatavalid <= '0';
avs_read_d <= '0';
swim_read_d <= '0';
avs_readdata <= (others => '0');
avs_readdata_i <= (others => '0');
--
host_pwr_en <= '0';
host_5v_en <= '0';

View file

@ -39,7 +39,7 @@
"minor_number" : {
"type" : "c",
"bit_len" : "8",
"reset" : "0x03",
"reset" : "0x04",
"description" : "Minor number"
},
"major_number" : {

View file

@ -59,26 +59,26 @@ use ieee.numeric_std.all;
use ieee.std_logic_misc.all;
entity swim_2 is
generic (
CLK_FREQ_MHZ : integer := 100;
TEST_MODE : boolean := false
generic(
CLK_FREQ_MHZ : integer := 100;
TEST_MODE : boolean := false
);
port (
clk : in std_logic;
reset_n : in std_logic;
port(
clk : in std_logic;
reset_n : in std_logic;
-- Avalon MM interface
avs_address : in std_logic_vector( 3 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_readdata : out std_logic_vector(31 downto 0);
avs_address : in std_logic_vector(3 downto 0);
avs_write : in std_logic;
avs_writedata : in std_logic_vector(31 downto 0);
avs_read : in std_logic;
avs_readdata : out std_logic_vector(31 downto 0);
swim_out : out std_logic;
swim_in : in std_logic;
swim_out : out std_logic;
swim_in : in std_logic;
-- Debug
dbg_port : out std_logic_vector(4 downto 0)
dbg_port : out std_logic_vector(4 downto 0)
);
end entity swim_2;
@ -86,223 +86,223 @@ end entity swim_2;
architecture rtl of swim_2 is
-- Define local constants for bit-patterns and their lengths
constant LONG_ONE : std_logic_vector(10 downto 0) := "10011111111";
constant LONG_ZERO : std_logic_vector(10 downto 0) := "10000000001";
constant SHORT_ONE : std_logic_vector(10 downto 0) := "00000001111";
constant SHORT_ZERO : std_logic_vector(10 downto 0) := "00000000001";
constant LONG_ONE : std_logic_vector(10 downto 0) := "10011111111";
constant LONG_ZERO : std_logic_vector(10 downto 0) := "10000000001";
constant SHORT_ONE : std_logic_vector(10 downto 0) := "00000001111";
constant SHORT_ZERO : std_logic_vector(10 downto 0) := "00000000001";
constant LONG_LENGTH : std_logic_vector( 3 downto 0) := 4x"B";
constant SHORT_LENGTH : std_logic_vector( 3 downto 0) := 4x"5";
constant LONG_LENGTH : std_logic_vector(3 downto 0) := 4x"B";
constant SHORT_LENGTH : std_logic_vector(3 downto 0) := 4x"5";
constant ENTRY_SEQ_LEN_M1 : integer := 28;
constant ENTRY_SEQ_PATTERN : std_logic_vector(ENTRY_SEQ_LEN_M1 downto 0) := "01001100110011001100101010101";
constant ENTRY_SEQ_LEN_M1 : integer := 28;
constant ENTRY_SEQ_PATTERN : std_logic_vector(ENTRY_SEQ_LEN_M1 downto 0) := "01001100110011001100101010101";
constant TX_SHIFT_REG_LEN_M1 : integer := 60;
constant WRITE_CMD_LEN_M1 : integer := TX_SHIFT_REG_LEN_M1;
constant READ_CMD_LEN_M1 : integer := 49;
constant BLK_CMD_LEN_M1 : integer := READ_CMD_LEN_M1;
constant BLK_BYTE_LEN_M1 : integer := 10;
constant SRST_CMD_LEN_M1 : integer := 5;
constant TX_SHIFT_REG_LEN_M1 : integer := 60;
constant WRITE_CMD_LEN_M1 : integer := TX_SHIFT_REG_LEN_M1;
constant READ_CMD_LEN_M1 : integer := 49;
constant BLK_CMD_LEN_M1 : integer := READ_CMD_LEN_M1;
constant BLK_BYTE_LEN_M1 : integer := 10;
constant SRST_CMD_LEN_M1 : integer := 5;
constant RX_BIT_COUNT_THRESHOLD : integer := 62 * CLK_FREQ_MHZ / 100; -- Number relative to 100MHz default clock speed
constant SWIM_BITS_PER_BYTE : integer := 11;
constant RX_BIT_COUNT_THRESHOLD : integer := 62 * CLK_FREQ_MHZ / 100; -- Number relative to 100MHz default clock speed
constant SWIM_BITS_PER_BYTE : integer := 11;
constant CLK_COUNT_4MHZ : integer := CLK_FREQ_MHZ/4; -- 15 for 60MHz, 20 for 80MHz and 25 for 100MHz
constant CLK4M_COUNT_4KHZ : integer := 1000;
constant CLK4M_LONG_COUNT_PER_BIT : integer := to_integer(unsigned(LONG_LENGTH));
constant CLK4M_SHORT_COUNT_PER_BIT : integer := to_integer(unsigned(SHORT_LENGTH));
constant CLK_COUNT_4MHZ : integer := CLK_FREQ_MHZ / 4; -- 15 for 60MHz, 20 for 80MHz and 25 for 100MHz
constant CLK4M_COUNT_4KHZ : integer := 1000;
constant CLK4M_LONG_COUNT_PER_BIT : integer := to_integer(unsigned(LONG_LENGTH));
constant CLK4M_SHORT_COUNT_PER_BIT : integer := to_integer(unsigned(SHORT_LENGTH));
-- Internal signals for the register block connections
signal control_high_speed : std_logic; -- Data rate is high sppend (i.e. not low speed)
signal control_clr_rx : std_logic; -- Clear the RX byte (pulse)
signal control_send_entry_seq : std_logic; -- Start the transmission of the entry sequence (pulse)
signal control_tx_retry_timeout : std_logic_vector(7 downto 0); -- TX retry limit
signal control_reset_state : std_logic; -- Reset all TX/RX state (pulse)
signal control_send_srst : std_logic; -- Send a SWRST command (pulse)
signal control_clear_errors : std_logic; -- Clear errors (pulse)
signal control_high_speed : std_logic; -- Data rate is high sppend (i.e. not low speed)
signal control_clr_rx : std_logic; -- Clear the RX byte (pulse)
signal control_send_entry_seq : std_logic; -- Start the transmission of the entry sequence (pulse)
signal control_tx_retry_timeout : std_logic_vector(7 downto 0); -- TX retry limit
signal control_reset_state : std_logic; -- Reset all TX/RX state (pulse)
signal control_send_srst : std_logic; -- Send a SWRST command (pulse)
signal control_clear_errors : std_logic; -- Clear errors (pulse)
signal tx_byte_pulse : std_logic; -- Pulse on tx_byte write
signal tx_byte_byte : std_logic_vector(7 downto 0); -- byte value for transmission
signal tx_byte_byte_in : std_logic_vector(7 downto 0); -- Readback value for tx_byte_byte
signal tx_byte_waddr : std_logic_vector(23 downto 0); -- Write address value for transmission
signal tx_byte_waddr_in : std_logic_vector(23 downto 0); -- Readback value for tx_byte_waddr
signal tx_byte_waddr_reg : std_logic_vector(23 downto 0); -- tx_byte waddr register value for readback
signal tx_byte_byte_reg : std_logic_vector( 7 downto 0); -- tx_byte byte register value for readback
signal tx_byte_pulse : std_logic; -- Pulse on tx_byte write
signal tx_byte_byte : std_logic_vector(7 downto 0); -- byte value for transmission
signal tx_byte_byte_in : std_logic_vector(7 downto 0); -- Readback value for tx_byte_byte
signal tx_byte_waddr : std_logic_vector(23 downto 0); -- Write address value for transmission
signal tx_byte_waddr_in : std_logic_vector(23 downto 0); -- Readback value for tx_byte_waddr
signal tx_byte_waddr_reg : std_logic_vector(23 downto 0); -- tx_byte waddr register value for readback
signal tx_byte_byte_reg : std_logic_vector(7 downto 0); -- tx_byte byte register value for readback
signal rx_byte_pulse : std_logic; -- Pulse on rx_byte write
signal rx_byte_byte_in : std_logic_vector( 7 downto 0); -- RX bye readback value
signal rx_byte_raddr : std_logic_vector(23 downto 0); -- Read address value for transmission
signal rx_byte_raddr_in : std_logic_vector(23 downto 0); -- Read address readback value
signal rx_byte_raddr_reg : std_logic_vector(23 downto 0); -- rx_byte raddr register value for readback
signal rx_byte_pulse : std_logic; -- Pulse on rx_byte write
signal rx_byte_byte_in : std_logic_vector(7 downto 0); -- RX bye readback value
signal rx_byte_raddr : std_logic_vector(23 downto 0); -- Read address value for transmission
signal rx_byte_raddr_in : std_logic_vector(23 downto 0); -- Read address readback value
signal rx_byte_raddr_reg : std_logic_vector(23 downto 0); -- rx_byte raddr register value for readback
signal status_rxbusy : std_logic; -- RX busy status input for reading
signal status_txbusy : std_logic; -- TX busy status input for reading
signal status_rx_ready : std_logic; -- RX ready with a byte for reading
signal status_tx_error : std_logic; -- TX error status input
signal status_rx_error : std_logic; -- RX error status input
signal status_tx_nak_error : std_logic; -- TX ACK/NAK status input
signal status_entry_seq_sent : std_logic; -- Entry sequence has been sent since last reset
signal blk_remaining : std_logic_vector(7 downto 0); -- Count of remaining byte in block TX
signal tx_block_pulse : std_logic;
signal tx_block_waddr : std_logic_vector(23 downto 0);
signal tx_block_waddr_reg : std_logic_vector(23 downto 0);
signal push_byte_pulse : std_logic;
signal push_byte : std_logic_vector(7 downto 0);
signal status_rxbusy : std_logic; -- RX busy status input for reading
signal status_txbusy : std_logic; -- TX busy status input for reading
signal status_rx_ready : std_logic; -- RX ready with a byte for reading
signal status_tx_error : std_logic; -- TX error status input
signal status_rx_error : std_logic; -- RX error status input
signal status_tx_nak_error : std_logic; -- TX ACK/NAK status input
signal status_entry_seq_sent : std_logic; -- Entry sequence has been sent since last reset
signal blk_remaining : std_logic_vector(7 downto 0); -- Count of remaining byte in block TX
signal tx_block_pulse : std_logic;
signal tx_block_waddr : std_logic_vector(23 downto 0);
signal tx_block_waddr_reg : std_logic_vector(23 downto 0);
signal push_byte_pulse : std_logic;
signal push_byte : std_logic_vector(7 downto 0);
-- Signals for timing pulse generation
signal count_4KHz : std_logic_vector(9 downto 0); -- Counter to count 4MHz pulse for 4KHz timing
signal count_4mhz_for_4khz : std_logic_vector(9 downto 0);
signal count_4MHz : std_logic_vector(4 downto 0); -- Counter to count 100MHz clock for 4MHz timing
signal count_4Mhz_thresh : std_logic_vector(4 downto 0);
signal bit_count : std_logic_vector(4 downto 0); -- Counter to count 4MHz ticks for TX of return-to zero 0/1
signal tick_4KHz : std_logic; -- Tick at 4KHz (100MHz pulse)
signal tick_4MHz : std_logic; -- Tick at 4MHz (100MHz pulse)
signal bit_clk : std_logic; -- Tick at end of each TX bit (for either high or low speed bits)
signal bit_rollover : std_logic_vector(4 downto 0); -- Count value for bit_count rollover dependent on high or low speed mode
signal active_hi_speed : std_logic; -- The active speed mode (control_high_speed, synced to bit period)
signal tick_active : std_logic; -- The active TX tick, either the 4KHz during entry seq, or 4MHz for transmission)
signal timeout : std_logic_vector(11 downto 0); -- Timeout counter
signal timed_out : std_logic; -- Timed out pulse
signal count_4KHz : std_logic_vector(9 downto 0); -- Counter to count 4MHz pulse for 4KHz timing
signal count_4mhz_for_4khz : std_logic_vector(9 downto 0);
signal count_4MHz : std_logic_vector(4 downto 0); -- Counter to count 100MHz clock for 4MHz timing
signal count_4Mhz_thresh : std_logic_vector(4 downto 0);
signal bit_count : std_logic_vector(4 downto 0); -- Counter to count 4MHz ticks for TX of return-to zero 0/1
signal tick_4KHz : std_logic; -- Tick at 4KHz (100MHz pulse)
signal tick_4MHz : std_logic; -- Tick at 4MHz (100MHz pulse)
signal bit_clk : std_logic; -- Tick at end of each TX bit (for either high or low speed bits)
signal bit_rollover : std_logic_vector(4 downto 0); -- Count value for bit_count rollover dependent on high or low speed mode
signal active_hi_speed : std_logic; -- The active speed mode (control_high_speed, synced to bit period)
signal tick_active : std_logic; -- The active TX tick, either the 4KHz during entry seq, or 4MHz for transmission)
signal timeout : std_logic_vector(11 downto 0); -- Timeout counter
signal timed_out : std_logic; -- Timed out pulse
-- Signals for transmission bit generation
signal tx_bits : std_logic_vector(12 downto 0); -- The bits for transmission, incl. header, parity and the ACK space
signal tx_bits_count : std_logic_vector(3 downto 0); -- The count of bits transmitted from tx_bits
signal op_active : std_logic; -- Flag for when the output is actively transmitting
signal tx_bit_active : std_logic; -- op_active, aligned to the bit_clk pulse
signal entry_active : std_logic; -- Flag set when entry sequence is in progress
signal tx_shift_reg : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- The TX output shift register. Holds up to an entire command, plus one byte
signal tx_shift_ack_reg : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Mirror shift register, marking the position of ACK slots
signal tx_wr_frame : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF command frame for loading into shift register
signal tx_wr_ack_pos : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF ack positions for loading into ack shift register
signal blk_wr_frame : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF block command frame for loading into shift register
signal blk_wr_ack_pos : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF ack positions for loading into ack shift register
signal push_wr_frame : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF byte for loading into shift register
signal tx_rd_frame : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed ROTF command frame for loading into shift register
signal tx_rd_ack_pos : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed ROTF ack positions for loading into ack shift register
signal sys_rst_frame : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed SWRST command frame for loading into shift register
signal sys_rst_ack_pos : std_logic_vector (TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed SWRST ack positions for loading into ack shift register
signal waddre_par : std_logic; -- Parity for upper most byte of write access address
signal waddrh_par : std_logic; -- Parity for mid byte of write access address
signal waddrl_par : std_logic; -- Parity for lowest most byte of write access address
signal raddre_par : std_logic; -- Parity for upper most byte of read access address
signal raddrh_par : std_logic; -- Parity for mid byte of read access address
signal raddrl_par : std_logic; -- Parity for lowest most byte of read access address
signal baddre_par : std_logic; -- Parity for upper most byte of block write access address
signal baddrh_par : std_logic; -- Parity for mid byte of block write access address
signal baddrl_par : std_logic; -- Parity for lowest most byte of block write access address
signal tx_byte_par : std_logic; -- Parity for the data byte
signal push_byte_par : std_logic; -- Parity for the pushed block data byte
signal tx_shift_count : std_logic_vector(5 downto 0); -- Count of bits sent from TX shift register
signal tx_shift_retry_pos : std_logic_vector(5 downto 0); -- State to hold retry position of shift register, for replay on NACK
signal tx_ack_slot : std_logic; -- Flag marking when in an ACK slot during transmission
signal tx_retry_count : std_logic_vector(7 downto 0); -- Count of retries since last successful transmission
signal seen_tx_ack_rising : std_logic; -- State flagging that a TX ACK rising edge has been seen
signal rx_ack_slot : std_logic; -- Flag marking when an RX ACK slot (aligned to 4MHz tick)
signal tx_bits : std_logic_vector(11 downto 0); -- The bits for transmission, incl. header, parity and the ACK space
signal tx_bits_count : std_logic_vector(3 downto 0); -- The count of bits transmitted from tx_bits
signal op_active : std_logic; -- Flag for when the output is actively transmitting
signal tx_bit_active : std_logic; -- op_active, aligned to the bit_clk pulse
signal entry_active : std_logic; -- Flag set when entry sequence is in progress
signal tx_shift_reg : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- The TX output shift register. Holds up to an entire command, plus one byte
signal tx_shift_ack_reg : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Mirror shift register, marking the position of ACK slots
signal tx_wr_frame : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF command frame for loading into shift register
signal tx_wr_ack_pos : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF ack positions for loading into ack shift register
signal blk_wr_frame : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF block command frame for loading into shift register
signal blk_wr_ack_pos : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF ack positions for loading into ack shift register
signal push_wr_frame : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed WOTF byte for loading into shift register
signal tx_rd_frame : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed ROTF command frame for loading into shift register
signal tx_rd_ack_pos : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed ROTF ack positions for loading into ack shift register
signal sys_rst_frame : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed SWRST command frame for loading into shift register
signal sys_rst_ack_pos : std_logic_vector(TX_SHIFT_REG_LEN_M1 downto 0); -- Constructed SWRST ack positions for loading into ack shift register
signal waddre_par : std_logic; -- Parity for upper most byte of write access address
signal waddrh_par : std_logic; -- Parity for mid byte of write access address
signal waddrl_par : std_logic; -- Parity for lowest most byte of write access address
signal raddre_par : std_logic; -- Parity for upper most byte of read access address
signal raddrh_par : std_logic; -- Parity for mid byte of read access address
signal raddrl_par : std_logic; -- Parity for lowest most byte of read access address
signal baddre_par : std_logic; -- Parity for upper most byte of block write access address
signal baddrh_par : std_logic; -- Parity for mid byte of block write access address
signal baddrl_par : std_logic; -- Parity for lowest most byte of block write access address
signal tx_byte_par : std_logic; -- Parity for the data byte
signal push_byte_par : std_logic; -- Parity for the pushed block data byte
signal tx_shift_count : std_logic_vector(5 downto 0); -- Count of bits sent from TX shift register
signal tx_shift_retry_pos : std_logic_vector(5 downto 0); -- State to hold retry position of shift register, for replay on NACK
signal tx_ack_slot : std_logic; -- Flag marking when in an ACK slot during transmission
signal tx_retry_count : std_logic_vector(7 downto 0); -- Count of retries since last successful transmission
signal seen_tx_ack_rising : std_logic; -- State flagging that a TX ACK rising edge has been seen
signal rx_ack_slot : std_logic; -- Flag marking when an RX ACK slot (aligned to 4MHz tick)
-- Receiver signals
signal rx_shift_register : std_logic_vector(10 downto 0); -- RX input shift register
signal rx_falling_edge : std_logic; -- Pulse on input signal falling edge
signal rx_rising_edge : std_logic; -- Pulse on input signal rising edge
signal swim_in_last : std_logic; -- Cycle delayed version of (synced) swim input
signal rx_bit_count : std_logic_vector(9 downto 0); -- Count of received bits
signal rx_bit_count_thresh : std_logic_vector(9 downto 0);
signal receiving_bit : std_logic; -- Flag active when receiving a bit
signal rx_idx : std_logic_vector(3 downto 0); -- Count of cycles for low period of received bit
signal rx_parity : std_logic; -- Parity of the received byte
signal rx_expecting_byte : std_logic; -- Flag set when expecting a byte (after an ROTF command sent)
signal send_rx_ack : std_logic; -- Request to transmitter to send an ACK bit
signal send_rx_ack_data : std_logic; -- ACK data value to be transmitted
signal rx_ack_delay : std_logic_vector(3 downto 0); -- ACK delay
signal rx_nacked : std_logic; -- Flag if receiver NAKed
signal rx_shift_register : std_logic_vector(10 downto 0); -- RX input shift register
signal rx_falling_edge : std_logic; -- Pulse on input signal falling edge
signal rx_rising_edge : std_logic; -- Pulse on input signal rising edge
signal swim_in_last : std_logic; -- Cycle delayed version of (synced) swim input
signal rx_bit_count : std_logic_vector(9 downto 0); -- Count of received bits
signal rx_bit_count_thresh : std_logic_vector(9 downto 0);
signal receiving_bit : std_logic; -- Flag active when receiving a bit
signal rx_idx : std_logic_vector(3 downto 0); -- Count of cycles for low period of received bit
signal rx_parity : std_logic; -- Parity of the received byte
signal rx_expecting_byte : std_logic; -- Flag set when expecting a byte (after an ROTF command sent)
signal send_rx_ack : std_logic; -- Request to transmitter to send an ACK bit
signal send_rx_ack_data : std_logic; -- ACK data value to be transmitted
signal rx_ack_delay : std_logic_vector(3 downto 0); -- ACK delay
signal rx_nacked : std_logic; -- Flag if receiver NAKed
signal swim_in_sync : std_logic_vector(1 downto 0); -- Synchroniser for SWIM input
signal swim_in_sync : std_logic_vector(1 downto 0); -- Synchroniser for SWIM input
constant zero : std_logic_vector(31 downto 0) := 32x"00000000"; -- Convenience std_logic_vector value of 0 to save on conversions
constant one : std_logic_vector(31 downto 0) := 32x"00000001"; -- Convenience std_logic_vector value of 1 to save on conversions
constant zero : std_logic_vector(31 downto 0) := 32x"00000000"; -- Convenience std_logic_vector value of 0 to save on conversions
constant one : std_logic_vector(31 downto 0) := 32x"00000001"; -- Convenience std_logic_vector value of 1 to save on conversions
begin
GEN_TEST_MODE : if TEST_MODE generate
count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ/100-1, 10));
rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD/10, 10));
count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ/10-1, 5));
count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ / 100 - 1, 10));
rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD / 10, 10));
count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ / 10 - 1, 5));
end generate;
GEN_NOT_TEST_MODE : if not TEST_MODE generate
count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ-1, 10));
rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD, 10));
count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ-1, 5));
count_4mhz_for_4khz <= std_logic_vector(to_unsigned(CLK4M_COUNT_4KHZ - 1, 10));
rx_bit_count_thresh <= std_logic_vector(to_unsigned(RX_BIT_COUNT_THRESHOLD, 10));
count_4Mhz_thresh <= std_logic_vector(to_unsigned(CLK_COUNT_4MHZ - 1, 5));
end generate;
-- Export for debug selected signals (up to 5)
dbg_port <= timed_out & status_rx_error & status_rxbusy & status_tx_nak_error & swim_in_sync(0) ;
dbg_port <= timed_out & status_rx_error & status_rxbusy & status_tx_nak_error & swim_in_sync(0);
-- TX byte, and address from RX_address read back registered values
tx_byte_waddr_in <= tx_byte_waddr_reg;
tx_byte_byte_in <= tx_byte_byte_reg;
rx_byte_raddr_in <= rx_byte_raddr_reg;
tx_byte_waddr_in <= tx_byte_waddr_reg;
tx_byte_byte_in <= tx_byte_byte_reg;
rx_byte_raddr_in <= rx_byte_raddr_reg;
-- Readback of RX byte field gives received bytes from RX shift register.
-- Valid only of status_rx_ready is set
rx_byte_byte_in <= rx_shift_register(9 downto 2);
rx_byte_byte_in <= rx_shift_register(9 downto 2);
-- Auto-generated register block
swim_csr_regs_inst : entity work.swim_2_csr_regs
generic map (
generic map(
ADDR_DECODE_WIDTH => 4
)
port map (
port map(
-- Clock and reset
clk => clk,
rst_n => reset_n,
clk => clk,
rst_n => reset_n,
-- Internal signal ports
control_high_speed => control_high_speed,
control_clr_rx => control_clr_rx,
control_send_entry_seq => control_send_entry_seq,
control_tx_retry_timeout => control_tx_retry_timeout,
control_send_srst => control_send_srst,
control_clear_errors => control_clear_errors,
control_reset_state => control_reset_state,
tx_byte_pulse => tx_byte_pulse,
tx_byte_byte => tx_byte_byte,
tx_byte_byte_in => tx_byte_byte_in,
tx_byte_waddr => tx_byte_waddr,
tx_byte_waddr_in => tx_byte_waddr_in,
rx_byte_pulse => rx_byte_pulse,
rx_byte_byte => open,
rx_byte_byte_in => rx_byte_byte_in,
rx_byte_raddr => rx_byte_raddr,
rx_byte_raddr_in => rx_byte_raddr_in,
status_rxbusy => status_rxbusy,
status_txbusy => status_txbusy,
status_rx_ready => status_rx_ready,
status_tx_error => status_tx_error,
status_rx_error => status_rx_error,
status_tx_nak_error => status_tx_nak_error,
status_entry_seq_sent => status_entry_seq_sent,
control_high_speed => control_high_speed,
control_clr_rx => control_clr_rx,
control_send_entry_seq => control_send_entry_seq,
control_tx_retry_timeout => control_tx_retry_timeout,
control_send_srst => control_send_srst,
control_clear_errors => control_clear_errors,
control_reset_state => control_reset_state,
tx_byte_pulse => tx_byte_pulse,
tx_byte_byte => tx_byte_byte,
tx_byte_byte_in => tx_byte_byte_in,
tx_byte_waddr => tx_byte_waddr,
tx_byte_waddr_in => tx_byte_waddr_in,
rx_byte_pulse => rx_byte_pulse,
rx_byte_byte => open,
rx_byte_byte_in => rx_byte_byte_in,
rx_byte_raddr => rx_byte_raddr,
rx_byte_raddr_in => rx_byte_raddr_in,
status_rxbusy => status_rxbusy,
status_txbusy => status_txbusy,
status_rx_ready => status_rx_ready,
status_tx_error => status_tx_error,
status_rx_error => status_rx_error,
status_tx_nak_error => status_tx_nak_error,
status_entry_seq_sent => status_entry_seq_sent,
tx_block_pulse => tx_block_pulse,
tx_block_waddr => tx_block_waddr,
tx_block_waddr_in => tx_block_waddr_reg,
push_byte_pulse => push_byte_pulse,
push_byte => push_byte,
push_byte_in => (others => '0'),
blk_remaining => blk_remaining,
tx_block_pulse => tx_block_pulse,
tx_block_waddr => tx_block_waddr,
tx_block_waddr_in => tx_block_waddr_reg,
push_byte_pulse => push_byte_pulse,
push_byte => push_byte,
push_byte_in => (others => '0'),
blk_remaining => blk_remaining,
-- Slave bus port
avs_address => avs_address,
avs_write => avs_write,
avs_writedata => avs_writedata,
avs_read => avs_read,
avs_readdata => avs_readdata
avs_address => avs_address,
avs_write => avs_write,
avs_writedata => avs_writedata,
avs_read => avs_read,
avs_readdata => avs_readdata
);
-- Signal to flag the bit counter rollover point, depending on speed
bit_rollover <= std_logic_vector(to_unsigned(CLK4M_LONG_COUNT_PER_BIT-1, 5)) when active_hi_speed = '0' else
std_logic_vector(to_unsigned(CLK4M_SHORT_COUNT_PER_BIT-1, 5));
bit_rollover <= std_logic_vector(to_unsigned(CLK4M_LONG_COUNT_PER_BIT - 1, 5)) when active_hi_speed = '0' else
std_logic_vector(to_unsigned(CLK4M_SHORT_COUNT_PER_BIT - 1, 5));
-- Flag TX as busy to the Avalon interface for bit transmission or entry activation.
status_txbusy <= op_active or tx_bit_active or entry_active;
@ -318,15 +318,15 @@ begin
if reset_n = '0' then
count_4KHz <= (others => '0');
count_4MHz <= (others => '0');
bit_count <= (others => '0');
tick_4KHz <= '0';
tick_4MHz <= '0';
bit_clk <= '0';
active_hi_speed <= '0';
timeout <= (others => '0');
timed_out <= '0';
count_4KHz <= (others => '0');
count_4MHz <= (others => '0');
bit_count <= (others => '0');
tick_4KHz <= '0';
tick_4MHz <= '0';
bit_clk <= '0';
active_hi_speed <= '0';
timeout <= (others => '0');
timed_out <= '0';
elsif (clk'event and clk = '1') then
@ -387,14 +387,14 @@ begin
else
bit_clk <= '0';
end if;
if tick_4KHz = '1' then
if status_rxbusy = '1' or status_txbusy = '1' then
timeout <= std_logic_vector(unsigned(timeout) + 1);
else
timeout <= (others => '0');
end if;
if timeout = 12x"fff" then
timed_out <= '1';
end if;
@ -430,43 +430,43 @@ begin
-- Calculate the command parity values
waddre_par <= XOR_REDUCE(tx_byte_waddr(23 downto 16));
waddrh_par <= XOR_REDUCE(tx_byte_waddr(15 downto 8));
waddrl_par <= XOR_REDUCE(tx_byte_waddr( 7 downto 0));
waddrl_par <= XOR_REDUCE(tx_byte_waddr(7 downto 0));
baddre_par <= XOR_REDUCE(tx_block_waddr(23 downto 16));
baddrh_par <= XOR_REDUCE(tx_block_waddr(15 downto 8));
baddrl_par <= XOR_REDUCE(tx_block_waddr( 7 downto 0));
baddrl_par <= XOR_REDUCE(tx_block_waddr(7 downto 0));
raddre_par <= XOR_REDUCE(rx_byte_raddr(23 downto 16));
raddrh_par <= XOR_REDUCE(rx_byte_raddr(15 downto 8));
raddrl_par <= XOR_REDUCE(rx_byte_raddr( 7 downto 0));
raddrl_par <= XOR_REDUCE(rx_byte_raddr(7 downto 0));
tx_byte_par <= XOR_REDUCE(tx_byte_byte);
push_byte_par <= XOR_REDUCE(push_byte);
-- Construct the various command bit patterns
tx_wr_frame <= '0' & "010" & '1' & '1' & -- CMD
'0' & "00000001" & '1' & '1' & -- N (1 byte)
'0' & tx_byte_waddr(23 downto 16) & waddre_par & '1' & -- ADDR @E
'0' & tx_byte_waddr(15 downto 8) & waddrh_par & '1' & -- ADDR @H
'0' & tx_byte_waddr( 7 downto 0) & waddrl_par & '1' & -- ADDR @L
'0' & tx_byte_byte & tx_byte_par & '1'; -- D0
tx_rd_frame <= "00000000000" & -- Padding
'0' & "001" & '1' & '1' & -- CMD
'0' & "00000001" & '1' & '1' & -- N (1 byte)
'0' & rx_byte_raddr(23 downto 16) & raddre_par & '1' & -- ADDR @E
'0' & rx_byte_raddr(15 downto 8) & raddrh_par & '1' & -- ADDR @H
'0' & rx_byte_raddr( 7 downto 0) & raddrl_par & '1'; -- ADDR @L
blk_wr_frame <= "00000000000" & -- Padding
'0' & "010" & '1' & '1' & -- CMD
'0' & "10000000" & '1' & '1' & -- N (128 bytes)
'0' & tx_block_waddr(23 downto 16) & baddre_par & '1' & -- ADDR @E
'0' & tx_block_waddr(15 downto 8) & baddrh_par & '1' & -- ADDR @H
'0' & tx_block_waddr( 7 downto 0) & baddrl_par & '1'; -- ADDR @L
push_wr_frame <= "00000000000000000000000000000000000000000000000000"& -- Padding
'0' & push_byte & push_byte_par & '1'; -- Dn
tx_wr_frame <= '0' & "010" & '1' & '1' & -- CMD
'0' & "00000001" & '1' & '1' & -- N (1 byte)
'0' & tx_byte_waddr(23 downto 16) & waddre_par & '1' & -- ADDR @E
'0' & tx_byte_waddr(15 downto 8) & waddrh_par & '1' & -- ADDR @H
'0' & tx_byte_waddr(7 downto 0) & waddrl_par & '1' & -- ADDR @L
'0' & tx_byte_byte & tx_byte_par & '1'; -- D0
tx_rd_frame <= "00000000000" & -- Padding
'0' & "001" & '1' & '1' & -- CMD
'0' & "00000001" & '1' & '1' & -- N (1 byte)
'0' & rx_byte_raddr(23 downto 16) & raddre_par & '1' & -- ADDR @E
'0' & rx_byte_raddr(15 downto 8) & raddrh_par & '1' & -- ADDR @H
'0' & rx_byte_raddr(7 downto 0) & raddrl_par & '1'; -- ADDR @L
blk_wr_frame <= "00000000000" & -- Padding
'0' & "010" & '1' & '1' & -- CMD
'0' & "10000000" & '1' & '1' & -- N (128 bytes)
'0' & tx_block_waddr(23 downto 16) & baddre_par & '1' & -- ADDR @E
'0' & tx_block_waddr(15 downto 8) & baddrh_par & '1' & -- ADDR @H
'0' & tx_block_waddr(7 downto 0) & baddrl_par & '1'; -- ADDR @L
push_wr_frame <= "00000000000000000000000000000000000000000000000000" & -- Padding
'0' & push_byte & push_byte_par & '1'; -- Dn
sys_rst_frame <= "0000000000000000000000000000000000000000000000000000000" &
'0' & "000" & '0' & '1'; -- CMD
'0' & "000" & '0' & '1'; -- CMD
tx_wr_ack_pos <= "0000010000000000100000000001000000000010000000000100000000001";
tx_rd_ack_pos <= "0000000000000000100000000001000000000010000000000100000000001";
@ -476,8 +476,8 @@ begin
-- Select which timing pulse to use for transmission
-- depending on the active mode.
tick_active <= tick_4KHz when entry_active = '1' else
bit_clk when tx_bit_active = '1' else '0';
tick_active <= tick_4KHz when entry_active = '1' else
bit_clk when tx_bit_active = '1' else '0';
tx_ack_slot <= tx_shift_ack_reg(to_integer(unsigned(tx_shift_count))) and tx_bit_active;
@ -486,54 +486,54 @@ begin
-----------------------------------------
TX_BITS_PROC : process(clk, reset_n) is
procedure rst_tx is
begin
tx_bits_count <= (others => '0');
swim_out <= '1';
op_active <= '0';
tx_bit_active <= '0';
seen_tx_ack_rising <= '0';
entry_active <= '0';
tx_shift_reg <= (others => '0');
tx_shift_ack_reg <= (others => '0');
tx_shift_count <= (others => '0');
tx_shift_retry_pos <= (others => '0');
tx_retry_count <= (others => '0');
status_tx_error <= '0';
status_tx_nak_error <= '0';
swim_in_sync <= "11";
tx_byte_waddr_reg <= (others => '0');
tx_byte_byte_reg <= (others => '0');
rx_byte_raddr_reg <= (others => '0');
blk_remaining <= (others => '0');
tx_block_waddr_reg <= (others => '0');
rx_ack_slot <= '0';
procedure rst_tx is
begin
tx_bits_count <= (others => '0');
swim_out <= '1';
op_active <= '0';
tx_bit_active <= '0';
seen_tx_ack_rising <= '0';
entry_active <= '0';
tx_shift_reg <= (others => '0');
tx_shift_ack_reg <= (others => '0');
tx_shift_count <= (others => '0');
tx_shift_retry_pos <= (others => '0');
tx_retry_count <= (others => '0');
status_tx_error <= '0';
status_tx_nak_error <= '0';
swim_in_sync <= "11";
tx_byte_waddr_reg <= (others => '0');
tx_byte_byte_reg <= (others => '0');
rx_byte_raddr_reg <= (others => '0');
blk_remaining <= (others => '0');
tx_block_waddr_reg <= (others => '0');
rx_ack_slot <= '0';
end procedure;
end procedure;
begin
if reset_n = '0' then
-- Reset state
rst_tx;
-- State not cleared by a 'reset state' control register write
status_entry_seq_sent <= '0';
elsif (clk'event and clk = '1') then
swim_in_sync <= swim_in & swim_in_sync(1);
swim_in_sync <= swim_in & swim_in_sync(1);
-- Clear all the TX state at the request over the Avalon slave interface
if control_reset_state = '1' then
rst_tx;
else
-- Flag that a rising edge has been seen during a TX ACK slot.
seen_tx_ack_rising <= seen_tx_ack_rising or (tx_ack_slot and rx_rising_edge);
-- Once the ack bit gone, clear any RX ACK slot
if tx_bits_count = zero(3 downto 0) then
rx_ack_slot <= '0';
rx_ack_slot <= '0';
end if;
-- Request from receiver for an RX ack
@ -542,15 +542,15 @@ begin
tx_shift_ack_reg(0) <= '0';
rx_ack_slot <= '1';
if active_hi_speed = '0' then
tx_bits_count <= LONG_LENGTH;
tx_bits_count <= LONG_LENGTH;
else
tx_bits_count <= SHORT_LENGTH;
end if;
tx_bits_count <= SHORT_LENGTH;
end if;
end if;
-- If timed out whilst transmitting, flag an error
if status_txbusy = '1' and timed_out = '1' then
status_tx_error <= '1';
status_tx_error <= '1';
end if;
-- Update the transmission bit count only on the 4MHz tick pulse
@ -561,14 +561,14 @@ begin
-- The count of the transmission bits is dependent on the speed mode
if active_hi_speed = '0' then
tx_bits_count <= LONG_LENGTH;
tx_bits_count <= LONG_LENGTH;
else
tx_bits_count <= SHORT_LENGTH;
tx_bits_count <= SHORT_LENGTH;
end if;
-- If the TX shift register count is about the go to 0, clear the op_active state
if (tx_shift_count = zero(5 downto 0)) then
op_active <= '0';
op_active <= '0';
end if;
-- If the TX bit counter is not zero, keep decrementing to the end of the bit
@ -579,14 +579,14 @@ begin
-- Generate an active TX state, aligned to the bit clock pulse.
if bit_clk = '1' then
tx_bit_active <= op_active;
tx_bit_active <= op_active;
end if;
-- On active TX clock, decrement the shift counter until 0
if tick_active = '1' then
seen_tx_ack_rising <= '0';
seen_tx_ack_rising <= '0';
if tx_shift_count /= zero(5 downto 0) then
tx_shift_count <= std_logic_vector(unsigned(tx_shift_count) - 1);
tx_shift_count <= std_logic_vector(unsigned(tx_shift_count) - 1);
else
-- Clear the entry status, and export that the entry sequence is sent.
entry_active <= '0';
@ -600,49 +600,49 @@ begin
if op_active = '0' and entry_active = '0' then
if tx_byte_pulse = '1' then
tx_shift_reg <= tx_wr_frame;
tx_shift_ack_reg <= tx_wr_ack_pos;
tx_shift_count <= std_logic_vector(to_unsigned(WRITE_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(WRITE_CMD_LEN_M1, 6));
tx_byte_waddr_reg <= tx_byte_waddr;
tx_byte_byte_reg <= tx_byte_byte;
op_active <= '1';
tx_shift_reg <= tx_wr_frame;
tx_shift_ack_reg <= tx_wr_ack_pos;
tx_shift_count <= std_logic_vector(to_unsigned(WRITE_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(WRITE_CMD_LEN_M1, 6));
tx_byte_waddr_reg <= tx_byte_waddr;
tx_byte_byte_reg <= tx_byte_byte;
op_active <= '1';
end if;
if rx_byte_pulse = '1' then
tx_shift_reg <= tx_rd_frame;
tx_shift_count <= std_logic_vector(to_unsigned(READ_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(READ_CMD_LEN_M1, 6));
tx_shift_ack_reg <= tx_rd_ack_pos;
rx_byte_raddr_reg <= rx_byte_raddr;
op_active <= '1';
tx_shift_reg <= tx_rd_frame;
tx_shift_count <= std_logic_vector(to_unsigned(READ_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(READ_CMD_LEN_M1, 6));
tx_shift_ack_reg <= tx_rd_ack_pos;
rx_byte_raddr_reg <= rx_byte_raddr;
op_active <= '1';
end if;
if tx_block_pulse = '1' then
tx_shift_reg <= blk_wr_frame;
tx_shift_count <= std_logic_vector(to_unsigned(BLK_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(BLK_CMD_LEN_M1, 6));
tx_shift_ack_reg <= blk_wr_ack_pos;
tx_block_waddr_reg <= tx_block_waddr;
blk_remaining <= std_logic_vector(to_unsigned(128, 8));
op_active <= '1';
tx_shift_reg <= blk_wr_frame;
tx_shift_count <= std_logic_vector(to_unsigned(BLK_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(BLK_CMD_LEN_M1, 6));
tx_shift_ack_reg <= blk_wr_ack_pos;
tx_block_waddr_reg <= tx_block_waddr;
blk_remaining <= std_logic_vector(to_unsigned(128, 8));
op_active <= '1';
end if;
if push_byte_pulse = '1' and blk_remaining /= 8x"00" then
tx_shift_reg <= push_wr_frame;
tx_shift_count <= std_logic_vector(to_unsigned(BLK_BYTE_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(BLK_BYTE_LEN_M1, 6));
tx_shift_ack_reg <= blk_wr_ack_pos;
blk_remaining <= std_logic_vector(unsigned(blk_remaining) - 1);
op_active <= '1';
tx_shift_reg <= push_wr_frame;
tx_shift_count <= std_logic_vector(to_unsigned(BLK_BYTE_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(BLK_BYTE_LEN_M1, 6));
tx_shift_ack_reg <= blk_wr_ack_pos;
blk_remaining <= std_logic_vector(unsigned(blk_remaining) - 1);
op_active <= '1';
end if;
if (control_send_srst = '1') then
tx_shift_reg <= sys_rst_frame;
tx_shift_ack_reg <= sys_rst_ack_pos;
tx_shift_count <= std_logic_vector(to_unsigned(SRST_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(SRST_CMD_LEN_M1, 6));
op_active <= '1';
tx_shift_reg <= sys_rst_frame;
tx_shift_ack_reg <= sys_rst_ack_pos;
tx_shift_count <= std_logic_vector(to_unsigned(SRST_CMD_LEN_M1, 6));
tx_shift_retry_pos <= std_logic_vector(to_unsigned(SRST_CMD_LEN_M1, 6));
op_active <= '1';
end if;
if (control_send_entry_seq = '1') then
@ -657,37 +657,37 @@ begin
if seen_tx_ack_rising = '1' then
-- if a NACK, put the shift count back to the last retry position
if rx_shift_register(0) = '0' then
tx_shift_count <= tx_shift_retry_pos;
tx_retry_count <= std_logic_vector(unsigned(tx_retry_count) + 1);
tx_shift_count <= tx_shift_retry_pos;
tx_retry_count <= std_logic_vector(unsigned(tx_retry_count) + 1);
else
tx_shift_retry_pos <= std_logic_vector(unsigned(tx_shift_count) - 1);
tx_retry_count <= (others => '0');
end if;
else
status_tx_nak_error <= '1';
status_tx_error <= '1';
status_tx_nak_error <= '1';
status_tx_error <= '1';
end if;
end if;
-- Check for retry timeout, if enabled
if control_tx_retry_timeout /= zero(7 downto 0) and
tx_retry_count = control_tx_retry_timeout then
status_tx_error <= '1';
op_active <= '0';
tx_bit_active <= '0';
tx_retry_count = control_tx_retry_timeout then
status_tx_error <= '1';
op_active <= '0';
tx_bit_active <= '0';
elsif control_clear_errors = '1' then
status_tx_error <= '0';
status_tx_nak_error <= '0';
status_tx_error <= '0';
status_tx_nak_error <= '0';
end if;
-- The SWIM output is either the entry sequence or the TX bits, depending
-- on which output is active. Set the output to 1 when TX is idle.
if entry_active = '1' then
if entry_active = '1' then
swim_out <= tx_shift_reg(to_integer(unsigned(tx_shift_count)));
elsif tx_bit_active = '1' or rx_ack_slot = '1' then
swim_out <= tx_bits(to_integer(unsigned(tx_bits_count))) or tx_ack_slot;
swim_out <= tx_bits(to_integer(unsigned(tx_bits_count))) or tx_ack_slot;
else
swim_out <= '1';
swim_out <= '1';
end if;
end if;
end if;
@ -698,31 +698,32 @@ begin
-----------------------------------------
-- Generate a pulse at the rising and falling of the SWIM input
rx_falling_edge <= not swim_in_sync(0) and swim_in_last;
rx_rising_edge <= swim_in_sync(0) and not swim_in_last;
rx_falling_edge <= not swim_in_sync(0) and swim_in_last;
rx_rising_edge <= swim_in_sync(0) and not swim_in_last;
-- Calculate the RX parity from the shift register
rx_parity <= XOR_REDUCE(rx_shift_register(7 downto 0));
rx_parity <= XOR_REDUCE(rx_shift_register(7 downto 0));
RX_BITS_PROC : process(clk, reset_n) is
procedure rst_tx is
begin
procedure rst_tx is
begin
swim_in_last <= '1';
receiving_bit <= '0';
rx_bit_count <= (others => '0');
rx_idx <= 4x"0A";
status_rx_error <= '0';
rx_expecting_byte <= '0';
status_rx_ready <= '0';
send_rx_ack <= '0';
rx_ack_delay <= (others => '0');
rx_nacked <= '0';
swim_in_last <= '1';
receiving_bit <= '0';
rx_bit_count <= (others => '0');
rx_idx <= 4x"0A";
status_rx_error <= '0';
rx_expecting_byte <= '0';
status_rx_ready <= '0';
send_rx_ack <= '0';
rx_ack_delay <= (others => '0');
rx_nacked <= '0';
rx_shift_register <= (others => '0');
end procedure;
end procedure;
variable rx_bit_var : std_logic;
variable rx_bit_var : std_logic;
begin
if reset_n = '0' then
@ -736,14 +737,14 @@ begin
else
-- Signal is a pulse
send_rx_ack <= '0';
send_rx_ack <= '0';
-- Generate a delayed swim_in for use in edge detection;
swim_in_last <= swim_in_sync(0);
-- Flag as receiving a bit between rising and falling edges,
-- when expecting a byte and TX is idle
receiving_bit <= (receiving_bit or rx_falling_edge) and not rx_rising_edge and
receiving_bit <= (receiving_bit or rx_falling_edge) and not rx_rising_edge and
(rx_expecting_byte or (tx_ack_slot and tx_bit_active)) and
not entry_active;
@ -751,23 +752,23 @@ begin
-- but flag an error if already busy
if rx_byte_pulse = '1' then
if rx_expecting_byte = '1' then
status_rx_error <= '1';
status_rx_error <= '1';
else
rx_expecting_byte <= '1';
rx_expecting_byte <= '1';
end if;
-- Always clear rx_expecting_byte state when seen an error.
elsif status_rx_error = '1' then
rx_expecting_byte <= '0';
rx_expecting_byte <= '0';
end if;
-- If timed out waiting for a byte
if rx_expecting_byte = '1' and timed_out = '1' then
status_rx_error <= '1';
status_rx_error <= '1';
end if;
-- Whilst receiving a bit, increment the bit counter
if receiving_bit = '1' then
rx_bit_count <= std_logic_vector(unsigned(rx_bit_count) + 1);
rx_bit_count <= std_logic_vector(unsigned(rx_bit_count) + 1);
end if;
-- If we see a rising edge on the swim input, determine if
@ -782,7 +783,7 @@ begin
end if;
-- Shift the bit onto the shift register
rx_shift_register <= rx_shift_register(9 downto 0) & rx_bit_var;
rx_shift_register <= rx_shift_register(9 downto 0) & rx_bit_var;
if receiving_bit = '1' and tx_bit_active = '0' then
@ -790,23 +791,23 @@ begin
-- otherwise reset to count the bits for a RX byte, and clear the receiver
-- active state
if unsigned(rx_idx) > 0 then
rx_idx <= std_logic_vector(unsigned(rx_idx) - 1);
rx_idx <= std_logic_vector(unsigned(rx_idx) - 1);
else
rx_idx <= std_logic_vector(to_unsigned(SWIM_BITS_PER_BYTE, 4));
rx_expecting_byte <= rx_nacked; -- Still expecting a byte if NAKed
status_rx_ready <= not rx_nacked; -- Byte ready if ACKed (not NAKed)
rx_nacked <= '0'; -- Clear naked state for retry.
rx_idx <= std_logic_vector(to_unsigned(SWIM_BITS_PER_BYTE, 4));
rx_expecting_byte <= rx_nacked; -- Still expecting a byte if NAKed
status_rx_ready <= not rx_nacked; -- Byte ready if ACKed (not NAKed)
rx_nacked <= '0'; -- Clear naked state for retry.
end if;
-- Last bit in byte
if rx_idx = one(3 downto 0) then
-- See out the rest of the bit slot after the parity bit is received
if rx_bit_var = '1' then
rx_ack_delay <= 4x"A";
else
rx_ack_delay <= 4x"1";
end if;
-- See out the rest of the bit slot after the parity bit is received
if rx_bit_var = '1' then
rx_ack_delay <= 4x"A";
else
rx_ack_delay <= 4x"1";
end if;
-- Check for parity errors
if rx_parity /= rx_bit_var then
send_rx_ack_data <= '0';
@ -819,13 +820,13 @@ begin
end if;
-- At the boundary of each bit, reset the bit counter
rx_bit_count <= (others => '0');
rx_bit_count <= (others => '0');
end if;
-- At 4MHz boundaries, whilst the RX ACK delay is not zero, decrement it.
if tick_4MHz = '1' and rx_ack_delay /= zero(3 downto 0) then
rx_ack_delay <= std_logic_vector(unsigned(rx_ack_delay) - 1);
rx_ack_delay <= std_logic_vector(unsigned(rx_ack_delay) - 1);
-- When about to go to zero, request the TX to send the ACK/NAK
if rx_ack_delay = one(3 downto 0) then
send_rx_ack <= '1';
@ -834,15 +835,15 @@ begin
-- Clear RX error if requested
if control_clear_errors = '1' then
status_rx_error <= '0';
status_rx_error <= '0';
end if;
-- Clear RX status if requested
if control_clr_rx = '1' then
status_rx_ready <= '0';
status_rx_ready <= '0';
end if;
end if;
end if;
end process;
end architecture rtl;
end architecture rtl;