]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - rx_control.vhd
Resets changed from asynchronous to synchronous.
[fpga/uart.git] / rx_control.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 entity rx_control is
7   port (
8     clk           : in  std_logic;
9     reset         : in  std_logic;
10     rx            : in  std_logic;
11     bad_start_bit : in  std_logic;
12     bad_stop_bit  : in  std_logic;
13     rx_ready      : in  std_logic;
14     rx_reset      : out std_logic := '0';
15     rx_en         : out std_logic := '0';
16     fifo_we       : out std_logic := '0';
17     clk_en        : out std_logic := '0');
18 end entity rx_control;
19
20 --------------------------------------------------------------------------------
21
22 architecture behavioral of rx_control is
23
24   type state_t is (resetting, waiting, next_frame, receiving);
25
26   signal state : state_t := waiting;
27
28 --------------------------------------------------------------------------------
29
30 begin
31
32   process (clk, reset) is
33   begin
34     if clk'event and clk = '1' then
35       if reset = '1' then
36         state    <= waiting;
37         rx_reset <= '0';
38         rx_en    <= '0';
39         fifo_we  <= '0';
40         clk_en   <= '0';
41
42       else
43         case state is
44           when resetting =>
45             state    <= waiting;
46             rx_reset <= '0';
47             rx_en    <= '0';
48             fifo_we  <= '0';
49             clk_en   <= '0';
50
51
52           when waiting =>
53             rx_reset <= '0';
54             rx_en    <= '0';
55             fifo_we  <= '0';
56             clk_en   <= '0';
57
58             if rx = '0' then
59               state  <= next_frame;
60               rx_en  <= '1';
61               clk_en <= '1';
62             end if;
63
64
65           when next_frame =>
66             rx_reset <= '0';
67             rx_en    <= '1';
68             fifo_we  <= '0';
69             clk_en   <= '1';
70
71             if rx_ready = '0' then
72               if bad_start_bit = '1' then
73                 state    <= resetting;
74                 rx_reset <= '1';
75                 rx_en    <= '0';
76                 clk_en   <= '0';
77
78               else
79                 state <= receiving;
80                 rx_en <= '0';
81               end if;
82             end if;
83
84
85           when receiving =>
86             rx_reset <= '0';
87             rx_en    <= '0';
88             fifo_we  <= '0';
89             clk_en   <= '1';
90
91             if rx_ready = '1' then
92               state   <= waiting;
93               fifo_we <= '1';
94               clk_en  <= '0';
95             end if;
96
97         end case;
98       end if;
99     end if;
100   end process;
101
102 end architecture behavioral;
103