-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsr.vhd
149 lines (125 loc) · 3.59 KB
/
tsr.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
library ieee;
use ieee.std_logic_1164.all;
--! This component is the Transmitter Shift Register of the Transmitter component
--! It adopts a PISO architecture, receiving data from the TDR parallelly,
--! and outputting data serially to the TxD output
entity tsr is
port (
reset_bar, sh_ld_bar : in std_logic;
clk : in std_logic;
data_in : in std_logic_vector(7 downto 0);
data_out : out std_logic
);
end tsr;
architecture tsr_struc of tsr is
-- signals for internal transfer of data to output
signal i_serial : std_logic_vector(7 downto 0);
signal i_data : std_logic_vector(7 downto 0);
signal i_serial_out : std_logic;
signal i_serial_start, i_start_bit, i_start_in : std_logic;
signal i_stop_bit, i_stop_in : std_logic;
signal i_no_transmit : std_logic;
component dflipflop is
port(i_d, i_clk, i_set, i_rst: in STD_LOGIC;
o_q, o_qbar : inout STD_LOGIC);
end component;
begin
-- DFF that holds the stop bit ('1') which is sent last to the TxD
stop_bit : dflipflop port map (
i_d => i_stop_in,
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(7)
);
-- DFF to hold bit 7 of data
bit7 : dflipflop port map (
i_d => i_data(7),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(6)
);
-- DFF to hold bit 6 of data
bit6 : dflipflop port map (
i_d => i_data(6),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(5)
);
-- DFF to hold bit 5 of data
bit5 : dflipflop port map (
i_d => i_data(5),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(4)
);
-- DFF to hold bit 4 of data
bit4 : dflipflop port map (
i_d => i_data(4),
i_clk => clk,
i_set => '1',
i_rst => reset_bar,
o_q => i_serial(3)
);
-- DFF to hold bit 3 of data
bit3 : dflipflop port map (
i_d => i_data(3),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(2)
);
-- DFF to hold bit 2 of data
bit2 : dflipflop port map (
i_d => i_data(2),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(1)
);
-- DFF to hold bit 1 of data
bit1 : dflipflop port map (
i_d => i_data(1),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial(0)
);
-- DFF to hold bit 0 of data
bit0 : dflipflop port map (
i_d => i_data(0),
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial_start
);
-- DFF that holds the start bit ('0') which be sent to the TxD first
-- Note that for this component, reset_bar is connected to the i_set instead of
-- i_rst, to achieve high TxD signal on reset
start_bit : dflipflop port map (
i_d => i_start_in,
i_clk => clk,
i_set => reset_bar,
i_rst => '1',
o_q => i_serial_out
);
-- Signal connections
i_stop_bit <= '1';
i_stop_in <= (sh_ld_bar) or (not sh_ld_bar and i_stop_bit);
i_data(7) <= (sh_ld_bar and i_serial(7)) or (not sh_ld_bar and data_in(7));
i_data(6) <= (sh_ld_bar and i_serial(6)) or (not sh_ld_bar and data_in(6));
i_data(5) <= (sh_ld_bar and i_serial(5)) or (not sh_ld_bar and data_in(5));
i_data(4) <= (sh_ld_bar and i_serial(4)) or (not sh_ld_bar and data_in(4));
i_data(3) <= (sh_ld_bar and i_serial(3)) or (not sh_ld_bar and data_in(3));
i_data(2) <= (sh_ld_bar and i_serial(2)) or (not sh_ld_bar and data_in(2));
i_data(1) <= (sh_ld_bar and i_serial(1)) or (not sh_ld_bar and data_in(1));
i_data(0) <= (sh_ld_bar and i_serial(0)) or (not sh_ld_bar and data_in(0));
i_start_bit <= '0';
i_start_in <= (sh_ld_bar and i_serial_start) or (not sh_ld_bar and i_start_bit);
i_no_transmit <= '1';
-- Output Driver
data_out <= (i_serial_out and sh_ld_bar) or (i_no_transmit and not sh_ld_bar);
end tsr_struc;