-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtop_level_tb.vhd
184 lines (129 loc) · 3.68 KB
/
top_level_tb.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
--top_level_tb
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity top_level_tb is
end top_level_tb;
architecture TB of top_level_tb is
-----------------------------------
--signals
-----------------------------------
signal clk50MHz : std_logic := '0';
signal rst : std_logic := '1';
signal mosi : std_logic;
signal miso : std_logic := '0';
signal sclk : std_logic;
signal cs : std_logic;
-- signal pol : std_logic;
-- signal pha : std_logic;
signal int1 : std_logic := '0';
signal led0 : std_logic_vector (6 downto 0);
signal led0_dp : std_logic;
signal led1 : std_logic_vector (6 downto 0);
signal led1_dp : std_logic;
signal led2 : std_logic_vector (6 downto 0);
signal led2_dp : std_logic;
signal led3 : std_logic_vector (6 downto 0);
signal led3_dp : std_logic;
signal led4 : std_logic_vector (6 downto 0);
signal led4_dp : std_logic;
signal led5 : std_logic_vector (6 downto 0);
signal led5_dp : std_logic;
signal rst_led : std_logic;
-- signal led_int1 : std_logic;
-- signal led_int2 : std_logic;
signal misoData :std_logic_vector(7 downto 0) := "11100101";--"11001110";
signal bit : integer range -1 to 8 := 7;
signal sentData : std_logic_vector (7 downto 0) := "00000000";
signal mosi_test : std_logic;
signal sclk_test : std_logic;
signal cs_test : std_logic;
signal intBypass : std_logic := '0';
begin
-----------------------------------
--units under test
-----------------------------------
U_TOP_LEVEL : entity work.top_level
port map(
clk50MHz => clk50MHz,
rst => rst,
mosi => mosi,
miso => miso,
sclk => sclk,
cs => cs,
int1 => int1,
mosi_test => mosi_test,
sclk_test => sclk_test,
cs_test => cs_test,
intBypass => intBypass,
led0 => led0,
led0_dp => led0_dp,
led1 => led1,
led1_dp => led1_dp,
led2 => led2,
led2_dp => led2_dp,
led3 => led3,
led3_dp => led3_dp,
led4 => led4,
led4_dp => led4_dp,
led5 => led5,
led5_dp => led5_dp
);
clk50MHz <= not clk50MHz after 10 ns;
rst_led <= not rst;
process
begin
rst <= '1';
wait for 1 ms;
wait until clk50MHz'event and clk50MHz = '1';
rst <= '0';
-- wait until cs'event and cs = '0'; --reg 1
-- --misoData <= "";
-- wait until cs'event and cs = '0'; -- reg 2
-- -- misoData <= "";
-- wait until cs'event and cs = '0'; -- reg 3
-- misoData <= "";
-- wait until cs'event and cs = '0'; --reg 1 read
-- misoData <= "00001010";
-- wait until cs'event and cs = '0'; -- reg 2 read
-- misoData <= "00000110";
-- wait until cs'event and cs = '0'; -- reg 3 read
-- misoData <= "00001000";
for i in 0 to 50 loop
wait for 20 us;
int1 <= '1';
wait until cs'event and cs = '0';
int1 <= '0';
end loop;
wait for 3 ms;
rst <= '1';
wait for 1 ms;
wait until clk50MHz'event and clk50MHz = '1';
rst <= '0';
for i in 0 to 500 loop
wait for 20 us;
int1 <= '1';
wait until cs'event and cs = '0';
int1 <= '0';
end loop;
for i in 0 to 900000000 loop
wait until clk50MHz'event and clk50MHz = '1';
end loop;
end process;
process (sclk, rst) -- simulation of miso data, clocked only on sclk
begin
if(rst = '1') then
bit <= 7;
end if;
if(sclk'event and sclk = '0' and cs = '0') then
miso <= misoData(bit); -- misoData is updated in test process above
bit <= bit - 1;
if(bit = 0) then
bit <= 7;
end if;
end if;
if(sclk'event and sclk = '1' and cs = '0') then
sentData <= sentData(6 downto 0) & mosi;
end if;
end process;
end TB;