]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx_control.vhd
Resets changed from asynchronous to synchronous.
[fpga/uart.git] / tx_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 --------------------------------------------------------------------------------
7 -- Transmitter control FSM
8 --
9 -- Finite state machine controlling interconnection of FIFO buffer and output
10 -- shift register.
11 --------------------------------------------------------------------------------
12
13 entity tx_control is
14   port (
15     clk        : in  std_logic;
16     reset      : in  std_logic;
17     tx_ready   : in  std_logic;
18     fifo_empty : in  std_logic;
19     tx_we      : out std_logic;
20     fifo_pop   : out std_logic
21   );
22 end tx_control;
23
24 --------------------------------------------------------------------------------
25
26 architecture behavioral of tx_control is
27   
28   type state_t is (waiting, next_frame, transmitting);
29   
30   signal state : state_t := waiting;
31
32 --------------------------------------------------------------------------------
33
34 begin
35
36   process (clk, reset)
37   begin
38     if (rising_edge(clk)) then
39       if (reset = '1') then
40         state <= waiting;
41
42       else
43         case state is
44           when waiting =>
45             if (fifo_empty = '0') then
46               state <= next_frame;
47             end if;
48           
49           when next_frame =>
50             if (tx_ready = '0') then
51               state <= transmitting;
52             end if;
53           
54           when transmitting =>
55             if (tx_ready = '1') then
56               if (fifo_empty = '0') then
57                 state <= next_frame;
58               else
59                 state <= waiting;
60               end if;
61             end if;
62         end case;
63       end if;
64     end if;
65   end process;
66
67
68   process (state, tx_ready)
69   begin
70     case state is
71       when waiting =>
72         tx_we <= '0';
73         fifo_pop <= '0';
74         
75       when next_frame =>
76         tx_we <= '1';
77         if (tx_ready = '0') then
78           fifo_pop <= '1';
79         else
80           fifo_pop <= '0';
81         end if;
82
83       when transmitting =>
84         tx_we <= '0';
85         fifo_pop <= '0';
86     end case;
87   end process;
88
89 --------------------------------------------------------------------------------
90
91 end behavioral;
92