-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_toplevelfib.vhd
434 lines (360 loc) · 12.4 KB
/
tb_toplevelfib.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
--------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 15:54:20 05/03/2012
-- Design Name:
-- Module Name: E:/My-documents/Dropbox/tdt4255_final/single_cycle/tb_toplevel.vhd
-- Project Name: single_cycle
-- Target Device:
-- Tool versions:
-- Description:
--
-- VHDL Test Bench Created by ISE for module: toplevel
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test. Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_toplevelfib IS
END tb_toplevelfib;
ARCHITECTURE behavior OF tb_toplevelfib IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT toplevel
PORT(
clk : IN std_logic;
reset : IN std_logic;
command : IN std_logic_vector(0 to 31);
bus_address_in : IN std_logic_vector(0 to 31);
bus_data_in : IN std_logic_vector(0 to 31);
status : OUT std_logic_vector(0 to 31);
bus_data_out : OUT std_logic_vector(0 to 31)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal reset : std_logic := '0';
signal command : std_logic_vector(0 to 31) := (others => '0');
signal bus_address_in : std_logic_vector(0 to 31) := (others => '0');
signal bus_data_in : std_logic_vector(0 to 31) := (others => '0');
--Outputs
signal status : std_logic_vector(0 to 31);
signal bus_data_out : std_logic_vector(0 to 31);
-- Clock period definitions
constant clk_period : time := 40 ns;
constant zero : std_logic_vector(0 to 31) := "00000000000000000000000000000000";
constant addr1 : std_logic_vector(0 to 31) := "00000000000000000000000000000001";
constant addr2 : std_logic_vector(0 to 31) := "00000000000000000000000000000010";
constant addr3 : std_logic_vector(0 to 31) := "00000000000000000000000000000011";
constant addr4 : std_logic_vector(0 to 31) := "00000000000000000000000000000100";
constant addr5 : std_logic_vector(0 to 31) := "00000000000000000000000000000101";
constant addr6 : std_logic_vector(0 to 31) := "00000000000000000000000000000110";
constant addr7 : std_logic_vector(0 to 31) := "00000000000000000000000000000111";
constant addr8 : std_logic_vector(0 to 31) := "00000000000000000000000000001000";
constant addr9 : std_logic_vector(0 to 31) := "00000000000000000000000000001001";
constant addr10: std_logic_vector(0 to 31) := "00000000000000000000000000001010";
constant addr11: std_logic_vector(0 to 31) := "00000000000000000000000000001011";
constant addr12: std_logic_vector(0 to 31) := "00000000000000000000000000001100";
constant addr13: std_logic_vector(0 to 31) := "00000000000000000000000000001101";
constant addr14: std_logic_vector(0 to 31) := "00000000000000000000000000001110";
constant addr15: std_logic_vector(0 to 31) := "00000000000000000000000000001111";
constant addr16: std_logic_vector(0 to 31) := "00000000000000000000000000010000";
-- This is written to memory initially
constant data0 : std_logic_vector(0 to 31):= X"00000000";
constant data1 : std_logic_vector(0 to 31):= X"00000001";
constant data2 : std_logic_vector(0 to 31):= X"00000002";
constant data3 : std_logic_vector(0 to 31):= X"00000000";
constant data4 : std_logic_vector(0 to 31):= X"00000000";
constant data5 : std_logic_vector(0 to 31):= X"00000000";
constant data6 : std_logic_vector(0 to 31):= X"00000000";
constant data7 : std_logic_vector(0 to 31):= X"00000000";
constant data8 : std_logic_vector(0 to 31):= X"00000000";
constant data9 : std_logic_vector(0 to 31):= X"00000000";
constant data10 : std_logic_vector(0 to 31):= X"00000000";
constant data11 : std_logic_vector(0 to 31):= X"00000000";
constant data12 : std_logic_vector(0 to 31):= X"00000000";
constant data13 : std_logic_vector(0 to 31):= X"00000000";
constant data14 : std_logic_vector(0 to 31):= X"00000000";
constant data15 : std_logic_vector(0 to 31):= X"00000010";
constant data16 : std_logic_vector(0 to 31):= X"00000000";
-- These are the instructions executed by the CPU (loaded to instruction-memory)
-- See ins.txt for what they actually mean (that is a file used when loading them to the FPGA)
constant ins0 : std_logic_vector(0 to 31) := X"8c010001";
constant ins1 : std_logic_vector(0 to 31) := X"8c020002";
constant ins2 : std_logic_vector(0 to 31) := X"8c03000f";
constant ins3 : std_logic_vector(0 to 31) := X"00222020";
constant ins4 : std_logic_vector(0 to 31) := X"00400820";
constant ins5 : std_logic_vector(0 to 31) := X"00801020";
constant ins6 : std_logic_vector(0 to 31) := X"0062202a";
constant ins7 : std_logic_vector(0 to 31) := X"1004fffc";
constant ins8 : std_logic_vector(0 to 31) := X"ac030010";
constant ins9 : std_logic_vector(0 to 31) := X"0800000a";
-- Used to control the COM-module
constant CMD_IDLE : std_logic_vector(0 to 31) := "00000000000000000000000000000000";
constant CMD_WI : std_logic_vector(0 to 31) := "00000000000000000000000000000001";
constant CMD_RD : std_logic_vector(0 to 31) := "00000000000000000000000000000010";
constant CMD_WD : std_logic_vector(0 to 31) := "00000000000000000000000000000011";
constant CMD_RUN : std_logic_vector(0 to 31) := "00000000000000000000000000000100";
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: toplevel PORT MAP (
clk => clk,
reset => reset,
command => command,
bus_address_in => bus_address_in,
bus_data_in => bus_data_in,
status => status,
bus_data_out => bus_data_out
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 20 ns.
wait for 20 ns;
-- insert stimulus here
-- INSTR: WRITE DATA TO DMEM
command <= CMD_WD;
bus_address_in <= addr1;
bus_data_in <= data1;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr2;
bus_data_in <= data2;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr3;
bus_data_in <= data3;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr4;
bus_data_in <= data4;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr5;
bus_data_in <= data5;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr6;
bus_data_in <= data6;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr7;
bus_data_in <= data7;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr8;
bus_data_in <= data8;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr9;
bus_data_in <= data9;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr10;
bus_data_in <= data10;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr11;
bus_data_in <= data11;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr12;
bus_data_in <= data12;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr13;
bus_data_in <= data13;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr14;
bus_data_in <= data14;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr15;
bus_data_in <= data15;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
command <= CMD_WD;
bus_address_in <= addr16;
bus_data_in <= data16;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 0
command <= CMD_WI;
bus_address_in <= zero;
bus_data_in <= ins0;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 1
command <= CMD_WI;
bus_address_in <= addr1;
bus_data_in <= ins1;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 2
command <= CMD_WI;
bus_address_in <= addr2;
bus_data_in <= ins2;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 3
command <= CMD_WI;
bus_address_in <= addr3;
bus_data_in <= ins3;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 4
command <= CMD_WI;
bus_address_in <= addr4;
bus_data_in <= ins4;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 5
command <= CMD_WI;
bus_address_in <= addr5;
bus_data_in <= ins5;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 6
command <= CMD_WI;
bus_address_in <= addr6;
bus_data_in <= ins6;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 7
command <= CMD_WI;
bus_address_in <= addr7;
bus_data_in <= ins7;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 8
command <= CMD_WI;
bus_address_in <= addr8;
bus_data_in <= ins8;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Add instruction 9
command <= CMD_WI;
bus_address_in <= addr9;
bus_data_in <= ins9;
wait for clk_period*3;
command <= CMD_IDLE;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*3;
-- Run CPU!
command <= CMD_RUN;
bus_address_in <= zero;
bus_data_in <= zero;
wait for clk_period*100;
wait;
end process;
END;