001.
library
IEEE
;
002.
use
IEEE.STD_LOGIC_1164.
all
;
003.
004.
package
UART
is
005.
006.
component
UART_Tx
is
007.
port
(
008.
Reset
:
in
std_logic
;
009.
SampCk
:
in
std_logic
;
010.
A0
:
in
std_logic
;
011.
WEn
:
in
std_logic
;
012.
Data
:
in
std_logic_vector
(
8
downto
0
)
;
013.
SOut
:
out
std_logic
;
014.
Busy
:
out
std_logic
015.
)
;
016.
end
component
;
017.
018.
component
UART_Rx
is
019.
port
(
020.
Reset
:
in
std_logic
;
021.
SampCk
:
in
std_logic
;
022.
SIn
:
in
std_logic
;
023.
A0
:
in
std_logic
;
024.
REn
:
in
std_logic
;
025.
Data
:
inout
std_logic_vector
(
8
downto
0
)
;
026.
BAv
:
out
std_logic
;
027.
DAv
:
out
std_logic
028.
)
;
029.
end
component
;
030.
031.
end
package
;
032.
033.
library
IEEE
;
034.
use
IEEE.STD_LOGIC_1164.
all
;
035.
use
work.UART_TxController.
all
;
036.
use
work.UART_Components.
all
;
037.
038.
entity
UART_Tx
is
039.
port
(
040.
Reset
:
in
std_logic
;
041.
SampCk
:
in
std_logic
;
042.
A0
:
in
std_logic
;
043.
WEn
:
in
std_logic
;
044.
Data
:
in
std_logic_vector
(
8
downto
0
)
;
045.
SOut
:
out
std_logic
;
046.
Busy
:
out
std_logic
047.
)
;
048.
end
entity
;
049.
050.
architecture
UART_Tx_A1
of
UART_Tx
is
051.
052.
constant
VCC
:
std_logic
:
=
'
1
'
;
053.
constant
GND
:
std_logic
:
=
'
0
'
;
054.
055.
056.
signal
DEn
:
std_logic
;
057.
signal
DWr
:
std_logic
;
058.
signal
ShiftRegWEn
:
std_logic
;
059.
060.
061.
signal
BEn
:
std_logic
;
062.
signal
BWr
:
std_logic
;
063.
signal
BaudRateRegWEn
:
std_logic
;
064.
065.
066.
signal
Shift
:
std_logic
;
067.
signal
TxD
:
std_logic
;
068.
signal
Output_Ctl
:
std_logic_vector
(
1
downto
0
)
;
069.
signal
DirtySOut
:
std_logic
;
070.
071.
072.
signal
SampClr
:
std_logic
;
073.
signal
SampCnt
:
std_logic
;
074.
signal
ZSC
:
std_logic_vector
(
8
downto
0
)
;
075.
076.
077.
signal
BitCnt
:
std_logic
;
078.
signal
BitClr
:
std_logic
;
079.
signal
ZBC
:
std_logic_vector
(
3
downto
0
)
;
080.
081.
082.
signal
BitBndDetA
:
std_logic_vector
(
8
downto
0
)
;
083.
signal
BitBndDetB
:
std_logic_vector
(
8
downto
0
)
;
084.
signal
BitBnd
:
std_logic
;
085.
086.
087.
signal
StopBitDetA
:
std_logic_vector
(
3
downto
0
)
;
088.
signal
SBC
:
std_logic_vector
(
3
downto
0
)
;
089.
signal
Stop
:
std_logic
;
090.
091.
begin
092.
093.
ShiftRegWEn
<
=
DEn
and
DWr
;
094.
BaudRateRegWEn
<
=
BEn
and
BWr
;
095.
096.
CleanupReg
:
BitPipe
097.
generic
map
(
Length
=
>
1
)
098.
port
map
(
099.
Ck
=
>
SampCk
,
100.
Clr
=
>
VCC
,
101.
D
=
>
DirtySOut
,
102.
Pr
=
>
Reset
,
103.
Q
=
>
SOut
104.
)
;
105.
106.
StopBitConst
:
Const
107.
generic
map
(
108.
Value
=
>
8
,
109.
Width
=
>
4
110.
)
111.
port
map
(
112.
Result
=
>
SBC
113.
)
;
114.
115.
StateMachine
:
TxController
116.
port
map
(
117.
AClr
=
>
Reset
,
118.
BEn
=
>
BEn
,
119.
BWr
=
>
BWr
,
120.
BitBnd
=
>
BitBnd
,
121.
BitClr
=
>
BitClr
,
122.
BitCnt
=
>
BitCnt
,
123.
Ck
=
>
SampCk
,
124.
DEn
=
>
DEn
,
125.
DWr
=
>
DWr
,
126.
Output_Ctl
=
>
Output_Ctl
,
127.
SampClr
=
>
SampClr
,
128.
SampCnt
=
>
SampCnt
,
129.
ShiftData
=
>
Shift
,
130.
Stop
=
>
Stop
,
131.
Busy
=
>
Busy
132.
)
;
133.
134.
ZeroSampleConst
:
Const
135.
generic
map
(
136.
Value
=
>
0
,
137.
Width
=
>
9
138.
)
139.
port
map
(
140.
Result
=
>
ZSC
141.
)
;
142.
143.
ZeroBitConst
:
Const
144.
generic
map
(
145.
Value
=
>
0
,
146.
Width
=
>
4
147.
)
148.
port
map
(
Result
=
>
ZBC
)
;
149.
150.
OutputControlMux
:
Mux4
151.
port
map
(
152.
ChanA
=
>
TxD
,
153.
ChanB
=
>
VCC
,
154.
ChanC
=
>
VCC
,
155.
ChanD
=
>
GND
,
156.
Result
=
>
DirtySOut
,
157.
Sel
=
>
Output_Ctl
158.
)
;
159.
160.
TxShiftReg
:
GenReg
161.
generic
map
(
Width
=
>
8
)
162.
port
map
(
163.
AClr
=
>
Reset
,
164.
Ck
=
>
SampCk
,
165.
Cnt
=
>
GND
,
166.
D
=
>
Data
(
7
downto
0
)
,
167.
OEn
=
>
GND
,
168.
Q
=
>
open
,
169.
ShEn
=
>
Shift
,
170.
WEn
=
>
ShiftRegWEn
,
171.
SIn
=
>
GND
,
172.
SOut
=
>
TxD
173.
)
;
174.
175.
BaudRateDivisor
:
GenReg
176.
generic
map
(
Width
=
>
9
)
177.
port
map
(
178.
AClr
=
>
Reset
,
179.
Ck
=
>
SampCk
,
180.
Cnt
=
>
GND
,
181.
D
=
>
Data
,
182.
OEn
=
>
VCC
,
183.
Q
=
>
BitBndDetB
,
184.
ShEn
=
>
GND
,
185.
WEn
=
>
BaudRateRegWEn
,
186.
SIn
=
>
GND
,
187.
SOut
=
>
open
188.
)
;
189.
190.
SampleCounter
:
GenReg
191.
generic
map
(
Width
=
>
9
)
192.
port
map
(
193.
AClr
=
>
Reset
,
194.
Ck
=
>
SampCk
,
195.
Cnt
=
>
SampCnt
,
196.
D
=
>
ZSC
,
197.
OEn
=
>
VCC
,
198.
Q
=
>
BitBndDetA
,
199.
ShEn
=
>
GND
,
200.
WEn
=
>
SampClr
,
201.
SIn
=
>
GND
,
202.
SOut
=
>
open
203.
)
;
204.
205.
BitCounter
:
GenReg
206.
generic
map
(
Width
=
>
4
)
207.
port
map
(
208.
AClr
=
>
Reset
,
209.
Ck
=
>
SampCk
,
210.
Cnt
=
>
BitCnt
,
211.
D
=
>
ZBC
,
212.
OEn
=
>
VCC
,
213.
Q
=
>
StopBitDetA
,
214.
ShEn
=
>
GND
,
215.
WEn
=
>
BitClr
,
216.
SIn
=
>
GND
,
217.
SOut
=
>
open
218.
)
;
219.
220.
BitBoundDetector
:
GEQ
221.
generic
map
(
Width
=
>
9
)
222.
port
map
(
223.
ChanA
=
>
BitBndDetA
,
224.
ChanB
=
>
BitBndDetB
,
225.
Result
=
>
BitBnd
226.
)
;
227.
228.
BitDetector
:
GEQ
229.
generic
map
(
Width
=
>
4
)
230.
port
map
(
231.
ChanA
=
>
StopBitDetA
,
232.
ChanB
=
>
SBC
,
233.
Result
=
>
Stop
234.
)
;
235.
236.
WriteDemux
:
DeMux2
237.
port
map
(
238.
ChanA
=
>
DWr
,
239.
ChanB
=
>
BWr
,
240.
Sel
=
>
A0
,
241.
Source
=
>
WEn
242.
)
;
243.
244.
end
architecture
;
245.
246.
library
IEEE
;
247.
use
IEEE.STD_LOGIC_1164.
all
;
248.
use
work.UART_RxController.
all
;
249.
use
work.UART_Components.
all
;
250.
251.
entity
UART_Rx
is
252.
port
(
253.
Reset
:
in
std_logic
;
254.
SampCk
:
in
std_logic
;
255.
SIn
:
in
std_logic
;
256.
A0
:
in
std_logic
;
257.
REn
:
in
std_logic
;
258.
Data
:
inout
std_logic_vector
(
8
downto
0
)
;
259.
BAv
:
out
std_logic
;
260.
DAv
:
out
std_logic
261.
)
;
262.
end
entity
;
263.
264.
architecture
UART_Rx_A1
of
UART_Rx
is
265.
266.
constant
VCC
:
std_logic
:
=
'
1
'
;
267.
constant
GND
:
std_logic
:
=
'
0
'
;
268.
269.
270.
signal
DRd
:
std_logic
;
271.
272.
273.
signal
BRd
:
std_logic
;
274.
275.
276.
signal
Muxed_Data
:
std_logic_vector
(
8
downto
0
)
;
277.
278.
279.
signal
Shift
:
std_logic
;
280.
signal
RxD
:
std_logic
;
281.
signal
Shift_Data
:
std_logic_vector
(
7
downto
0
)
:
=
(
others
=
>
'
0
'
)
;
282.
signal
Shift_Buf_Data
:
std_logic_vector
(
8
downto
0
)
;
283.
284.
285.
signal
SampClr
:
std_logic
;
286.
signal
SampCnt
:
std_logic
;
287.
signal
ZSC
:
std_logic_vector
(
8
downto
0
)
;
288.
289.
290.
signal
BitCnt
:
std_logic
;
291.
signal
BitClr
:
std_logic
;
292.
signal
ZBC
:
std_logic_vector
(
3
downto
0
)
;
293.
294.
295.
signal
BitBndDetA
:
std_logic_vector
(
8
downto
0
)
;
296.
signal
BitBndDetB
:
std_logic_vector
(
8
downto
0
)
;
297.
signal
Baud
:
std_logic_vector
(
8
downto
0
)
;
298.
signal
HalfBaud
:
std_logic_vector
(
8
downto
0
)
;
299.
signal
BitBnd
:
std_logic
;
300.
301.
302.
signal
StopBitDetA
:
std_logic_vector
(
3
downto
0
)
;
303.
signal
SBC
:
std_logic_vector
(
3
downto
0
)
;
304.
signal
Stop
:
std_logic
;
305.
306.
307.
signal
KeyDetA
:
std_logic_vector
(
7
downto
0
)
;
308.
signal
KBC
:
std_logic_vector
(
7
downto
0
)
;
309.
signal
KeyDet
:
std_logic
;
310.
311.
312.
signal
BdLd
:
std_logic
;
313.
signal
BdHalf
:
std_logic
;
314.
315.
begin
316.
317.
StateMachine
:
RxController
318.
port
map
(
319.
AClr
=
>
Reset
,
320.
Ck
=
>
SampCk
,
321.
DRd
=
>
DRd
,
322.
DAv
=
>
DAv
,
323.
BRd
=
>
BRd
,
324.
BAv
=
>
BAv
,
325.
Start
=
>
RxD
,
326.
Stop
=
>
Stop
,
327.
BitBnd
=
>
BitBnd
,
328.
KeyDet
=
>
KeyDet
,
329.
ShiftData
=
>
Shift
,
330.
SampClr
=
>
SampClr
,
331.
SampCnt
=
>
SampCnt
,
332.
BitClr
=
>
BitClr
,
333.
BitCnt
=
>
BitCnt
,
334.
BdHalf
=
>
BdHalf
,
335.
BdLd
=
>
BdLd
336.
)
;
337.
338.
MetastableReg
:
BitPipe
339.
generic
map
(
Length
=
>
2
)
340.
port
map
(
341.
Ck
=
>
SampCk
,
342.
Clr
=
>
VCC
,
343.
D
=
>
SIn
,
344.
Pr
=
>
Reset
,
345.
Q
=
>
RxD
346.
)
;
347.
348.
ZeroSampleConst
:
Const
349.
generic
map
(
350.
Value
=
>
0
,
351.
Width
=
>
9
352.
)
353.
port
map
(
354.
Result
=
>
ZSC
355.
)
;
356.
357.
StopBitConst
:
Const
358.
generic
map
(
359.
Value
=
>
8
,
360.
Width
=
>
4
361.
)
362.
port
map
(
Result
=
>
SBC
)
;
363.
364.
ZeroBitConst
:
Const
365.
generic
map
(
366.
Value
=
>
0
,
367.
Width
=
>
4
368.
)
369.
port
map
(
Result
=
>
ZBC
)
;
370.
371.
SerKeyConst
:
Const
372.
generic
map
(
373.
Value
=
>
SLV2I
(
x
"71"
)
,
374.
Width
=
>
8
375.
)
376.
port
map
(
Result
=
>
KBC
)
;
377.
378.
Shift_Buf_Data
(
7
downto
0
)
<
=
KeyDetA
;
379.
Shift_Buf_Data
(
8
)
<
=
'
0
'
;
380.
381.
OutputDataMux
:
BusMux2
382.
generic
map
(
Width
=
>
9
)
383.
port
map
(
384.
Sel
=
>
A0
,
385.
ChanA
=
>
Shift_Buf_Data
,
386.
ChanB
=
>
Baud
,
387.
Result
=
>
Muxed_Data
388.
)
;
389.
390.
OutputTriState
:
TriSt
391.
generic
map
(
Width
=
>
9
)
392.
port
map
(
393.
En
=
>
REn
,
394.
Dir
=
>
VCC
,
395.
ChanA
=
>
Data
,
396.
ChanB
=
>
Muxed_Data
397.
)
;
398.
399.
RxShiftReg
:
GenReg
400.
generic
map
(
Width
=
>
8
)
401.
port
map
(
402.
AClr
=
>
Reset
,
403.
Ck
=
>
SampCk
,
404.
Cnt
=
>
GND
,
405.
D
=
>
Shift_Data
,
406.
OEn
=
>
VCC
,
407.
Q
=
>
KeyDetA
,
408.
ShEn
=
>
Shift
,
409.
WEn
=
>
GND
,
410.
SIn
=
>
RxD
,
411.
SOut
=
>
open
412.
)
;
413.
414.
BaudRateDivisor
:
GenReg
415.
generic
map
(
Width
=
>
9
)
416.
port
map
(
417.
AClr
=
>
Reset
,
418.
Ck
=
>
SampCk
,
419.
Cnt
=
>
GND
,
420.
D
=
>
BitBndDetA
,
421.
OEn
=
>
VCC
,
422.
Q
=
>
Baud
,
423.
ShEn
=
>
GND
,
424.
WEn
=
>
BdLd
,
425.
SIn
=
>
GND
,
426.
SOut
=
>
open
427.
)
;
428.
429.
SampleCounter
:
GenReg
430.
generic
map
(
Width
=
>
9
)
431.
port
map
(
432.
AClr
=
>
Reset
,
433.
Ck
=
>
SampCk
,
434.
Cnt
=
>
SampCnt
,
435.
D
=
>
ZSC
,
436.
OEn
=
>
VCC
,
437.
Q
=
>
BitBndDetA
,
438.
ShEn
=
>
GND
,
439.
WEn
=
>
SampClr
,
440.
SIn
=
>
GND
,
441.
SOut
=
>
open
442.
)
;
443.
444.
BitCounter
:
GenReg
445.
generic
map
(
Width
=
>
4
)
446.
port
map
(
447.
AClr
=
>
Reset
,
448.
Ck
=
>
SampCk
,
449.
Cnt
=
>
BitCnt
,
450.
D
=
>
ZBC
,
451.
OEn
=
>
VCC
,
452.
Q
=
>
StopBitDetA
,
453.
ShEn
=
>
GND
,
454.
WEn
=
>
BitClr
,
455.
SIn
=
>
GND
,
456.
SOut
=
>
open
457.
)
;
458.
459.
KeyDetector
:
EQ
460.
generic
map
(
Width
=
>
8
)
461.
port
map
(
462.
ChanA
=
>
KeyDetA
,
463.
ChanB
=
>
KBC
,
464.
Result
=
>
KeyDet
465.
)
;
466.
467.
BitBoundDetector
:
GEQ
468.
generic
map
(
Width
=
>
9
)
469.
port
map
(
470.
ChanA
=
>
BitBndDetA
,
471.
ChanB
=
>
BitBndDetB
,
472.
Result
=
>
BitBnd
473.
)
;
474.
475.
BitDetector
:
GEQ
476.
generic
map
(
Width
=
>
4
)
477.
port
map
(
478.
ChanA
=
>
StopBitDetA
,
479.
ChanB
=
>
SBC
,
480.
Result
=
>
Stop
481.
)
;
482.
483.
BaudMux
:
BusMux2
484.
generic
map
(
Width
=
>
9
)
485.
port
map
(
486.
Sel
=
>
BdHalf
,
487.
ChanA
=
>
Baud
,
488.
ChanB
=
>
HalfBaud
,
489.
Result
=
>
BitBndDetB
490.
)
;
491.
492.
BaudDivide
:
Div2
493.
generic
map
(
Width
=
>
9
)
494.
port
map
(
495.
Operand
=
>
Baud
,
496.
Result
=
>
HalfBaud
497.
)
;
498.
499.
ReadDemux
:
DeMux2
500.
port
map
(
501.
ChanA
=
>
DRd
,
502.
ChanB
=
>
BRd
,
503.
Sel
=
>
A0
,
504.
Source
=
>
REn
505.
)
;
506.
507.
end
architecture
;