]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx_control.vhd
Baud_gen scale input width redefined as generic. Default value is 16.
[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 entity tx_control is
7   port (
8     clk        : in  std_logic;
9     reset      : in  std_logic;
10     tx_ready   : in  std_logic;
11     fifo_empty : in  std_logic;
12     tx_we      : out std_logic;
13     fifo_pop   : out std_logic
14   );
15 end tx_control;
16
17 --------------------------------------------------------------------------------
18
19 architecture behavioral of tx_control is
20   
21   type state_t is (waiting, next_frame, transmitting);
22   
23   signal state : state_t;
24
25 --------------------------------------------------------------------------------
26
27 begin
28
29   process (clk, reset)
30   begin
31     if (reset = '1') then
32       state <= waiting;
33       
34     elsif (rising_edge(clk)) then
35       case state is
36         when waiting =>
37           if (fifo_empty = '0') then
38             state <= next_frame;
39           end if;
40         
41         when next_frame =>
42           if (tx_ready = '0') then
43             state <= transmitting;
44           end if;
45         
46         when transmitting =>
47           if (tx_ready = '1') then
48             if (fifo_empty = '0') then
49               state <= next_frame;
50             else
51               state <= waiting;
52             end if;
53           end if;
54       end case;
55     end if;
56   end process;
57
58
59   process (state, tx_ready)
60   begin
61     case state is
62       when waiting =>
63         tx_we <= '0';
64         fifo_pop <= '0';
65         
66       when next_frame =>
67         tx_we <= '1';
68         if (tx_ready = '0') then
69           fifo_pop <= '1';
70         else
71           fifo_pop <= '0';
72         end if;
73
74       when transmitting =>
75         tx_we <= '0';
76         fifo_pop <= '0';
77     end case;
78   end process;
79
80 --------------------------------------------------------------------------------
81
82 end behavioral;
83