]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx.vhd
Resets changed from asynchronous to synchronous.
[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 --------------------------------------------------------------------------------
7 -- Output shift register
8 --
9 -- This entity can be used for generating of RS232 like output. Configuration is
10 -- hard wired as 8N1 (8 bits of data, no parity, 1 stop bit).
11 --
12 -- All operations (except for 'reset') are synchronous to 'clk' rising edges.
13 -- This clock signal also determines baud rate.
14 --
15 -- When 'ready' signal is high, next data vector can be written in by setting
16 -- 'we' signal.
17 --------------------------------------------------------------------------------
18
19 entity transmitter is
20   port (
21     clk    : in  std_logic;
22     reset  : in  std_logic;
23     data   : in  std_logic_vector (7 downto 0);
24     we     : in  std_logic;
25     ready  : out std_logic;
26     tx     : out std_logic
27   );
28 end transmitter;
29
30 --------------------------------------------------------------------------------
31
32 architecture behavioral of transmitter is
33   
34   -- Output shift register (containing also start and stop bit).
35   signal tx_shift_reg : std_logic_vector (9 downto 0) := "1111111111";
36   -- Register parallel to the output shift register where '1' shows the last
37   -- bit of the frame ('1' is in the place of stop bit).
38   signal tx_flag      : std_logic_vector (9 downto 0) := "0000000000";
39   -- Transmitting of new frame could be started with next clk.
40   signal tx_ready     : std_logic := '1';
41
42 --------------------------------------------------------------------------------
43
44 begin
45
46   process (clk, reset)
47   begin
48     if (rising_edge(clk)) then
49       if (reset = '1') then
50         tx_shift_reg <= "1111111111";
51         tx_flag <= "0000000000";
52         tx_ready <= '1';
53       
54       else  
55         if (we = '1') then
56           tx_shift_reg <= '1' & data & '0';
57           tx_flag <= "1000000000";
58           tx_ready <= '0';
59           
60         else
61           tx_shift_reg <= '1' & tx_shift_reg(9 downto 1);
62           tx_flag <= '0' & tx_flag(9 downto 1);
63           
64           if (tx_flag(1) = '1') then
65             tx_ready <= '1';
66           end if;
67           
68         end if;
69       end if;
70     end if;
71   end process;
72
73 --------------------------------------------------------------------------------
74
75   ready <= tx_ready;
76   
77   tx <= tx_shift_reg(0);
78   
79 end behavioral;
80