]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - rx_control.vhd
Receiver control FSM prototype.
[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;
15     rx_en         : out std_logic;
16     fifo_we       : out std_logic;
17     clk_en        : out std_logic);
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;
27
28 --------------------------------------------------------------------------------
29
30 begin
31
32   process (clk, reset) is
33   begin
34     if reset = '1' then
35       state    <= waiting;
36       rx_reset <= '0';
37       rx_en    <= '0';
38       fifo_we  <= '0';
39       clk_en   <= '0';
40
41     elsif clk'event and clk = '1' then
42       case state is
43         when resetting =>
44           state    <= waiting;
45           rx_reset <= '0';
46           rx_en    <= '0';
47           fifo_we  <= '0';
48           clk_en   <= '0';
49
50
51         when waiting =>
52           rx_reset <= '0';
53           rx_en    <= '0';
54           fifo_we  <= '0';
55           clk_en   <= '0';
56
57           if rx = '0' then
58             state  <= next_frame;
59             rx_en  <= '1';
60             clk_en <= '1';
61           end if;
62
63
64         when next_frame =>
65           rx_reset <= '0';
66           rx_en    <= '1';
67           fifo_we  <= '0';
68           clk_en   <= '1';
69
70           if rx_ready = '0' then
71             if bad_start_bit = '1' then
72               state    <= resetting;
73               rx_reset <= '1';
74               rx_en    <= '0';
75               clk_en   <= '0';
76
77             else
78               state <= receiving;
79               rx_en <= '0';
80             end if;
81           end if;
82
83
84         when receiving =>
85           rx_reset <= '0';
86           rx_en    <= '0';
87           fifo_we  <= '0';
88           clk_en   <= '1';
89
90           if rx_ready = '1' then
91             state   <= waiting;
92             fifo_we <= '1';
93             clk_en  <= '0';
94           end if;
95
96       end case;
97     end if;
98   end process;
99
100 end architecture behavioral;
101