HMBFDHV-83 Comparison to zero and registering intermediate signal should help timing
This commit is contained in:
parent
8999a043a4
commit
d752c59a09
1 changed files with 40 additions and 39 deletions
|
|
@ -25,21 +25,21 @@ entity uart_rx_1 is
|
|||
port(
|
||||
reset_n : in std_logic;
|
||||
clk : in std_logic;
|
||||
bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit
|
||||
bit_div : in std_logic_vector(3 downto 0); -- number of clock cycles per tx bit
|
||||
init : in std_logic;
|
||||
data_out : out std_logic_vector(data_width-1 downto 0);
|
||||
data_out : out std_logic_vector(data_width - 1 downto 0);
|
||||
data_out_valid : out std_logic;
|
||||
rx_error : out std_logic;
|
||||
rx_data : in std_logic);
|
||||
rx_data : in std_logic);
|
||||
end entity uart_rx_1;
|
||||
|
||||
architecture rtl of uart_rx_1 is
|
||||
|
||||
component sync_wire_1
|
||||
generic (
|
||||
generic(
|
||||
rst_val : std_logic;
|
||||
sync_stages : positive);
|
||||
port (
|
||||
port(
|
||||
rstN : in std_logic;
|
||||
clk : in std_logic;
|
||||
async_in : in std_logic;
|
||||
|
|
@ -48,16 +48,16 @@ architecture rtl of uart_rx_1 is
|
|||
|
||||
type fsm_state_t is (s_init, s_idle, s_get_start_bit, s_get_data, s_get_stop_bit);
|
||||
|
||||
signal fsm_state_curr, fsm_state_next : fsm_state_t;
|
||||
signal fsm_state_curr, fsm_state_next : fsm_state_t;
|
||||
--
|
||||
signal rx_data_i, shf_data, rst_bit_cnt, inc_bit_cnt : std_logic;
|
||||
signal rst_clk_cnt, end_of_bit, end_of_rx, data_valid : std_logic;
|
||||
signal stop_bit, rx_error_i : std_logic;
|
||||
--
|
||||
signal data : std_logic_vector(data_width-1 downto 0);
|
||||
signal clk_cnt : std_logic_vector(3 downto 0);
|
||||
signal bit_cnt : std_logic_vector(5 downto 0);
|
||||
|
||||
signal data : std_logic_vector(data_width - 1 downto 0);
|
||||
signal clk_cnt : std_logic_vector(3 downto 0);
|
||||
signal bit_cnt : std_logic_vector(5 downto 0);
|
||||
|
||||
begin
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
@ -65,10 +65,10 @@ begin
|
|||
-----------------------------------------------------------------------------
|
||||
|
||||
iSYNC_IN : sync_wire_1
|
||||
generic map (
|
||||
generic map(
|
||||
rst_val => '1',
|
||||
sync_stages => 3)
|
||||
port map (
|
||||
port map(
|
||||
rstN => reset_n,
|
||||
clk => clk,
|
||||
async_in => rx_data,
|
||||
|
|
@ -80,38 +80,39 @@ begin
|
|||
|
||||
pREGs : process(clk)
|
||||
begin
|
||||
if(clk ='1' and clk'event) then
|
||||
if(rst_bit_cnt = '1') then
|
||||
if (clk = '1' and clk'event) then
|
||||
if (rst_bit_cnt = '1') then
|
||||
bit_cnt <= (others => '0');
|
||||
elsif(inc_bit_cnt = '1') then
|
||||
bit_cnt <= std_logic_vector(unsigned(bit_cnt)+1);
|
||||
elsif (inc_bit_cnt = '1') then
|
||||
bit_cnt <= std_logic_vector(unsigned(bit_cnt) + 1);
|
||||
end if;
|
||||
if(rst_clk_cnt = '1' or end_of_bit = '1') then
|
||||
clk_cnt <= (others => '0');
|
||||
shf_data <= '0';
|
||||
if clk_cnt = std_logic_vector(unsigned(bit_div(bit_div'high downto 1)) + 1) and stop_bit = '0' then
|
||||
shf_data <= '1';
|
||||
end if;
|
||||
if (rst_clk_cnt = '1' or end_of_bit = '1') then
|
||||
clk_cnt <= std_logic_vector(unsigned(bit_div) - 1);
|
||||
else
|
||||
clk_cnt <= std_logic_vector(unsigned(clk_cnt)+1);
|
||||
clk_cnt <= std_logic_vector(unsigned(clk_cnt) - 1);
|
||||
end if;
|
||||
if(rst_clk_cnt = '1') then
|
||||
if (rst_clk_cnt = '1') then
|
||||
data <= (others => '0');
|
||||
elsif(shf_data = '1') then
|
||||
elsif (shf_data = '1') then
|
||||
data <= rx_data_i & data(data'high downto 1);
|
||||
end if;
|
||||
data_out_valid <= data_valid;
|
||||
if(init = '1') then
|
||||
if (init = '1') then
|
||||
data_out <= (others => '0');
|
||||
elsif(data_valid = '1') then
|
||||
elsif (data_valid = '1') then
|
||||
data_out <= data;
|
||||
end if;
|
||||
rx_error <= rx_error_i;
|
||||
rx_error <= rx_error_i;
|
||||
end if;
|
||||
end process pREGs;
|
||||
|
||||
end_of_bit <= '1' when unsigned(clk_cnt) = (unsigned(bit_div)-1) else '0';
|
||||
end_of_bit <= '1' when unsigned(clk_cnt) = 0 else '0';
|
||||
end_of_rx <= '1' when unsigned(bit_cnt) = data_width else '0';
|
||||
|
||||
--shf_data <= '1' when unsigned(clk_cnt) = 1 and stop_bit = '0' else '0';
|
||||
shf_data <= '1' when unsigned(clk_cnt) = (unsigned(bit_div(bit_div'high downto 1))-1) and stop_bit = '0' else '0';
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- FSM
|
||||
-----------------------------------------------------------------------------
|
||||
|
|
@ -119,15 +120,15 @@ begin
|
|||
-- FSM state register
|
||||
pFSM_SR : process(clk)
|
||||
begin
|
||||
if(clk = '1' and clk'event) then
|
||||
if(init = '1') then
|
||||
if (clk = '1' and clk'event) then
|
||||
if (init = '1') then
|
||||
fsm_state_curr <= s_init;
|
||||
else
|
||||
fsm_state_curr <= fsm_state_next;
|
||||
end if;
|
||||
end if;
|
||||
end process pFSM_SR;
|
||||
|
||||
|
||||
-- FSM Combinational Logic
|
||||
pFSM_CL : process(fsm_state_curr, rx_data_i, end_of_bit, end_of_rx)
|
||||
begin
|
||||
|
|
@ -143,35 +144,35 @@ begin
|
|||
|
||||
case fsm_state_curr is
|
||||
when s_init =>
|
||||
if(rx_data_i = '1') then
|
||||
if (rx_data_i = '1') then
|
||||
fsm_state_next <= s_idle;
|
||||
end if;
|
||||
|
||||
|
||||
when s_idle =>
|
||||
if(rx_data_i = '0') then
|
||||
if (rx_data_i = '0') then
|
||||
rst_clk_cnt <= '1';
|
||||
rst_bit_cnt <= '1';
|
||||
fsm_state_next <= s_get_start_bit;
|
||||
end if;
|
||||
|
||||
when s_get_start_bit =>
|
||||
if(end_of_bit = '1') then
|
||||
if (end_of_bit = '1') then
|
||||
inc_bit_cnt <= '1';
|
||||
fsm_state_next <= s_get_data;
|
||||
end if;
|
||||
|
||||
when s_get_data =>
|
||||
if(end_of_bit = '1') then
|
||||
if (end_of_bit = '1') then
|
||||
inc_bit_cnt <= '1';
|
||||
if(end_of_rx = '1') then
|
||||
if (end_of_rx = '1') then
|
||||
fsm_state_next <= s_get_stop_bit;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
when s_get_stop_bit =>
|
||||
stop_bit <= '1';
|
||||
if(end_of_bit = '1') then
|
||||
if(rx_data_i = '1') then
|
||||
if (end_of_bit = '1') then
|
||||
if (rx_data_i = '1') then
|
||||
data_valid <= '1';
|
||||
fsm_state_next <= s_idle;
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue