]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx_control.vhd
First prototype of receiver shift register.
[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;
31
32 --------------------------------------------------------------------------------
33
34 begin
35
36   process (clk, reset)
37   begin
38     if (reset = '1') then
39       state <= waiting;
40       
41     elsif (rising_edge(clk)) then
42       case state is
43         when waiting =>
44           if (fifo_empty = '0') then
45             state <= next_frame;
46           end if;
47         
48         when next_frame =>
49           if (tx_ready = '0') then
50             state <= transmitting;
51           end if;
52         
53         when transmitting =>
54           if (tx_ready = '1') then
55             if (fifo_empty = '0') then
56               state <= next_frame;
57             else
58               state <= waiting;
59             end if;
60           end if;
61       end case;
62     end if;
63   end process;
64
65
66   process (state, tx_ready)
67   begin
68     case state is
69       when waiting =>
70         tx_we <= '0';
71         fifo_pop <= '0';
72         
73       when next_frame =>
74         tx_we <= '1';
75         if (tx_ready = '0') then
76           fifo_pop <= '1';
77         else
78           fifo_pop <= '0';
79         end if;
80
81       when transmitting =>
82         tx_we <= '0';
83         fifo_pop <= '0';
84     end case;
85   end process;
86
87 --------------------------------------------------------------------------------
88
89 end behavioral;
90