-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathuart_async_tx.vhd
190 lines (162 loc) · 5.07 KB
/
uart_async_tx.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
------------------------------------------------------------------------------
-- Title : Simple Wishbone UART - tranmitter
-- Project : General Cores Collection (gencores) library
------------------------------------------------------------------------------
-- File : uart_async_tx.vhd
-- Author : Tomasz Wlostowski
-- Company : CERN
-- Platform : FPGA-generic
-- Standard : VHDL'93
-------------------------------------------------------------------------------
-- Copyright (c) 2010 CERN
--
-- This source file is free software; you can redistribute it
-- and/or modify it under the terms of the GNU Lesser General
-- Public License as published by the Free Software Foundation;
-- either version 2.1 of the License, or (at your option) any
-- later version.
--
-- This source is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-- PURPOSE. See the GNU Lesser General Public License for more
-- details.
--
-- You should have received a copy of the GNU Lesser General
-- Public License along with this source; if not, download it
-- from http://www.gnu.org/licenses/lgpl-2.1.html
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity uart_async_tx is
port (
clk_sys_i : in std_logic;
rst_n_i : in std_logic;
baud_tick_i: in std_logic;
txd_o : out std_logic;
tx_start_p_i : in std_logic;
tx_data_i : in std_logic_vector(7 downto 0);
tx_busy_o : out std_logic
);
end uart_async_tx;
architecture behavioral of uart_async_tx is
signal BaudTick : std_logic;
signal TxD_busy : std_logic;
signal TxD_ready : std_logic;
signal state : std_logic_vector(3 downto 0);
signal TxD_dataReg : std_logic_vector(7 downto 0);
signal TxD_dataD : std_logic_vector(7 downto 0);
signal muxbit : std_logic;
signal TxD : std_logic;
begin -- behavioral
TxD_ready <= '1' when state = "0000" else '0';
TxD_busy <= not TxD_ready;
BaudTick <= baud_tick_i;
process(clk_sys_i, rst_n_i)
begin
if rising_edge(clk_sys_i) then
if rst_n_i = '0' then
TxD_dataReg <= (others => '0');
elsif TxD_ready = '1' and tx_start_p_i = '1' then
TxD_dataReg <= tx_data_i;
end if;
end if;
end process;
TxD_dataD <= TxD_dataReg;
process(clk_sys_i, rst_n_i)
begin
if rising_edge(clk_sys_i) then
if rst_n_i = '0' then
state <= "0000";
else
case state is
when "0000" =>
if (tx_start_p_i = '1') then
state <= "0001";
end if;
when "0001" =>
if (BaudTick = '1') then
state <= "0100";
end if;
when "0100" =>
if (BaudTick = '1') then
state <= "1000";
end if;
when "1000" =>
if (BaudTick = '1') then
state <= "1001";
end if;
when "1001" =>
if (BaudTick = '1') then
state <= "1010";
end if;
when "1010" =>
if (BaudTick = '1') then
state <= "1011";
end if;
when "1011" =>
if (BaudTick = '1') then
state <= "1100";
end if;
when "1100" =>
if (BaudTick = '1') then
state <= "1101";
end if;
when "1101" =>
if (BaudTick = '1') then
state <= "1110";
end if;
when "1110" =>
if (BaudTick = '1') then
state <= "1111";
end if;
when "1111" =>
if (BaudTick = '1') then
state <= "0010";
end if;
when "0010" =>
if (BaudTick = '1') then
state <= "0011";
end if;
when "0011" =>
if (BaudTick = '1') then
state <= "0000";
end if;
when others =>
state <= "0000";
end case;
end if;
end if;
end process;
process(TxD_dataD, state)
begin
case state(2 downto 0) is
when "000" => muxbit <= TxD_dataD(0);
when "001" => muxbit <= TxD_dataD(1);
when "010" => muxbit <= TxD_dataD(2);
when "011" => muxbit <= TxD_dataD(3);
when "100" => muxbit <= TxD_dataD(4);
when "101" => muxbit <= TxD_dataD(5);
when "110" => muxbit <= TxD_dataD(6);
when "111" => muxbit <= TxD_dataD(7);
when others => null;
end case;
end process;
process(clk_sys_i, rst_n_i)
begin
if rising_edge(clk_sys_i) then
if rst_n_i = '0' then
TxD <= '1';
else
if(unsigned(state) < to_unsigned(4, state'length) or (state(3) = '1' and muxbit = '1')) then
TxD <= '1';
else
TxD <= '0';
end if;
end if;
end if;
end process;
txd_o <= TxD;
tx_busy_o <= TxD_busy;
end behavioral;