]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx.vhd
aca961aedef674f265b2abf6db7da1d952ac8758
[fpga/uart.git] / tx.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 transmitter is
7   port (
8     clk    : in  std_logic;
9     reset  : in  std_logic;
10     data   : in  std_logic_vector (7 downto 0);
11     we     : in  std_logic;
12     ready  : out std_logic;
13     tx     : out std_logic
14   );
15 end transmitter;
16
17 --------------------------------------------------------------------------------
18
19 architecture dataflow of transmitter is
20   
21   -- Output shift register (containing also start and stop bit).
22   signal tx_shift_reg : std_logic_vector (9 downto 0);
23   -- Register parallel to the output shift register where '1' shows the last
24   -- bit of the frame ('1' is in the place of stop bit).
25   signal tx_flag      : std_logic_vector (9 downto 0);
26   -- Transmitting of new frame could be started with next tx_clk.
27   signal tx_ready     : std_logic;
28
29 --------------------------------------------------------------------------------
30
31 begin
32
33   process (clk, reset)
34   begin
35     if (reset = '1') then
36       tx_shift_reg <= "1111111111";
37       tx_flag <= "0000000000";
38       tx_ready <= '1';
39       
40     elsif (rising_edge(clk)) then
41       if (we = '1') then
42         tx_shift_reg <= '1' & data & '0';
43         tx_flag <= "1000000000";
44         tx_ready <= '0';
45         
46       else
47         tx_shift_reg <= '1' & tx_shift_reg(9 downto 1);
48         tx_flag <= '0' & tx_flag(9 downto 1);
49         
50         if (tx_flag(1) = '1') then
51           tx_ready <= '1';
52         end if;
53         
54       end if;
55     end if;
56   end process;
57
58 --------------------------------------------------------------------------------
59
60   ready <= tx_ready;
61   
62   tx <= tx_shift_reg(0);
63   
64 end dataflow;
65