001.
library
IEEE
;
002.
use
IEEE.STD_LOGIC_1164.
all
;
003.
004.
package
UART_TxController
is
005.
006.
component
TxController
is
007.
port
(
008.
AClr
:
in
std_logic
;
009.
Ck
:
in
std_logic
;
010.
011.
DWr
:
in
std_logic
;
012.
DEn
:
out
std_logic
;
013.
014.
BWr
:
in
std_logic
;
015.
BEn
:
out
std_logic
;
016.
017.
Stop
:
in
std_logic
;
018.
BitBnd
:
in
std_logic
;
019.
020.
SampClr
:
out
std_logic
;
021.
SampCnt
:
out
std_logic
;
022.
023.
BitClr
:
out
std_logic
;
024.
BitCnt
:
out
std_logic
;
025.
026.
ShiftData
:
out
std_logic
;
027.
Output_Ctl
:
out
std_logic_vector
(
1
downto
0
)
;
028.
029.
Busy
:
out
std_logic
030.
)
;
031.
end
component
;
032.
033.
end
package
;
034.
035.
library
IEEE
;
036.
use
IEEE.STD_LOGIC_1164.
all
;
037.
038.
entity
TxController
is
039.
port
(
040.
AClr
:
in
std_logic
;
041.
Ck
:
in
std_logic
;
042.
043.
DWr
:
in
std_logic
;
044.
DEn
:
out
std_logic
;
045.
046.
BWr
:
in
std_logic
;
047.
BEn
:
out
std_logic
;
048.
049.
Stop
:
in
std_logic
;
050.
BitBnd
:
in
std_logic
;
051.
052.
SampClr
:
out
std_logic
;
053.
SampCnt
:
out
std_logic
;
054.
055.
BitClr
:
out
std_logic
;
056.
BitCnt
:
out
std_logic
;
057.
058.
ShiftData
:
out
std_logic
;
059.
Output_Ctl
:
out
std_logic_vector
(
1
downto
0
)
;
060.
061.
Busy
:
out
std_logic
062.
)
;
063.
end
entity
;
064.
065.
architecture
TxController_A1
of
TxController
is
066.
type
StateType
is
(
Reset
,
Ready
,
StartBit
,
Running
,
StopBit
)
;
067.
constant
OutData
:
std_logic_vector
(
1
downto
0
)
:
=
"00"
;
068.
constant
OutIdle
:
std_logic_vector
(
1
downto
0
)
:
=
"01"
;
069.
constant
OutStop
:
std_logic_vector
(
1
downto
0
)
:
=
"10"
;
070.
constant
OutStart
:
std_logic_vector
(
1
downto
0
)
:
=
"11"
;
071.
072.
signal
State
:
StateType
;
073.
signal
SampCntEn
:
std_logic
;
074.
signal
BitCntEn
:
std_logic
;
075.
signal
ShiftEn
:
std_logic
;
076.
077.
begin
078.
079.
process
(
AClr
,
Ck
)
080.
variable
NextState
:
StateType
;
081.
begin
082.
083.
if
(
AClr
=
'
0
'
)
then
084.
085.
DEn
<
=
'
0
'
;
086.
BEn
<
=
'
1
'
;
087.
SampCntEn
<
=
'
0
'
;
088.
BitCntEn
<
=
'
0
'
;
089.
ShiftEn
<
=
'
0
'
;
090.
Output_Ctl
<
=
OutIdle
;
091.
Busy
<
=
'
0
'
;
092.
NextState
:
=
Reset
;
093.
094.
elsif
(
rising_edge
(
Ck
)
)
then
095.
096.
case
State
is
097.
098.
when
Reset
=
>
099.
100.
if
(
BWr
=
'
1
'
)
then
101.
102.
DEn
<
=
'
1
'
;
103.
BEn
<
=
'
0
'
;
104.
SampCntEn
<
=
'
0
'
;
105.
BitCntEn
<
=
'
0
'
;
106.
ShiftEn
<
=
'
0
'
;
107.
Output_Ctl
<
=
OutIdle
;
108.
Busy
<
=
'
0
'
;
109.
NextState
:
=
Ready
;
110.
111.
else
112.
113.
DEn
<
=
'
0
'
;
114.
BEn
<
=
'
1
'
;
115.
SampCntEn
<
=
'
0
'
;
116.
BitCntEn
<
=
'
0
'
;
117.
ShiftEn
<
=
'
0
'
;
118.
Output_Ctl
<
=
OutIdle
;
119.
Busy
<
=
'
0
'
;
120.
NextState
:
=
Reset
;
121.
122.
end
if
;
123.
124.
when
Ready
=
>
125.
126.
if
(
DWr
=
'
1
'
)
then
127.
128.
DEn
<
=
'
0
'
;
129.
BEn
<
=
'
0
'
;
130.
SampCntEn
<
=
'
1
'
;
131.
BitCntEn
<
=
'
1
'
;
132.
ShiftEn
<
=
'
0
'
;
133.
Output_Ctl
<
=
OutStart
;
134.
Busy
<
=
'
1
'
;
135.
NextState
:
=
StartBit
;
136.
137.
else
138.
139.
DEn
<
=
'
1
'
;
140.
BEn
<
=
'
0
'
;
141.
SampCntEn
<
=
'
0
'
;
142.
BitCntEn
<
=
'
0
'
;
143.
ShiftEn
<
=
'
0
'
;
144.
Output_Ctl
<
=
OutIdle
;
145.
Busy
<
=
'
0
'
;
146.
NextState
:
=
Ready
;
147.
148.
end
if
;
149.
150.
when
StartBit
=
>
151.
152.
if
(
BitBnd
=
'
1
'
)
then
153.
154.
DEn
<
=
'
0
'
;
155.
BEn
<
=
'
0
'
;
156.
SampCntEn
<
=
'
1
'
;
157.
BitCntEn
<
=
'
1
'
;
158.
ShiftEn
<
=
'
1
'
;
159.
Output_Ctl
<
=
OutData
;
160.
Busy
<
=
'
1
'
;
161.
NextState
:
=
Running
;
162.
163.
else
164.
165.
DEn
<
=
'
0
'
;
166.
BEn
<
=
'
0
'
;
167.
SampCntEn
<
=
'
1
'
;
168.
BitCntEn
<
=
'
1
'
;
169.
ShiftEn
<
=
'
0
'
;
170.
Output_Ctl
<
=
OutStart
;
171.
Busy
<
=
'
1
'
;
172.
NextState
:
=
StartBit
;
173.
174.
end
if
;
175.
176.
when
Running
=
>
177.
178.
if
(
BitBnd
=
'
1
'
)
then
179.
180.
if
(
Stop
=
'
1
'
)
then
181.
182.
DEn
<
=
'
0
'
;
183.
BEn
<
=
'
0
'
;
184.
SampCntEn
<
=
'
1
'
;
185.
BitCntEn
<
=
'
0
'
;
186.
ShiftEn
<
=
'
0
'
;
187.
Output_Ctl
<
=
OutStop
;
188.
Busy
<
=
'
1
'
;
189.
NextState
:
=
StopBit
;
190.
191.
else
192.
193.
DEn
<
=
'
0
'
;
194.
BEn
<
=
'
0
'
;
195.
SampCntEn
<
=
'
1
'
;
196.
BitCntEn
<
=
'
1
'
;
197.
ShiftEn
<
=
'
1
'
;
198.
Output_Ctl
<
=
OutData
;
199.
Busy
<
=
'
1
'
;
200.
NextState
:
=
Running
;
201.
202.
end
if
;
203.
204.
else
205.
206.
DEn
<
=
'
0
'
;
207.
BEn
<
=
'
0
'
;
208.
SampCntEn
<
=
'
1
'
;
209.
BitCntEn
<
=
'
1
'
;
210.
ShiftEn
<
=
'
1
'
;
211.
Output_Ctl
<
=
OutData
;
212.
Busy
<
=
'
1
'
;
213.
NextState
:
=
Running
;
214.
215.
end
if
;
216.
217.
when
StopBit
=
>
218.
219.
if
(
BitBnd
=
'
1
'
)
then
220.
221.
DEn
<
=
'
1
'
;
222.
BEn
<
=
'
0
'
;
223.
SampCntEn
<
=
'
0
'
;
224.
BitCntEn
<
=
'
0
'
;
225.
ShiftEn
<
=
'
0
'
;
226.
Output_Ctl
<
=
OutIdle
;
227.
Busy
<
=
'
0
'
;
228.
NextState
:
=
Ready
;
229.
230.
else
231.
232.
DEn
<
=
'
0
'
;
233.
BEn
<
=
'
0
'
;
234.
SampCntEn
<
=
'
1
'
;
235.
BitCntEn
<
=
'
0
'
;
236.
ShiftEn
<
=
'
0
'
;
237.
Output_Ctl
<
=
OutStop
;
238.
Busy
<
=
'
1
'
;
239.
NextState
:
=
StopBit
;
240.
241.
end
if
;
242.
243.
end
case
;
244.
245.
end
if
;
246.
247.
State
<
=
NextState
;
248.
249.
end
process
;
250.
251.
SampClr
<
=
BitBnd
;
252.
SampCnt
<
=
SampCntEn
;
253.
BitClr
<
=
BitBnd
and
Stop
;
254.
BitCnt
<
=
BitBnd
and
BitCntEn
;
255.
ShiftData
<
=
BitBnd
and
ShiftEn
;
256.
257.
end
architecture
;