-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouse_tb.vhd
More file actions
222 lines (159 loc) · 4.16 KB
/
Mouse_tb.vhd
File metadata and controls
222 lines (159 loc) · 4.16 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity TB is
end;
architecture arc_TB of TB is
component mouse_control
port(
clk :in std_logic;
rst :in std_logic;
data_mouse :inout std_logic;
clk_mouse :inout std_logic;
valid :out std_logic;
x_move :out std_logic_vector(8 downto 0);
y_move :out std_logic_vector(8 downto 0)
);
end component;
constant clock_period: time := 20 ns;
constant clock_period_12: time := 81.92 us; -- T=50MHz/2^12=12.207kHz
signal stop_the_clock_12: boolean:=true;
signal sig_mouse_data :std_logic:= '1';
signal sig_clk_mouse :std_logic:= '1';
signal clk_12 :std_logic:= '1';
signal clk :std_logic:= '0';
signal rst :std_logic:= '0';
signal valid :std_logic:= '0';
signal x_move :std_logic_vector(8 downto 0):= "000000000";
signal y_move :std_logic_vector(8 downto 0):= "000000000";
signal data_send :std_logic_vector(10 downto 0):= "00000000000";
signal data_send_s :std_logic := '1';
signal flag_sig :boolean := false;
begin
uut: mouse_control
port map (
clk => clk,
rst => rst,
data_mouse => data_send_s,
clk_mouse => sig_clk_mouse,
valid => valid,
x_move => x_move,
y_move => y_move
);
rst <= '1' after 100 ns;
-- 50MHz clock
process
begin
wait for clock_period / 2;
clk <= (NOT clk);
end process;
-- 12.207kHz clock
process
begin
wait for clock_period_12 / 2;
if(stop_the_clock_12 = true) then
clk_12 <= '1';
else
clk_12 <= (NOT clk_12);
end if;
end process;
-- receive F6 and conecting mouse to data
process
begin
wait until falling_edge(clk);
if (flag_sig = true) then
sig_clk_mouse <= clk_12;
data_send_s <= sig_mouse_data;
else
sig_clk_mouse <= 'Z';
data_send_s <= 'Z';
end if;
end process;
-- sending data, valid data, expact to work
process
begin
wait for 1.5 ms;
flag_sig <= true;
stop_the_clock_12 <= false;
wait for clock_period_12*3;
-- Byte 1
data_send <= "00001110011";
wait for clock_period_12;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- X data
data_send <= "01101101101";
wait for 179.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- Y data
data_send <= "00010010001";
wait for 179.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
stop_the_clock_12 <= true;
wait for 1 ms;
-- Test 2
-- Data with overflow.
-- Valid is expected to be '0'
stop_the_clock_12 <= false;
wait for clock_period_12*3;
-- Byte 1
data_send <= "00001001001";
wait for clock_period_12;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- X data
data_send <= "01111100101";
wait for 189.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- Y data
data_send <= "00111000011";
wait for 189.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
stop_the_clock_12 <= true;
wait for 189.8 us;
-- Test 3
-- watchdog
--expected reset
stop_the_clock_12 <= false;
wait for clock_period_12*3;
-- Byte 1
data_send <= "00000000001";
wait for clock_period_12;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- X data
data_send <= "01111111101";
wait for 189.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
-- Y data
data_send <= "00111111111";
wait for 189.8 us;
for i in 10 downto 0 loop
sig_mouse_data <= data_send(i);
wait until rising_edge(clk_12);
end loop;
stop_the_clock_12 <= true;
wait;
end process;
end architecture arc_TB;