]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - uart.vhd
First prototype of receiver shift register.
[fpga/uart.git] / uart.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 uart is
7   generic (
8     output_fifo_width : integer := 2
9   );
10   port (
11     mclk        : in  std_logic;
12     per_addr    : in  std_logic_vector (7  downto 0);
13     per_din     : in  std_logic_vector (15 downto 0);  -- unused
14     per_en      : in  std_logic;
15     per_wen     : in  std_logic_vector (1  downto 0);  -- unused
16     puc         : in  std_logic;                       -- unused
17     --per_irq_acc : in  std_logic;                       -- unused
18     --per_irq     : out std_logic;
19     per_dout    : out std_logic_vector (15 downto 0);
20
21     txd         : out std_logic
22   );
23 end uart;
24
25 -- Registers:
26 --  - Prescaler .16b
27 --  - Modulator .8b
28 --  - TX data .8b
29 --  - TX enable
30 --  - TX buffer full .1b
31 --  - TX buffer empty .1b
32 --  - TX buffer empty IE 1.b
33 --  - RX data .8b
34 --  - RX enable
35 --  - RX buffer empty .1b
36 --  - RX buffer half full .1b
37 --  - RX buffer full .1b
38 --  - RX buffer half full IE .1b
39 --  - RX buffer full IE .1b
40 --  - RX framing error .1b
41 --  - RX buffer overflow .1b
42
43 --------------------------------------------------------------------------------
44
45 architecture dataflow of uart is
46
47   component tx_control is
48     port (
49       clk        : in  std_logic;
50       reset      : in  std_logic;
51       tx_ready   : in  std_logic;
52       fifo_empty : in  std_logic;
53       tx_we      : out std_logic;
54       fifo_pop   : out std_logic
55     );
56   end component;
57
58   component transmitter is
59     port (
60       clk    : in  std_logic;
61       reset  : in  std_logic;
62       data   : in  std_logic_vector (7 downto 0);
63       we     : in  std_logic;
64       ready  : out std_logic;
65       tx     : out std_logic
66     );
67   end component;
68
69   component fifo is
70     generic (
71       width : integer := 2
72     );
73     port (
74       clk      : in  std_logic;
75       reset    : in  std_logic;
76       we       : in  std_logic;
77       re       : in  std_logic;
78       clear_ow : in  std_logic;
79       d_in     : in  std_logic_vector (7 downto 0);
80       d_out    : out std_logic_vector (7 downto 0);
81       full     : out std_logic;
82       hfull    : out std_logic;
83       empty    : out std_logic;
84       overflow : out std_logic
85     );
86   end component;
87
88   component baud_gen is
89     port (
90       clk      : in  std_logic;
91       reset    : in  std_logic;
92       scale    : in std_logic_vector (15 downto 0);
93       clk_baud : out  std_logic
94     );
95   end component;
96
97 --------------------------------------------------------------------------------
98
99   type boolean_vector is array (natural range <>) of boolean;
100
101 --------------------------------------------------------------------------------
102   
103   constant base_addr : integer := 16#0100#;
104   
105   constant UBAUD : integer := base_addr + 00;
106   constant UTX   : integer := base_addr + 02;
107
108   signal reg_we : std_logic_vector (511 downto 0);
109   signal reg_re : boolean_vector (511 downto 0);
110
111   signal tx_clk : std_logic;
112   signal tx_data : std_logic_vector (7 downto 0);
113   signal tx_we : std_logic;
114   signal tx_ready : std_logic;
115
116   signal tx_fifo_empty : std_logic;
117   signal tx_fifo_re : std_logic;
118   signal tx_fifo_we : std_logic;
119
120 --------------------------------------------------------------------------------
121
122 begin
123
124   process (per_addr, per_wen, per_en)
125   begin
126     for i in reg_re'range loop
127       reg_re (i) <= false;
128       reg_we (i) <= '0';
129       
130       if (per_en = '1' and per_addr = i/2) then
131         reg_re (i) <= true;
132         
133         if (per_wen (i mod 2) = '1') then
134           reg_we (i) <= '1';
135         end if;
136       end if;
137     end loop;
138   end process;
139   
140
141   tx_control_0 : tx_control port map (
142     clk        => mclk,
143     reset      => puc,
144     tx_ready   => tx_ready,
145     fifo_empty => tx_fifo_empty,
146     tx_we      => tx_we,
147     fifo_pop   => tx_fifo_re
148   );
149
150   transmitter_0 : transmitter port map (
151     clk    => tx_clk,
152     reset  => puc,
153     data   => tx_data,
154     we     => tx_we,
155     ready  => tx_ready,
156     tx     => txd
157   );
158
159   tx_fifo : fifo port map (
160     clk      => mclk,
161     reset    => puc,
162     we       => tx_fifo_we,
163     re       => tx_fifo_re,
164     clear_ow => '0',
165     d_in     => per_din (7 downto 0),
166     d_out    => tx_data,
167     full     => open,
168     hfull    => open,
169     empty    => tx_fifo_empty,
170     overflow => open
171   );
172
173   baud_gen_0 : baud_gen port map (
174     clk      => mclk,
175     reset    => puc,
176     scale    => "0000000000000000",
177     clk_baud => tx_clk
178   );
179
180
181 --------------------------------------------------------------------------------
182
183   tx_fifo_we <= reg_we (UTX);
184   
185 end dataflow;
186