Line 45... |
Line 45... |
-- RX Signals
|
-- RX Signals
|
signal rx_fsm : state; -- Control of reception
|
signal rx_fsm : state; -- Control of reception
|
signal rx_clk_en : std_logic; -- Received clock enable
|
signal rx_clk_en : std_logic; -- Received clock enable
|
signal rx_rcv_init : std_logic; -- Start of reception
|
signal rx_rcv_init : std_logic; -- Start of reception
|
signal rx_par_bit : std_logic; -- Calculated Parity bit
|
signal rx_par_bit : std_logic; -- Calculated Parity bit
|
|
signal rx_data_deb : std_logic; -- Debounce RX data
|
signal rx_data_tmp : std_logic_vector(7 downto 0); -- Serial to parallel converter
|
signal rx_data_tmp : std_logic_vector(7 downto 0); -- Serial to parallel converter
|
signal rx_data_cnt : std_logic_vector(2 downto 0); -- Count received bits
|
signal rx_data_cnt : std_logic_vector(2 downto 0); -- Count received bits
|
|
|
-- TX Signals
|
-- TX Signals
|
signal tx_fsm : state; -- Control of transmission
|
signal tx_fsm : state; -- Control of transmission
|
Line 71... |
Line 72... |
tx_clk_en <= '0';
|
tx_clk_en <= '0';
|
counter := counter + 1;
|
counter := counter + 1;
|
end if;
|
end if;
|
-- Reset condition
|
-- Reset condition
|
if rst = RST_LVL then
|
if rst = RST_LVL then
|
tx_clk_en := '0';
|
tx_clk_en <= '0';
|
counter := 0;
|
counter := 0;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
Line 139... |
Line 140... |
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
rx_start_detect:process(clk)
|
rx_debounceer:process(clk)
|
variable deb_buf : std_logic_vector(3 downto 0);
|
variable deb_buf : std_logic_vector(3 downto 0);
|
variable deb_val : std_logic;
|
|
variable deb_old : std_logic;
|
|
begin
|
begin
|
if clk'event and clk = '1' then
|
if clk'event and clk = '1' then
|
-- Store previous debounce value
|
|
deb_old := deb_val;
|
|
-- Debounce logic
|
-- Debounce logic
|
if deb_buf = "0000" then
|
if deb_buf = "0000" then
|
deb_val := '0';
|
rx_data_deb <= '0';
|
elsif deb_buf = "1111" then
|
elsif deb_buf = "1111" then
|
deb_val := '1';
|
rx_data_deb <= '1';
|
end if;
|
end if;
|
-- Data storage to debounce
|
-- Data storage to debounce
|
deb_buf := deb_buf(2 downto 0) & rx;
|
deb_buf := deb_buf(2 downto 0) & rx;
|
|
end if;
|
|
end process;
|
|
|
-- Check RX idle state
|
rx_start_detect:process(clk)
|
if rx_fsm = idle then
|
variable rx_data_old : std_logic;
|
|
begin
|
|
if clk'event and clk = '1' then
|
-- Falling edge detection
|
-- Falling edge detection
|
if deb_old = '1' and deb_val = '0' then
|
if rx_data_old = '1' and rx_data_deb = '0' then
|
rx_rcv_init <= '1';
|
rx_rcv_init <= '1';
|
end if;
|
|
-- Default assignments
|
|
else
|
else
|
rx_rcv_init <= '0';
|
rx_rcv_init <= '0';
|
end if;
|
end if;
|
|
-- Default assignments
|
|
rx_data_old := rx_data_deb;
|
-- Reset condition
|
-- Reset condition
|
if rst = RST_LVL then
|
if rst = RST_LVL then
|
deb_old := '0';
|
rx_data_old := '0';
|
deb_val := '0';
|
|
deb_buf <= (others=>'0');
|
|
rx_rcv_init <= '0';
|
rx_rcv_init <= '0';
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end process;
|
|
|
|
|
rx_clk_gen:process(clk)
|
rx_clk_gen:process(clk)
|
variable counter : integer range 0 to conv_integer((CLK_FREQ*1_000_000)/SER_FREQ-1);
|
variable counter : integer range 0 to conv_integer((CLK_FREQ*1_000_000)/SER_FREQ-1);
|
begin
|
begin
|
if clk'event and clk = '1' then
|
if clk'event and clk = '1' then
|
-- Normal Operation
|
-- Normal Operation
|
if counter = (CLK_FREQ*1_000_000)/SER_FREQ-1 and rx_rcv_init = '1' then
|
if counter = (CLK_FREQ*1_000_000)/SER_FREQ-1 or rx_rcv_init = '1' then
|
rx_clk_en <= '1';
|
rx_clk_en <= '1';
|
counter := 0;
|
counter := 0;
|
else
|
else
|
rx_clk_en <= '0';
|
rx_clk_en <= '0';
|
counter := counter + 1;
|
counter := counter + 1;
|
Line 200... |
Line 199... |
end process;
|
end process;
|
|
|
rx_proc:process(clk)
|
rx_proc:process(clk)
|
begin
|
begin
|
if clk'event and clk = '1' then
|
if clk'event and clk = '1' then
|
if rx_clk_en = '1' then
|
|
-- Default values
|
-- Default values
|
rx_ready <= '0';
|
rx_ready <= '0';
|
|
-- Enable on UART rate
|
|
if rx_clk_en = '1' then
|
-- FSM description
|
-- FSM description
|
case rx_fsm is
|
case rx_fsm is
|
-- Wait to transfer data
|
-- Wait to transfer data
|
when idle =>
|
when idle =>
|
if rx_rcv_init = '1' then
|
if rx_data_deb = UART_START then
|
rx_fsm <= data;
|
rx_fsm <= data;
|
end if;
|
end if;
|
rx_par_bit <= '0';
|
rx_par_bit <= '0';
|
rx_data_cnt <= (others=>'0');
|
rx_data_cnt <= (others=>'0');
|
-- Data receive
|
-- Data receive
|