1 |
24 |
TobiasJ |
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_top is
|
7 |
|
|
generic(address_width : integer := 3);
|
8 |
28 |
TobiasJ |
port( clk, master_rst : in std_logic;
|
9 |
24 |
TobiasJ |
|
10 |
28 |
TobiasJ |
RST_I : in std_logic;
|
11 |
24 |
TobiasJ |
ADR_I : in std_logic_vector(7 downto 0);
|
12 |
|
|
DAT_I : in std_logic_vector(7 downto 0);
|
13 |
|
|
WE_I : in std_logic;
|
14 |
|
|
STB_I : in std_logic;
|
15 |
|
|
CYC_I : in std_logic;
|
16 |
25 |
TobiasJ |
DAT_O : out std_logic_vector(7 downto 0);
|
17 |
24 |
TobiasJ |
ACK_O : out std_logic;
|
18 |
|
|
|
19 |
|
|
rx : in std_logic;
|
20 |
|
|
tx : out std_logic;
|
21 |
|
|
|
22 |
25 |
TobiasJ |
rx_fifo_empty : out std_logic;
|
23 |
|
|
rx_fifo_full : out std_logic;
|
24 |
|
|
tx_fifo_empty : out std_logic;
|
25 |
|
|
tx_fifo_full : out std_logic;
|
26 |
24 |
TobiasJ |
parity_error : out std_logic;
|
27 |
|
|
stop_bit_error : out std_logic;
|
28 |
|
|
transmitting : out std_logic);
|
29 |
|
|
end entity uart_top;
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
architecture behaviour of uart_top is
|
34 |
|
|
component uart_wb is
|
35 |
|
|
port( --WB interface
|
36 |
|
|
CLK_I : in std_logic;
|
37 |
28 |
TobiasJ |
master_rst : in std_logic;
|
38 |
24 |
TobiasJ |
RST_I : in std_logic;
|
39 |
|
|
ADR_I : in std_logic_vector(7 downto 0);
|
40 |
|
|
DAT_I : in std_logic_vector(7 downto 0);
|
41 |
|
|
WE_I : in std_logic;
|
42 |
|
|
STB_I : in std_logic;
|
43 |
|
|
CYC_I : in std_logic;
|
44 |
|
|
|
45 |
25 |
TobiasJ |
DAT_O : out std_logic_vector(7 downto 0);
|
46 |
24 |
TobiasJ |
ACK_O : out std_logic;
|
47 |
|
|
|
48 |
|
|
--uart controll
|
49 |
|
|
word_width : out std_logic_vector(3 downto 0);
|
50 |
|
|
baud_period : out std_logic_vector(15 downto 0);
|
51 |
|
|
use_parity_bit : out std_logic;
|
52 |
|
|
parity_type : out std_logic;
|
53 |
|
|
stop_bits : out std_logic_vector(1 downto 0);
|
54 |
|
|
idle_line_lvl : out std_logic;
|
55 |
|
|
rx_enable : out std_logic; --rx specific
|
56 |
|
|
start_samples : out std_logic_vector(3 downto 0); --rx specific
|
57 |
|
|
line_samples : out std_logic_vector(3 downto 0); --rx specific
|
58 |
|
|
uart_rx_rst : out std_logic;
|
59 |
|
|
uart_rx_fifo_rst : out std_logic;
|
60 |
|
|
uart_tx_rst : out std_logic;
|
61 |
|
|
uart_tx_fifo_rst : out std_logic;
|
62 |
|
|
|
63 |
|
|
--FIFO control/data
|
64 |
|
|
tx_fifo_entries_free : in std_logic_vector (7 downto 0);
|
65 |
|
|
write_tx_data : out std_logic;
|
66 |
|
|
tx_data : out std_logic_vector(7 downto 0);
|
67 |
|
|
|
68 |
25 |
TobiasJ |
read_rx_data : out std_logic;
|
69 |
24 |
TobiasJ |
rx_data : in std_logic_vector(7 downto 0);
|
70 |
|
|
rx_fifo_entries_free : in std_logic_vector (7 downto 0));
|
71 |
|
|
end component;
|
72 |
|
|
|
73 |
|
|
component tx_func is
|
74 |
|
|
port( clk, reset : in std_logic;
|
75 |
|
|
data : in std_logic_vector(7 downto 0);
|
76 |
|
|
transmit_data : in std_logic;
|
77 |
|
|
|
78 |
|
|
word_width : in std_logic_vector(3 downto 0);
|
79 |
|
|
baud_period : in std_logic_vector(15 downto 0);
|
80 |
|
|
use_parity_bit, parity_type : in std_logic;
|
81 |
|
|
stop_bits : in std_logic_vector(1 downto 0);
|
82 |
|
|
idle_line_lvl : in std_logic;
|
83 |
|
|
|
84 |
|
|
tx : out std_logic;
|
85 |
|
|
sending : out std_logic);
|
86 |
|
|
end component;
|
87 |
|
|
|
88 |
|
|
component rx_func is
|
89 |
|
|
port( clk, reset, rx_enable : in std_logic;
|
90 |
|
|
rx : in std_logic;
|
91 |
|
|
|
92 |
|
|
word_width : in std_logic_vector(3 downto 0);
|
93 |
|
|
baud_period : in std_logic_vector(15 downto 0);
|
94 |
|
|
use_parity_bit, parity_type : in std_logic;
|
95 |
|
|
stop_bits : in std_logic_vector(1 downto 0);
|
96 |
|
|
idle_line_lvl : in std_logic;
|
97 |
|
|
|
98 |
|
|
start_samples : in std_logic_vector(3 downto 0); --How many correct samples should give a start bit
|
99 |
|
|
line_samples : in std_logic_vector(3 downto 0); --How many samples should tip the internal rx value
|
100 |
|
|
|
101 |
|
|
data : out std_logic_vector(7 downto 0);
|
102 |
|
|
data_ready : out std_logic;
|
103 |
|
|
parity_error : out std_logic;
|
104 |
|
|
stop_bit_error : out std_logic);
|
105 |
|
|
end component;
|
106 |
|
|
|
107 |
|
|
component rx_fifo is
|
108 |
|
|
generic(address_width : integer := 3);
|
109 |
|
|
port( clk, reset : in std_logic;
|
110 |
|
|
|
111 |
|
|
read_rx_data : in std_logic;
|
112 |
|
|
rx_data : out std_logic_vector(7 downto 0);
|
113 |
|
|
rx_fifo_full : out std_logic;
|
114 |
|
|
rx_fifo_empty : out std_logic;
|
115 |
|
|
rx_fifo_entries_free : out std_logic_vector(7 downto 0);
|
116 |
|
|
|
117 |
|
|
rx_func_data : in std_logic_vector(7 downto 0);
|
118 |
|
|
rx_func_data_ready : in std_logic);
|
119 |
|
|
end component;
|
120 |
|
|
|
121 |
|
|
component tx_fifo is
|
122 |
|
|
generic(address_width : integer := 3);
|
123 |
|
|
port( clk, reset : in std_logic;
|
124 |
|
|
|
125 |
|
|
write_tx_data : in std_logic;
|
126 |
|
|
tx_data : in std_logic_vector(7 downto 0);
|
127 |
|
|
tx_fifo_full : out std_logic;
|
128 |
|
|
tx_fifo_empty : out std_logic;
|
129 |
|
|
tx_fifo_entries_free : out std_logic_vector(7 downto 0);
|
130 |
|
|
|
131 |
|
|
tx_func_data : out std_logic_vector(7 downto 0);
|
132 |
|
|
tx_func_apply_data : out std_logic;
|
133 |
|
|
tx_func_sending : in std_logic);
|
134 |
|
|
end component;
|
135 |
|
|
|
136 |
|
|
signal word_width : std_logic_vector(3 downto 0);
|
137 |
|
|
signal baud_period : std_logic_vector(15 downto 0);
|
138 |
|
|
signal start_samples, line_samples : std_logic_vector(3 downto 0);
|
139 |
|
|
signal use_parity_bit, parity_type, idle_line_lvl : std_logic;
|
140 |
|
|
signal uart_rx_rst, uart_tx_rst, uart_rx_fifo_rst, uart_tx_fifo_rst : std_logic;
|
141 |
|
|
signal rx_fifo_entries_free, tx_fifo_entries_free : std_logic_vector(7 downto 0);
|
142 |
|
|
signal read_rx_data, write_tx_data : std_logic;
|
143 |
|
|
signal tx_data, rx_data : std_logic_vector(7 downto 0);
|
144 |
|
|
signal sending : std_logic;
|
145 |
|
|
signal stop_bits : std_logic_vector(1 downto 0);
|
146 |
|
|
signal rx_func_data, tx_func_data : std_logic_vector(7 downto 0);
|
147 |
|
|
signal rx_func_data_ready, tx_func_apply_data : std_logic;
|
148 |
28 |
TobiasJ |
signal rx_enable: std_logic;
|
149 |
24 |
TobiasJ |
|
150 |
|
|
begin
|
151 |
|
|
transmitting <= sending;
|
152 |
|
|
|
153 |
28 |
TobiasJ |
wishBoneInterFace : uart_wb port map (clk, master_rst, RST_I,ADR_I,DAT_I,WE_I,STB_I,CYC_I,DAT_O,ACK_O,word_width,baud_period,use_parity_bit,parity_type,stop_bits,idle_line_lvl,rx_enable,start_samples,line_samples,uart_rx_rst,uart_rx_fifo_rst,uart_tx_rst,uart_tx_fifo_rst,tx_fifo_entries_free,write_tx_data,tx_data,read_rx_data,rx_data,rx_fifo_entries_free);
|
154 |
24 |
TobiasJ |
|
155 |
|
|
UartRx : rx_func port map (clk, uart_rx_rst, rx_enable, rx, word_width, baud_period, use_parity_bit, parity_type, stop_bits, idle_line_lvl, start_samples, line_samples, rx_func_data, rx_func_data_ready,parity_error,stop_bit_error);
|
156 |
|
|
|
157 |
25 |
TobiasJ |
UartTx : tx_func port map(clk, uart_tx_rst, tx_func_data, tx_func_apply_data,word_width,baud_period,use_parity_bit, parity_type,stop_bits,idle_line_lvl,tx,sending);
|
158 |
24 |
TobiasJ |
|
159 |
|
|
RxFifo : rx_fifo generic map(address_width) port map(clk, uart_rx_fifo_rst, read_rx_data, rx_data, rx_fifo_full, rx_fifo_empty, rx_fifo_entries_free, rx_func_data, rx_func_data_ready);
|
160 |
|
|
|
161 |
|
|
TxFifo : tx_fifo generic map(address_width) port map(clk, uart_tx_fifo_rst, write_tx_data,tx_data,tx_fifo_full,tx_fifo_empty,tx_fifo_entries_free,tx_func_data,tx_func_apply_data,sending);
|
162 |
|
|
|
163 |
|
|
end architecture behaviour;
|