OpenCores
URL https://opencores.org/ocsvn/dbg_interface/dbg_interface/trunk

Subversion Repositories dbg_interface

[/] [dbg_interface/] [trunk/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 102

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_tb.v                                                    ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC/OpenRISC Development Interface ////
7 36 mohor
////  http://www.opencores.org/projects/DebugInterface/           ////
8 2 mohor
////                                                              ////
9
////  Author(s):                                                  ////
10 80 mohor
////       Igor Mohor (igorm@opencores.org)                       ////
11 2 mohor
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18 101 mohor
//// Copyright (C) 2000 - 2004 Authors                            ////
19 2 mohor
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 102 mohor
// Revision 1.26  2004/01/17 17:01:25  mohor
47
// Almost finished.
48
//
49 101 mohor
// Revision 1.25  2004/01/16 14:51:24  mohor
50
// cpu registers added.
51
//
52 99 mohor
// Revision 1.24  2004/01/15 10:47:13  mohor
53
// Working.
54
//
55 96 mohor
// Revision 1.23  2004/01/14 22:59:01  mohor
56
// Temp version.
57
//
58 95 mohor
// Revision 1.22  2004/01/13 11:28:30  mohor
59
// tmp version.
60
//
61 93 mohor
// Revision 1.21  2004/01/10 07:50:41  mohor
62
// temp version.
63
//
64 92 mohor
// Revision 1.20  2004/01/09 12:49:23  mohor
65
// tmp version.
66
//
67 91 mohor
// Revision 1.19  2004/01/08 17:53:12  mohor
68
// tmp version.
69
//
70 90 mohor
// Revision 1.18  2004/01/07 11:59:48  mohor
71
// temp4 version.
72
//
73 89 mohor
// Revision 1.17  2004/01/06 17:14:59  mohor
74
// temp3 version.
75
//
76 88 mohor
// Revision 1.16  2004/01/05 12:16:50  mohor
77
// tmp2 version.
78
//
79 87 mohor
// Revision 1.15  2003/12/23 14:26:01  mohor
80
// New version of the debug interface. Not finished, yet.
81
//
82 80 mohor
// Revision 1.14  2003/10/23 16:16:30  mohor
83
// CRC logic changed.
84
//
85 73 mohor
// Revision 1.13  2003/08/28 13:54:33  simons
86
// Three more chains added for cpu debug access.
87
//
88 63 simons
// Revision 1.12  2002/05/07 14:44:52  mohor
89
// mon_cntl_o signals that controls monitor mux added.
90
//
91 47 mohor
// Revision 1.11  2002/03/12 14:32:26  mohor
92
// Few outputs for boundary scan chain added.
93
//
94 38 mohor
// Revision 1.10  2002/03/08 15:27:08  mohor
95
// Structure changed. Hooks for jtag chain added.
96
//
97 36 mohor
// Revision 1.9  2001/10/19 11:39:20  mohor
98
// dbg_timescale.v changed to timescale.v This is done for the simulation of
99
// few different cores in a single project.
100
//
101 17 mohor
// Revision 1.8  2001/10/17 10:39:17  mohor
102
// bs_chain_o added.
103
//
104 15 mohor
// Revision 1.7  2001/10/16 10:10:18  mohor
105
// Signal names changed to lowercase.
106
//
107 13 mohor
// Revision 1.6  2001/10/15 09:52:50  mohor
108
// Wishbone interface added, few fixes for better performance,
109
// hooks for boundary scan testing added.
110
//
111 12 mohor
// Revision 1.5  2001/09/24 14:06:12  mohor
112
// Changes connected to the OpenRISC access (SPR read, SPR write).
113
//
114 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
115
// Working version. Few bugs fixed, comments added.
116
//
117 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
118
// Minor changes for simulation.
119
//
120 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
121
// Trace fixed. Some registers changed, trace simplified.
122
//
123 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
124
// Initial official release.
125
//
126 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
127
// This is a backup. It is not a fully working version. Not for use, yet.
128
//
129
// Revision 1.2  2001/05/18 13:10:05  mohor
130
// Headers changed. All additional information is now avaliable in the README.txt file.
131
//
132
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
133
// Initial release
134
//
135
//
136
 
137
 
138 17 mohor
`include "timescale.v"
139 2 mohor
`include "dbg_defines.v"
140 80 mohor
`include "dbg_wb_defines.v"
141 99 mohor
`include "dbg_cpu_defines.v"
142 2 mohor
 
143
// Test bench
144
module dbg_tb;
145
 
146 80 mohor
parameter TCLK = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
147 2 mohor
 
148 80 mohor
reg   tms_pad_i;
149
reg   tck_pad_i;
150
reg   trst_pad_i;
151
reg   tdi_pad_i;
152
wire  tdo_pad_o;
153
wire  tdo_padoe_o;
154 2 mohor
 
155 80 mohor
wire  shift_dr_o;
156
wire  pause_dr_o;
157
wire  update_dr_o;
158 102 mohor
wire  capture_dr_o;
159 2 mohor
 
160 80 mohor
wire  extest_select_o;
161
wire  sample_preload_select_o;
162
wire  mbist_select_o;
163
wire  debug_select_o;
164 2 mohor
 
165 80 mohor
// WISHBONE common signals
166
reg   wb_rst_i;
167
reg   wb_clk_i;
168
 
169
// WISHBONE master interface
170
wire [31:0] wb_adr_o;
171
wire [31:0] wb_dat_o;
172
wire [31:0] wb_dat_i;
173
wire        wb_cyc_o;
174
wire        wb_stb_o;
175
wire  [3:0] wb_sel_o;
176
wire        wb_we_o;
177
wire        wb_ack_i;
178
wire        wb_cab_o;
179
wire        wb_err_i;
180
wire  [2:0] wb_cti_o;
181
wire  [1:0] wb_bte_o;
182 2 mohor
 
183 101 mohor
// CPU signals
184
wire        cpu_clk_i;
185
wire [31:0] cpu_addr_o;
186
wire [31:0] cpu_data_i;
187
wire [31:0] cpu_data_o;
188
wire        cpu_bp_i;
189
wire        cpu_stall_o;
190
wire        cpu_stall_all_o;
191
wire        cpu_stb_o;
192
wire  [`CPU_NUM -1:0]  cpu_sel_o;
193
wire        cpu_we_o;
194
wire        cpu_ack_i;
195
wire        cpu_rst_o;
196
 
197 87 mohor
// Text used for easier debugging
198 99 mohor
reg [199:0] test_text;
199 88 mohor
reg   [2:0] last_wb_cmd;
200 99 mohor
reg [199:0] last_wb_cmd_text;
201 88 mohor
reg  [31:0] wb_data;
202 2 mohor
 
203
 
204 12 mohor
 
205 80 mohor
wire  tdo_o;
206 12 mohor
 
207 80 mohor
wire  debug_tdi_i;
208
wire  bs_chain_tdi_i;
209
wire  mbist_tdi_i;
210 73 mohor
 
211 80 mohor
reg   test_enabled;
212 73 mohor
 
213 80 mohor
reg [31:0] result;
214 2 mohor
 
215 99 mohor
reg  crc_out_en;
216
reg  crc_out_shift;
217
wire crc_out;
218 88 mohor
 
219 99 mohor
 
220
 
221 80 mohor
wire tdo;
222 73 mohor
 
223 80 mohor
assign tdo = tdo_padoe_o? tdo_pad_o : 1'hz;
224 73 mohor
 
225 80 mohor
// Connecting TAP module
226
tap_top i_tap_top (
227 101 mohor
                    .tms_pad_i        (tms_pad_i),
228
                    .tck_pad_i        (tck_pad_i),
229
                    .trst_pad_i       (!trst_pad_i),
230
                    .tdi_pad_i        (tdi_pad_i),
231
                    .tdo_pad_o        (tdo_pad_o),
232
                    .tdo_padoe_o      (tdo_padoe_o),
233 38 mohor
 
234 80 mohor
                    // TAP states
235 101 mohor
                    .shift_dr_o       (shift_dr_o),
236
                    .pause_dr_o       (pause_dr_o),
237
                    .update_dr_o      (update_dr_o),
238 102 mohor
                    .capture_dr_o     (capture_dr_o),
239 38 mohor
 
240 80 mohor
                    // Select signals for boundary scan or mbist
241 101 mohor
                    .extest_select_o  (extest_select_o),
242 80 mohor
                    .sample_preload_select_o(sample_preload_select_o),
243 101 mohor
                    .mbist_select_o   (mbist_select_o),
244
                    .debug_select_o   (debug_select_o),
245 2 mohor
 
246 80 mohor
                    // TDO signal that is connected to TDI of sub-modules.
247 101 mohor
                    .tdo_o            (tdo_o),
248 38 mohor
 
249 80 mohor
                    // TDI signals from sub-modules
250 101 mohor
                    .debug_tdi_i      (debug_tdi_i),        // from debug module
251
                    .bs_chain_tdi_i   (bs_chain_tdi_i),  // from Boundary Scan Chain
252
                    .mbist_tdi_i      (mbist_tdi_i)         // from Mbist Chain
253 73 mohor
 
254 38 mohor
               );
255 2 mohor
 
256
 
257 99 mohor
// Connecting debug top module
258 80 mohor
dbg_top i_dbg_top  (
259 101 mohor
                    .tck_i            (tck_pad_i),
260
                    .tdi_i            (tdo_o),
261
                    .tdo_o            (debug_tdi_i),
262 80 mohor
 
263
                    // TAP states
264 101 mohor
                    .shift_dr_i       (shift_dr_o),
265
                    .pause_dr_i       (pause_dr_o),
266
                    .update_dr_i      (update_dr_o),
267 80 mohor
 
268
                    // Instructions
269 101 mohor
                    .debug_select_i   (debug_select_o),
270 12 mohor
 
271 80 mohor
                    // WISHBONE common signals
272 101 mohor
                    .wb_rst_i         (wb_rst_i),
273
                    .wb_clk_i         (wb_clk_i),
274 80 mohor
 
275
                    // WISHBONE master interface
276 101 mohor
                    .wb_adr_o         (wb_adr_o),
277
                    .wb_dat_o         (wb_dat_o),
278
                    .wb_dat_i         (wb_dat_i),
279
                    .wb_cyc_o         (wb_cyc_o),
280
                    .wb_stb_o         (wb_stb_o),
281
                    .wb_sel_o         (wb_sel_o),
282
                    .wb_we_o          (wb_we_o),
283
                    .wb_ack_i         (wb_ack_i),
284
                    .wb_cab_o         (wb_cab_o),
285
                    .wb_err_i         (wb_err_i),
286
                    .wb_cti_o         (wb_cti_o),
287
                    .wb_bte_o         (wb_bte_o),
288
 
289
                    // CPU signals
290
                    .cpu_clk_i        (cpu_clk_i),
291
                    .cpu_addr_o       (cpu_addr_o),
292
                    .cpu_data_i       (cpu_data_i),
293
                    .cpu_data_o       (cpu_data_o),
294
                    .cpu_bp_i         (cpu_bp_i),
295
                    .cpu_stall_o      (cpu_stall_o),
296
                    .cpu_stall_all_o  (cpu_stall_all_o),
297
                    .cpu_stb_o        (cpu_stb_o),
298
                    .cpu_sel_o        (cpu_sel_o),
299
                    .cpu_we_o         (cpu_we_o),
300
                    .cpu_ack_i        (cpu_ack_i),
301
                    .cpu_rst_o        (cpu_rst_o)
302
 
303
 
304
 
305
 
306 80 mohor
                   );
307 12 mohor
 
308
 
309 99 mohor
 
310
// Connecting CRC module that calculates CRC that is shifted into debug
311
dbg_crc32_d1 crc32_bench_out
312 101 mohor
                   (
313
                    .data             (tdi_pad_i),
314
                    .enable           (crc_out_en),
315
                    .shift            (crc_out_shift),
316
                    .rst              (wb_rst_i),
317
                    .sync_rst         (update_dr_o),
318
                    .crc_out          (crc_out),
319
                    .clk              (tck_pad_i),
320
                    .crc_match        ()
321
                   );
322 99 mohor
 
323
 
324
 
325
 
326 80 mohor
wb_slave_behavioral wb_slave
327
                   (
328 101 mohor
                    .CLK_I            (wb_clk_i),
329
                    .RST_I            (wb_rst_i),
330
                    .ACK_O            (wb_ack_i),
331
                    .ADR_I            (wb_adr_o),
332
                    .CYC_I            (wb_cyc_o),
333
                    .DAT_O            (wb_dat_i),
334
                    .DAT_I            (wb_dat_o),
335
                    .ERR_O            (wb_err_i),
336
                    .RTY_O            (),      // NOT USED for now!
337
                    .SEL_I            (wb_sel_o),
338
                    .STB_I            (wb_stb_o),
339
                    .WE_I             (wb_we_o),
340
                    .CAB_I            (1'b0)
341 80 mohor
                   );
342 2 mohor
 
343
 
344 101 mohor
 
345
cpu_behavioral i_cpu_behavioral
346
                   (
347
                    // CPU signals
348
                    .cpu_rst_i        (wb_rst_i),
349
                    .cpu_clk_o        (cpu_clk_i),
350
                    .cpu_addr_i       (cpu_addr_o),
351
                    .cpu_data_o       (cpu_data_i),
352
                    .cpu_data_i       (cpu_data_o),
353
                    .cpu_bp_o         (cpu_bp_i),
354
                    .cpu_stall_i      (cpu_stall_o),
355
                    .cpu_stall_all_i  (cpu_stall_all_o),
356
                    .cpu_stb_i        (cpu_stb_o),
357
                    .cpu_sel_i        (cpu_sel_o),
358
                    .cpu_we_i         (cpu_we_o),
359
                    .cpu_ack_o        (cpu_ack_i),
360
                    .cpu_rst_o        (cpu_rst_o)
361
                   );
362
 
363
 
364
 
365
 
366 80 mohor
// Initial values
367 2 mohor
initial
368
begin
369 80 mohor
  test_enabled = 1'b0;
370 99 mohor
  crc_out_en = 1'b0;
371
  crc_out_shift = 1'b0;
372 88 mohor
  wb_data = 32'h01234567;
373 80 mohor
  trst_pad_i = 1'b1;
374
  tms_pad_i = 1'hz;
375
  tck_pad_i = 1'hz;
376
  tdi_pad_i = 1'hz;
377
 
378
  #100;
379
  trst_pad_i = 1'b0;
380
  #100;
381
  trst_pad_i = 1'b1;
382
  #1 test_enabled<=#1 1'b1;
383 2 mohor
end
384
 
385 80 mohor
initial
386
begin
387
  wb_rst_i = 1'b0;
388
  #1000;
389
  wb_rst_i = 1'b1;
390
  #1000;
391
  wb_rst_i = 1'b0;
392 2 mohor
 
393 80 mohor
  // Initial values for wishbone slave model
394 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
395 80 mohor
end
396
 
397
initial
398 2 mohor
begin
399 80 mohor
  wb_clk_i = 1'b0;
400
  forever #5 wb_clk_i = ~wb_clk_i;
401 2 mohor
end
402
 
403 80 mohor
always @ (posedge test_enabled)
404
begin
405 2 mohor
 
406 80 mohor
  $display("//////////////////////////////////////////////////////////////////");
407
  $display("//                                                              //");
408
  $display("//  (%0t) dbg_tb starting                                     //", $time);
409
  $display("//                                                              //");
410
  $display("//////////////////////////////////////////////////////////////////");
411 2 mohor
 
412 80 mohor
  initialize_memory(32'h12340000, 32'h00100000);  // Initialize 0x100000 bytes starting from address 0x12340000
413 2 mohor
 
414 80 mohor
  reset_tap;
415 95 mohor
 
416
  #500;
417 80 mohor
  goto_run_test_idle;
418 12 mohor
 
419 80 mohor
  // Testing read and write to internal registers
420
  #10000;
421
  set_instruction(`IDCODE);
422
  read_id_code;
423 12 mohor
 
424 80 mohor
  set_instruction(`DEBUG);
425
  #10000;
426 2 mohor
 
427 99 mohor
  chain_select(`WISHBONE_SCAN_CHAIN, 1'b0);   // {chain, gen_crc_err}
428 12 mohor
 
429 80 mohor
//  #10000;
430
//  xxx(4'b1001, 32'he579b242);
431 12 mohor
 
432 80 mohor
  #10000;
433 2 mohor
 
434 99 mohor
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "abc 1"); // {command, ready, addr, length, gen_crc_err, result, text}
435
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345679, 16'h4, 1'b0, result, "abc 2"); // {command, ready, addr, length, gen_crc_err, result, text}
436
//  debug_wishbone(`WB_READ8, 1'b0, 32'h1234567a, 16'h4, 1'b0, result, "abc 3"); // {command, ready, addr, length, gen_crc_err, result, text}
437 88 mohor
//
438 99 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "abc 4"); // {command, ready, addr, length, gen_crc_err, result, text}
439
//  debug_wishbone(`WB_READ16, 1'b0, 32'h1234567a, 16'h4, 1'b0, result, "abc 5"); // {command, ready, addr, length, gen_crc_err, result, text}
440 88 mohor
//
441 99 mohor
  debug_wishbone(`WB_READ32, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "read32 1"); // {command, ready, addr, length, gen_crc_err, result, text}
442 88 mohor
//
443 99 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345679, 16'h4, 1'b0, result, "abc 6"); // {command, ready, addr, length, gen_crc_err, result, text}
444 2 mohor
 
445 80 mohor
  #10000;
446
//  xxx(4'b1001, 32'he579b242);
447
 
448 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12345678, 16'h4, 1'b0, result, "read32 2"); // {command, ready, addr, length, gen_crc_err, result, text}
449 87 mohor
 
450
  #10000;
451 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
452 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, result, "read32 3"); // {command, ready, addr, length, gen_crc_err, result, text}
453 80 mohor
 
454
  #10000;
455 96 mohor
  wb_slave.cycle_response(`ERR_RESPONSE, 9'h03, 8'h2);   // (`ERR_RESPONSE, wbs_waits, wbs_retries);
456 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, result, "read32 4"); // {command, ready, addr, length, gen_crc_err, result, text}
457 80 mohor
 
458
  #10000;
459 99 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, result, "status 1"); // {command, ready, addr, length, gen_crc_err, result, text}
460 80 mohor
 
461 87 mohor
  #10000;
462 99 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, result, "status 2"); // {command, ready, addr, length, gen_crc_err, result, text}
463 80 mohor
 
464 87 mohor
  #10000;
465 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h012, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
466 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12347778, 16'hc, 1'b0, result, "read32 5"); // {command, ready, addr, length, gen_crc_err, result, text}
467 80 mohor
 
468 87 mohor
  #10000;
469 99 mohor
  debug_wishbone(`WB_WRITE32, 1'b0, 32'h12346668, 16'h8, 1'b0, result, "wr32 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
470 87 mohor
 
471
  #10000;
472 99 mohor
  debug_wishbone(`WB_WRITE16, 1'b0, 32'h12344446, 16'h8, 1'b0, result, "wr16 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
473 87 mohor
 
474 88 mohor
  #10000;
475 99 mohor
  debug_wishbone(`WB_WRITE8, 1'b0, 32'h1234010e, 16'h8, 1'b0, result, "wr8 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
476 87 mohor
 
477 88 mohor
  #10000;
478 99 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, result, "go 1"); // {command, ready, addr, length, gen_crc_err, result, text}
479 87 mohor
 
480 89 mohor
  #10000;
481 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12340100, 16'hc, 1'b0, result, "read32 6"); // {command, ready, addr, length, gen_crc_err, result, text}
482
//  debug_wishbone(`WB_READ32, 1'b1, 32'h12340100, 16'hfffc, 1'b0, result, "read32 6"); // {command, ready, addr, length, gen_crc_err, result, text}
483 88 mohor
 
484 89 mohor
  #10000;
485 99 mohor
//  debug_wishbone(`WB_READ16, 1'b1, 32'h12340102, 16'he, 1'b0, result, "read16 7"); // {command, ready, addr, length, gen_crc_err, result, text}
486
//  debug_wishbone(`WB_READ16, 1'b1, 32'h12340102, 16'hfffe, 1'b0, result, "read16 7"); // {command, ready, addr, length, gen_crc_err, result, text}
487 88 mohor
 
488 90 mohor
  #10000;
489 99 mohor
//  debug_wishbone(`WB_READ8, 1'b1, 32'h12348804, 16'h6, 1'b0, result, "read8 8"); // {command, ready, addr, length, gen_crc_err, result, text}  
490
//  debug_wishbone(`WB_READ8, 1'b1, 32'h12348804, 16'hfffc, 1'b0, result, "read8 8"); // {command, ready, addr, length, gen_crc_err, result, text}
491 89 mohor
 
492 90 mohor
  #10000;
493 99 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, result, "go 2"); // {command, ready, addr, length, gen_crc_err, result, text}
494 89 mohor
 
495 99 mohor
  #10000;
496
  chain_select(`CPU_DEBUG_CHAIN, 1'b0);   // {chain, gen_crc_err}
497 89 mohor
 
498 101 mohor
 
499
 
500
 
501
  // Select cpu0
502 99 mohor
  #10000;
503 101 mohor
  debug_cpu(`CPU_WRITE_REG, `CPU_SEL_ADR, 32'h0, 1'b0, result, "select cpu 0"); // {command, addr, data, gen_crc_err, result, text}
504 90 mohor
 
505 99 mohor
  #10000;
506 101 mohor
  debug_cpu(`CPU_GO, 32'h0, 32'h1, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
507
 
508
  // Read register
509
  #10000;
510
  debug_cpu(`CPU_READ_REG, `CPU_SEL_ADR, 32'h0, 1'b0, result, "cpu_read_reg"); // {command, addr, data, gen_crc_err, result, text}
511
 
512
  #10000;
513 99 mohor
  debug_cpu(`CPU_GO, 32'h0, 32'hff, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
514 90 mohor
 
515 101 mohor
  // Stall cpu0
516
  #10000;
517
  debug_cpu(`CPU_WRITE_REG, `CPU_OP_ADR, 32'h0, 1'b0, result, "stall cpu0"); // {command, addr, data, gen_crc_err, result, text}
518 99 mohor
 
519 101 mohor
  #10000;
520
  debug_cpu(`CPU_GO, 32'h0, 32'h1, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
521
 
522
  // write to cpu 32-bit
523
  #10000;
524
  debug_cpu(`CPU_WRITE32, 32'h32323232, 32'h0, 1'b0, result, "cpu_write_32"); // {command, addr, data, gen_crc_err, result, text}
525
 
526
  #10000;
527
  debug_cpu(`CPU_GO, 32'h0, 32'hdeadbeef, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
528
 
529 102 mohor
  // read from cpu 32-bit
530 101 mohor
  #10000;
531
  debug_cpu(`CPU_READ32, 32'h32323232, 32'h0, 1'b0, result, "cpu_read_32"); // {command, addr, data, gen_crc_err, result, text}
532
 
533
  #10000;
534
  debug_cpu(`CPU_GO, 32'h0, 32'hdeadbeef, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
535
 
536
  // write to cpu 8-bit
537
  #10000;
538
  debug_cpu(`CPU_WRITE8, 32'h08080808, 32'h0, 1'b0, result, "cpu_write_8"); // {command, addr, data, gen_crc_err, result, text}
539
 
540
  #10000;
541
  debug_cpu(`CPU_GO, 32'h0, 32'hdeadbeef, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
542
 
543 102 mohor
  // read from cpu 8-bit
544 101 mohor
  #10000;
545
  debug_cpu(`CPU_READ8, 32'h08080808, 32'h0, 1'b0, result, "cpu_read_8"); // {command, addr, data, gen_crc_err, result, text}
546
 
547
  #10000;
548
  debug_cpu(`CPU_GO, 32'h0, 32'hdeadbeef, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
549
 
550 80 mohor
/*
551
  // Testing read and write to CPU0 registers
552
  #10000;
553
  set_instruction(`CHAIN_SELECT);
554
  chain_select(`CPU_DEBUG_CHAIN_0, 8'h12);  // {chain, crc}
555
  set_instruction(`DEBUG);
556
  WriteCPURegister(32'h11001100, 32'h00110011, 8'h86);  // {data, addr, crc}
557
 
558
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
559
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
560
*/
561
  #5000 gen_clk(1);            // One extra TCLK for debugging purposes
562 95 mohor
  $display("\n\nSimulation end.");
563 5 mohor
  #1000 $stop;
564 80 mohor
 
565 2 mohor
end
566
 
567 80 mohor
 
568
task initialize_memory;
569
  input [31:0] start_addr;
570
  input [31:0] length;
571
  integer i;
572
  reg [31:0] addr;
573
  begin
574 96 mohor
//    for (i=0; i<length; i=i+4)    // inverted address
575
//      begin
576
//        addr = start_addr + i;
577
//        wb_slave.wr_mem(addr, {addr[7:0], addr[15:8], addr[23:16], addr[31:24]}, 4'hf);    // adr, data, sel
578
//      end
579 80 mohor
    for (i=0; i<length; i=i+4)
580
      begin
581
        addr = start_addr + i;
582 96 mohor
        wb_slave.wr_mem(addr, {addr[7:0], addr[7:0]+2'd1, addr[7:0]+2'd2, addr[7:0]+2'd3}, 4'hf);    // adr, data, sel
583 80 mohor
      end
584
  end
585
endtask
586
 
587
 
588
 
589 2 mohor
// Generation of the TCLK signal
590 80 mohor
task gen_clk;
591
  input [7:0] num;
592 2 mohor
  integer i;
593
  begin
594 80 mohor
    for(i=0; i<num; i=i+1)
595 2 mohor
      begin
596 80 mohor
        #TCLK tck_pad_i<=1;
597
        #TCLK tck_pad_i<=0;
598 2 mohor
      end
599
  end
600
endtask
601
 
602
 
603
// TAP reset
604 80 mohor
task reset_tap;
605 2 mohor
  begin
606 80 mohor
    $display("(%0t) Task reset_tap", $time);
607
    tms_pad_i<=#1 1'b1;
608 95 mohor
    gen_clk(5);
609 2 mohor
  end
610
endtask
611
 
612
 
613
// Goes to RunTestIdle state
614 80 mohor
task goto_run_test_idle;
615 2 mohor
  begin
616 80 mohor
    $display("(%0t) Task goto_run_test_idle", $time);
617
    tms_pad_i<=#1 1'b0;
618
    gen_clk(1);
619 2 mohor
  end
620
endtask
621
 
622
 
623
// sets the instruction to the IR register and goes to the RunTestIdle state
624 80 mohor
task set_instruction;
625
  input [3:0] instr;
626 2 mohor
  integer i;
627
 
628
  begin
629 80 mohor
    $display("(%0t) Task set_instruction", $time);
630
    tms_pad_i<=#1 1;
631
    gen_clk(2);
632
    tms_pad_i<=#1 0;
633
    gen_clk(2);  // we are in shiftIR
634 2 mohor
 
635
    for(i=0; i<`IR_LENGTH-1; i=i+1)
636
    begin
637 80 mohor
      tdi_pad_i<=#1 instr[i];
638
      gen_clk(1);
639 2 mohor
    end
640
 
641 80 mohor
    tdi_pad_i<=#1 instr[i]; // last shift
642
    tms_pad_i<=#1 1;        // going out of shiftIR
643
    gen_clk(1);
644 90 mohor
    tdi_pad_i<=#1 'hz;    // tri-state
645 80 mohor
    gen_clk(1);
646
    tms_pad_i<=#1 0;
647
    gen_clk(1);       // we are in RunTestIdle
648 2 mohor
  end
649
endtask
650
 
651
 
652 80 mohor
// Reads the ID code
653
task read_id_code;
654
  begin
655
    $display("(%0t) Task read_id_code", $time);
656
    tms_pad_i<=#1 1;
657
    gen_clk(1);
658
    tms_pad_i<=#1 0;
659
    gen_clk(2);  // we are in shiftDR
660
 
661
    tdi_pad_i<=#1 0;
662
    gen_clk(31);
663
 
664
    tms_pad_i<=#1 1;        // going out of shiftIR
665
    gen_clk(1);
666
 
667
    tdi_pad_i<=#1 'hz; // tri-state
668
    gen_clk(1);
669
    tms_pad_i<=#1 0;
670
    gen_clk(1);       // we are in RunTestIdle
671
  end
672
endtask
673
 
674
 
675 2 mohor
// sets the selected scan chain and goes to the RunTestIdle state
676 80 mohor
task chain_select;
677
  input [3:0]  data;
678 99 mohor
  input        gen_crc_err;
679 2 mohor
  integer i;
680
 
681
  begin
682 99 mohor
    case (data)
683
      `CPU_DEBUG_CHAIN      : $display("(%0t) Task chain_select (CPU_DEBUG_CHAIN, gen_crc_err=%0d)", $time, gen_crc_err);
684
      `WISHBONE_SCAN_CHAIN  : $display("(%0t) Task chain_select (WISHBONE_SCAN_CHAIN gen_crc_err=%0d)", $time, gen_crc_err);
685
      default               : $display("(%0t) Task chain_select (ERROR!!! Unknown chain selected)", $time);
686
    endcase
687
 
688 80 mohor
    tms_pad_i<=#1 1;
689
    gen_clk(1);
690
    tms_pad_i<=#1 0;
691
    gen_clk(2);  // we are in shiftDR
692 2 mohor
 
693 99 mohor
    crc_out_en = 1; // Enable CRC calculation
694
 
695 80 mohor
    tdi_pad_i<=#1 1'b1; // chain_select bit
696
    gen_clk(1);
697
 
698 2 mohor
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
699
    begin
700 80 mohor
      tdi_pad_i<=#1 data[i];
701
      gen_clk(1);
702 2 mohor
    end
703
 
704 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
705
    crc_out_shift = 1;  // Enable CRC shifting
706
 
707
    for(i=31; i>=0; i=i-1)
708 2 mohor
    begin
709 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
710
        tdi_pad_i<=#1 ~crc_out;   // error crc
711
      else
712
        tdi_pad_i<=#1 crc_out;    // ok crc
713
 
714 80 mohor
      gen_clk(1);
715 2 mohor
    end
716
 
717 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
718
 
719
    tdi_pad_i<=#1 'hz;  // tri-state
720
 
721 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
722
 
723
 
724
    for(i=0; i<`CRC_LEN -1; i=i+1)
725
      gen_clk(1);
726
 
727
    tms_pad_i<=#1 1;
728
    gen_clk(1);         // to exit1_dr
729
 
730
    tdi_pad_i<=#1 'hz;  // tri-state
731
    tms_pad_i<=#1 1;
732
    gen_clk(1);         // to update_dr
733
    tms_pad_i<=#1 0;
734
    gen_clk(1);         // to run_test_idle
735 2 mohor
  end
736 99 mohor
endtask   // chain_select
737 2 mohor
 
738
 
739 87 mohor
 
740
 
741
 
742
 
743
 
744 80 mohor
task debug_wishbone;
745
  input [2:0]   command;
746 87 mohor
  input         ready;
747 80 mohor
  input [31:0]  addr;
748
  input [15:0]  length;
749 99 mohor
  input         gen_crc_err;
750 80 mohor
  output [31:0] result;
751 87 mohor
  input [99:0]  text;
752 80 mohor
  integer i;
753
 
754 2 mohor
  begin
755 80 mohor
   $write("(%0t) Task debug_wishbone: ", $time);
756 2 mohor
 
757 87 mohor
    test_text = text;
758 36 mohor
 
759 80 mohor
    case (command)
760
      `WB_STATUS   :
761
        begin
762 99 mohor
          $display("wb_status (gen_crc_err=%0d (%0s))", gen_crc_err, text);
763
          debug_wishbone_status(command, gen_crc_err);
764 88 mohor
          last_wb_cmd = `WB_STATUS;  last_wb_cmd_text = "WB_STATUS";
765 80 mohor
        end
766
      `WB_READ8    :
767
        begin
768 99 mohor
          $display("wb_read8 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
769
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
770 88 mohor
          last_wb_cmd = `WB_READ8;  last_wb_cmd_text = "WB_READ8";
771 80 mohor
        end
772
      `WB_READ16   :
773
        begin
774 99 mohor
          $display("wb_read16 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
775
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
776 88 mohor
          last_wb_cmd = `WB_READ16;  last_wb_cmd_text = "WB_READ16";
777 80 mohor
        end
778
      `WB_READ32   :
779
        begin
780 99 mohor
          $display("wb_read32 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
781
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
782 88 mohor
          last_wb_cmd = `WB_READ32;  last_wb_cmd_text = "WB_READ32";
783 80 mohor
        end
784
      `WB_WRITE8   :
785
        begin
786 99 mohor
          $display("wb_write8 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
787
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
788 88 mohor
          last_wb_cmd = `WB_WRITE8;  last_wb_cmd_text = "WB_WRITE8";
789 80 mohor
        end
790
      `WB_WRITE16  :
791
        begin
792 99 mohor
          $display("wb_write16 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
793
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
794 88 mohor
          last_wb_cmd = `WB_WRITE16;  last_wb_cmd_text = "WB_WRITE16";
795 80 mohor
        end
796
      `WB_WRITE32  :
797
        begin
798 99 mohor
          $display("wb_write32 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
799
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
800 88 mohor
          last_wb_cmd = `WB_WRITE32;  last_wb_cmd_text = "WB_WRITE32";
801 80 mohor
        end
802
      `WB_GO       :
803
        begin
804 99 mohor
          $display("wb_go, gen_crc_err=%0d (%0s))", gen_crc_err, text);
805
          debug_wishbone_go(command, gen_crc_err);
806
//          $display("wb_go_tmp, gen_crc_err=0x%0x (%0s))", gen_crc_err, text);
807 93 mohor
//          debug_wishbone_go_tmp(command, crc);
808 88 mohor
          last_wb_cmd = `WB_GO;  last_wb_cmd_text = "WB_GO";
809 80 mohor
        end
810
    endcase
811 2 mohor
  end
812 87 mohor
endtask       // debug_wishbone
813 2 mohor
 
814
 
815 80 mohor
 
816
 
817
 
818
 
819 87 mohor
task debug_wishbone_set_addr;
820 80 mohor
  input [2:0]   command;
821 99 mohor
  input         wait_for_wb_ready;    // igor !!! Change this since access only occurs in the "go" stage. Add condition "fifo_empty".
822 80 mohor
  input [31:0]  addr;
823
  input [15:0]  length;
824 99 mohor
  input         gen_crc_err;
825 80 mohor
  integer i;
826
 
827
  begin
828 87 mohor
    $display("(%0t) Task debug_wishbone_set_addr: ", $time);
829 80 mohor
 
830
    tms_pad_i<=#1 1;
831
    gen_clk(1);
832
    tms_pad_i<=#1 0;
833
    gen_clk(2);  // we are in shiftDR
834
 
835 99 mohor
    crc_out_en = 1; // Enable CRC calculation
836
 
837 80 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
838
    gen_clk(1);
839
 
840 88 mohor
    for(i=2; i>=0; i=i-1)
841 80 mohor
    begin
842
      tdi_pad_i<=#1 command[i]; // command
843
      gen_clk(1);
844
    end
845
 
846 88 mohor
    for(i=31; i>=0; i=i-1)       // address
847 80 mohor
    begin
848
      tdi_pad_i<=#1 addr[i];
849
      gen_clk(1);
850
    end
851 87 mohor
 
852 88 mohor
    for(i=15; i>=0; i=i-1)       // length
853 80 mohor
    begin
854
      tdi_pad_i<=#1 length[i];
855
      gen_clk(1);
856
    end
857
 
858 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
859
    crc_out_shift = 1;  // Enable CRC shifting
860
 
861 88 mohor
    for(i=31; i>=0; i=i-1)
862 80 mohor
    begin
863 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
864
        tdi_pad_i<=#1 ~crc_out;   // error crc
865
      else
866
        tdi_pad_i<=#1 crc_out;    // ok crc
867
 
868 80 mohor
      gen_clk(1);
869
    end
870
 
871 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
872
 
873 92 mohor
    tdi_pad_i<=#1 'hz;
874 87 mohor
    if (wait_for_wb_ready)
875
      begin
876
        gen_clk(`STATUS_LEN -1);   // Generating 4 clocks to read out status. Going to pause_dr at the end
877
        tms_pad_i<=#1 1;
878
        gen_clk(1);       // to exit1_dr
879
        tms_pad_i<=#1 0;
880
        gen_clk(1);       // to pause_dr
881
 
882
        while (dbg_tb.tdo_pad_o)     // waiting for wb to send "ready" 
883
        begin
884
          gen_clk(1);       // staying in pause_dr
885
        end
886
 
887
        tms_pad_i<=#1 1;
888
        gen_clk(1);       // to exit2_dr
889
        tms_pad_i<=#1 0;
890
        gen_clk(1);       // to shift_dr
891
      end
892
    else
893
      gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
894 80 mohor
 
895 88 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
896 80 mohor
    begin
897
      gen_clk(1);
898
    end
899
 
900
    tms_pad_i<=#1 1;
901
    gen_clk(1);         // to exit1_dr
902
 
903
    tms_pad_i<=#1 1;
904
    gen_clk(1);         // to update_dr
905
    tms_pad_i<=#1 0;
906
    gen_clk(1);         // to run_test_idle
907
  end
908 87 mohor
endtask       // debug_wishbone_set_addr
909 80 mohor
 
910
 
911
 
912
 
913
 
914 88 mohor
task debug_wishbone_status;
915
  input [2:0]   command;
916 99 mohor
  input         gen_crc_err;
917 88 mohor
  integer i;
918
 
919
  begin
920
    $display("(%0t) Task debug_wishbone_status: ", $time);
921 80 mohor
 
922 88 mohor
    tms_pad_i<=#1 1;
923
    gen_clk(1);
924
    tms_pad_i<=#1 0;
925
    gen_clk(2);  // we are in shiftDR
926 87 mohor
 
927 99 mohor
    crc_out_en = 1; // Enable CRC calculation
928
 
929 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
930
    gen_clk(1);
931 87 mohor
 
932 88 mohor
    for(i=2; i>=0; i=i-1)
933
    begin
934
      tdi_pad_i<=#1 command[i]; // command
935
      gen_clk(1);
936
    end
937 87 mohor
 
938 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
939
    crc_out_shift = 1;  // Enable CRC shifting
940
 
941
    for(i=31; i>=0; i=i-1)
942 88 mohor
    begin
943 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
944
        tdi_pad_i<=#1 ~crc_out;   // error crc
945
      else
946
        tdi_pad_i<=#1 crc_out;    // ok crc
947
 
948 88 mohor
      gen_clk(1);
949
    end
950
 
951 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
952
 
953 92 mohor
    tdi_pad_i<=#1 1'hz;
954 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
955
 
956
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
957
    begin
958
      gen_clk(1);
959
    end
960
 
961
    tms_pad_i<=#1 1;
962
    gen_clk(1);         // to exit1_dr
963
 
964
    tms_pad_i<=#1 1;
965
    gen_clk(1);         // to update_dr
966
    tms_pad_i<=#1 0;
967
    gen_clk(1);         // to run_test_idle
968
  end
969
endtask       // debug_wishbone_status
970
 
971
 
972
 
973
 
974
task debug_wishbone_go;
975
  input [2:0]   command;
976 99 mohor
  input         gen_crc_err;
977 90 mohor
  integer i;
978
  reg   [4:0]   pointer;
979
 
980 2 mohor
  begin
981 88 mohor
    $display("(%0t) Task debug_wishbone_go (previous command was %0s): ", $time, last_wb_cmd_text);
982
 
983 80 mohor
    tms_pad_i<=#1 1;
984
    gen_clk(1);
985
    tms_pad_i<=#1 0;
986
    gen_clk(2);  // we are in shiftDR
987 2 mohor
 
988 99 mohor
    crc_out_en = 1; // Enable CRC calculation
989
 
990 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
991 80 mohor
    gen_clk(1);
992 88 mohor
 
993
    for(i=2; i>=0; i=i-1)
994
    begin
995
      tdi_pad_i<=#1 command[i]; // command
996
      gen_clk(1);
997
    end
998
 
999
 
1000
    if ((last_wb_cmd == `WB_WRITE8) | (last_wb_cmd == `WB_WRITE16) | (last_wb_cmd == `WB_WRITE32))  // When WB_WRITEx was previously activated, data needs to be shifted.
1001
      begin
1002 90 mohor
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.len << 3); i=i+1)
1003 88 mohor
          begin
1004 90 mohor
            if (!(i%32))
1005 88 mohor
              begin
1006 90 mohor
                wb_data = wb_data + 32'h11111111;
1007
                $display("\t\twb_data = 0x%x", wb_data);
1008 88 mohor
              end
1009 90 mohor
            pointer = 31-i[4:0];
1010
            tdi_pad_i<=#1 wb_data[pointer];
1011
            gen_clk(1);
1012
 
1013 88 mohor
          end
1014
      end
1015
 
1016 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
1017
    crc_out_shift = 1;  // Enable CRC shifting
1018 88 mohor
 
1019 99 mohor
    for(i=31; i>=0; i=i-1)
1020 88 mohor
    begin
1021 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1022
        tdi_pad_i<=#1 ~crc_out;   // error crc
1023
      else
1024
        tdi_pad_i<=#1 crc_out;    // ok crc
1025
 
1026 88 mohor
      gen_clk(1);
1027
    end
1028
 
1029 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
1030
 
1031 92 mohor
    tdi_pad_i<=#1 1'hz;
1032 90 mohor
 
1033
 
1034
 
1035
    if ((last_wb_cmd == `WB_READ8) | (last_wb_cmd == `WB_READ16) | (last_wb_cmd == `WB_READ32))  // When WB_WRITEx was previously activated, data needs to be shifted.
1036
      begin
1037 95 mohor
        $display("\t\tGenerating %0d clocks to read %0d data bytes.", dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit, dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit>>3);
1038
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit); i=i+1)
1039 92 mohor
          gen_clk(1);
1040 90 mohor
      end
1041
 
1042
 
1043 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
1044
 
1045
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
1046
    begin
1047
      gen_clk(1);
1048
    end
1049
 
1050
    tms_pad_i<=#1 1;
1051
    gen_clk(1);         // to exit1_dr
1052
 
1053
    tms_pad_i<=#1 1;
1054
    gen_clk(1);         // to update_dr
1055 80 mohor
    tms_pad_i<=#1 0;
1056 88 mohor
    gen_clk(1);         // to run_test_idle
1057 2 mohor
  end
1058 88 mohor
endtask       // debug_wishbone_go
1059 2 mohor
 
1060
 
1061 88 mohor
 
1062
 
1063 99 mohor
task debug_cpu;
1064
  input [2:0]   command;
1065
  input [31:0]  addr;
1066
  input [31:0]  data;
1067
  input         gen_crc_err;
1068
  output [31:0] result;
1069
  input [199:0]  text;
1070
  integer i;
1071
 
1072
  begin
1073
   $write("(%0t) Task debug_cpu: ", $time);
1074 88 mohor
 
1075 99 mohor
    test_text = text;
1076
 
1077
    case (command)
1078
//      `WB_STATUS   : 
1079
//        begin
1080
//          $display("wb_status (gen_crc_err=%0d (%0s))", gen_crc_err, text);
1081
//          debug_wishbone_status(command, gen_crc_err);
1082
//          last_wb_cmd = `WB_STATUS;  last_wb_cmd_text = "WB_STATUS";
1083
//        end 
1084
      `CPU_READ_REG   :
1085
        begin
1086
          $display("cpu_read_reg (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1087
          debug_cpu_set_addr(command, addr, gen_crc_err);
1088
          last_wb_cmd = `CPU_READ_REG;  last_wb_cmd_text = "CPU_READ_REG";
1089
        end
1090
      `CPU_WRITE_REG  :
1091
        begin
1092
          $display("cpu_write_reg (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1093
          debug_cpu_set_addr(command, addr, gen_crc_err);
1094
          last_wb_cmd = `CPU_WRITE_REG;  last_wb_cmd_text = "CPU_WRITE_REG";
1095
        end
1096
      `CPU_READ8      :
1097
        begin
1098
          $display("cpu_read8 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1099
          debug_cpu_set_addr(command, addr, gen_crc_err);
1100
          last_wb_cmd = `CPU_READ8;  last_wb_cmd_text = "CPU_READ8";
1101
        end
1102
      `CPU_READ32     :
1103
        begin
1104
          $display("cpu_read32 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1105
          debug_cpu_set_addr(command, addr, gen_crc_err);
1106
          last_wb_cmd = `CPU_READ32;  last_wb_cmd_text = "CPU_READ32";
1107
        end
1108
      `CPU_WRITE8     :
1109
        begin
1110
          $display("cpu_write8 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1111
          debug_cpu_set_addr(command, addr, gen_crc_err);
1112
          last_wb_cmd = `CPU_WRITE8;  last_wb_cmd_text = "CPU_WRITE8";
1113
        end
1114
      `CPU_WRITE32    :
1115
        begin
1116
          $display("cpu_write32 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1117
          debug_cpu_set_addr(command, addr, gen_crc_err);
1118
          last_wb_cmd = `CPU_WRITE32;  last_wb_cmd_text = "CPU_WRITE32";
1119
        end
1120
      `CPU_GO         :
1121
        begin
1122
          $display("cpu_go, data = 0x%0x, gen_crc_err=%0d (%0s))", data, gen_crc_err, text);
1123
          debug_cpu_go(command, data, gen_crc_err);
1124
          last_wb_cmd = `CPU_GO;  last_wb_cmd_text = "CPU_GO";
1125
        end
1126
      default     :
1127
        begin
1128
          $display("\t\tERROR: Non-existing command while debugging %0s", gen_crc_err, text);
1129
          $stop;
1130
        end
1131
    endcase
1132
  end
1133
endtask       // debug_cpu
1134
 
1135
 
1136
 
1137
task debug_cpu_set_addr;
1138 93 mohor
  input [2:0]   command;
1139 99 mohor
  input [31:0]  addr;
1140
  input         gen_crc_err;
1141 93 mohor
  integer i;
1142 99 mohor
 
1143
  begin
1144
    $display("(%0t) Task debug_cpu_set_addr: ", $time);
1145
 
1146
    tms_pad_i<=#1 1;
1147
    gen_clk(1);
1148
    tms_pad_i<=#1 0;
1149
    gen_clk(2);  // we are in shiftDR
1150
 
1151
    crc_out_en = 1; // Enable CRC calculation
1152
 
1153
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
1154
    gen_clk(1);
1155
 
1156
    for(i=2; i>=0; i=i-1)
1157
    begin
1158
      tdi_pad_i<=#1 command[i]; // command
1159
      gen_clk(1);
1160
    end
1161
 
1162
    for(i=31; i>=0; i=i-1)       // address
1163
    begin
1164
      tdi_pad_i<=#1 addr[i];
1165
      gen_clk(1);
1166
    end
1167 93 mohor
 
1168 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
1169
    crc_out_shift = 1;  // Enable CRC shifting
1170
 
1171
    for(i=31; i>=0; i=i-1)
1172
    begin
1173
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1174
        tdi_pad_i<=#1 ~crc_out;   // error crc
1175
      else
1176
        tdi_pad_i<=#1 crc_out;    // ok crc
1177
 
1178
      gen_clk(1);
1179
    end
1180
 
1181
    crc_out_shift = 0;  // Disable CRC shifting
1182
 
1183
    tdi_pad_i<=#1 'hz;
1184
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
1185
 
1186
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
1187
    begin
1188
      gen_clk(1);
1189
    end
1190
 
1191
    tms_pad_i<=#1 1;
1192
    gen_clk(1);         // to exit1_dr
1193
 
1194
    tms_pad_i<=#1 1;
1195
    gen_clk(1);         // to update_dr
1196
    tms_pad_i<=#1 0;
1197
    gen_clk(1);         // to run_test_idle
1198
  end
1199
endtask       // debug_cpu_set_addr
1200
 
1201
 
1202
 
1203
 
1204
task debug_cpu_go;
1205
  input [2:0]   command;
1206
  input [31:0]  data;
1207
  input         gen_crc_err;
1208
  integer i, len;
1209
 
1210
 
1211 93 mohor
  begin
1212 99 mohor
    $display("(%0t) Task debug_cpu_go (previous command was %0s): ", $time, last_wb_cmd_text);
1213 88 mohor
 
1214 93 mohor
    tms_pad_i<=#1 1;
1215
    gen_clk(1);
1216
    tms_pad_i<=#1 0;
1217
    gen_clk(2);  // we are in shiftDR
1218 88 mohor
 
1219 99 mohor
    crc_out_en = 1; // Enable CRC calculation
1220
 
1221 93 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
1222
    gen_clk(1);
1223 88 mohor
 
1224 93 mohor
    for(i=2; i>=0; i=i-1)
1225
    begin
1226
      tdi_pad_i<=#1 command[i]; // command
1227
      gen_clk(1);
1228
    end
1229 88 mohor
 
1230
 
1231 99 mohor
    if (last_wb_cmd == `CPU_WRITE32)
1232 93 mohor
      begin
1233 99 mohor
        len = 31;
1234
        $display("\t\tdata = 0x%x", data);
1235
      end
1236
    else if ((last_wb_cmd == `CPU_WRITE8) | (last_wb_cmd == `CPU_WRITE_REG))
1237
      begin
1238
        len = 7;
1239
        $display("\t\tdata = 0x%x", data[7:0]);
1240
      end
1241
    else
1242
      len = 0;
1243
 
1244
    if (len>0)  // When CPU_WRITEx was previously activated, data needs to be shifted.
1245
      begin
1246
        for (i=len; i>=0; i=i-1)
1247 93 mohor
          begin
1248 99 mohor
            tdi_pad_i<=#1 data[i];
1249 93 mohor
            gen_clk(1);
1250
          end
1251
      end
1252 2 mohor
 
1253 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
1254
    crc_out_shift = 1;  // Enable CRC shifting
1255 2 mohor
 
1256 99 mohor
    for(i=31; i>=0; i=i-1)
1257 93 mohor
    begin
1258 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1259
        tdi_pad_i<=#1 ~crc_out;   // error crc
1260
      else
1261
        tdi_pad_i<=#1 crc_out;    // ok crc
1262
 
1263 93 mohor
      gen_clk(1);
1264
    end
1265
 
1266 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
1267
 
1268 93 mohor
    tdi_pad_i<=#1 1'hz;
1269
 
1270
 
1271 99 mohor
    if (last_wb_cmd == `CPU_READ32)
1272
      len = 32;
1273
    else if ((last_wb_cmd == `CPU_READ8) | (last_wb_cmd == `CPU_READ_REG))
1274
      len = 8;
1275
    else
1276
      len = 0;
1277 93 mohor
 
1278 99 mohor
    if (len>0)    // When CPU_WRITEx was previously activated, data needs to be shifted.
1279 93 mohor
      begin
1280 99 mohor
        $display("\t\tGenerating %0d clocks to read out the data.", len);
1281
        for (i=0; i<len; i=i+1)
1282 93 mohor
          gen_clk(1);
1283
      end
1284
 
1285
 
1286
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
1287
 
1288
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
1289
    begin
1290
      gen_clk(1);
1291
    end
1292
 
1293
    tms_pad_i<=#1 1;
1294
    gen_clk(1);         // to exit1_dr
1295
 
1296
    tms_pad_i<=#1 1;
1297
    gen_clk(1);         // to update_dr
1298
    tms_pad_i<=#1 0;
1299
    gen_clk(1);         // to run_test_idle
1300
  end
1301 99 mohor
endtask       // debug_cpu_go
1302 93 mohor
 
1303
 
1304
 
1305
 
1306
 
1307
 
1308
 
1309
 
1310
 
1311
 
1312
 
1313
 
1314
 
1315 99 mohor
 
1316 2 mohor
/**********************************************************************************
1317
*                                                                                 *
1318
*   Printing the information to the screen                                        *
1319
*                                                                                 *
1320
**********************************************************************************/
1321
 
1322 80 mohor
always @ (posedge tck_pad_i)
1323 2 mohor
begin
1324 80 mohor
  if(dbg_tb.i_tap_top.update_ir)
1325
    case(dbg_tb.i_tap_top.jtag_ir[`IR_LENGTH-1:0])
1326
      `EXTEST         : $display("\tInstruction EXTEST entered");
1327
      `SAMPLE_PRELOAD : $display("\tInstruction SAMPLE_PRELOAD entered");
1328
      `IDCODE         : $display("\tInstruction IDCODE entered");
1329
      `MBIST          : $display("\tInstruction MBIST entered");
1330
      `DEBUG          : $display("\tInstruction DEBUG entered");
1331
      `BYPASS         : $display("\tInstruction BYPASS entered");
1332
                default           :     $display("\n\tInstruction not valid. Instruction BYPASS activated !!!");
1333 2 mohor
    endcase
1334
end
1335
 
1336
 
1337
 
1338
// Print shifted IDCode
1339 80 mohor
reg [31:0] tmp_data;
1340
always @ (posedge tck_pad_i)
1341 2 mohor
begin
1342 80 mohor
  if(dbg_tb.i_tap_top.idcode_select)
1343 2 mohor
    begin
1344 80 mohor
      if(dbg_tb.i_tap_top.shift_dr)
1345
        tmp_data[31:0]<=#1 {dbg_tb.tdo, tmp_data[31:1]};
1346 2 mohor
      else
1347 80 mohor
      if(dbg_tb.i_tap_top.update_dr)
1348
        if (tmp_data[31:0] != `IDCODE_VALUE)
1349 73 mohor
          begin
1350
            $display("(%0t) ERROR: IDCODE not correct", $time);
1351
            $stop;
1352
          end
1353
        else
1354 80 mohor
          $display("\t\tIDCode = 0x%h", tmp_data[31:0]);
1355 2 mohor
    end
1356
end
1357
 
1358
 
1359 80 mohor
// We never use following states: exit2_ir,  exit2_dr,  pause_ir or pause_dr
1360
always @ (posedge tck_pad_i)
1361 2 mohor
begin
1362 80 mohor
  if(dbg_tb.i_tap_top.pause_ir | dbg_tb.i_tap_top.exit2_ir)
1363 2 mohor
    begin
1364 80 mohor
      $display("\n(%0t) ERROR: State pause_ir or exit2_ir detected.", $time);
1365
      $display("(%0t) Simulation stopped !!!", $time);
1366
      $stop;
1367 2 mohor
    end
1368
end
1369
 
1370
 
1371 80 mohor
// sets the selected scan chain and goes to the RunTestIdle state
1372
task xxx;
1373
  input [3:0]  data;
1374
  input [31:0] crc;
1375
  integer i;
1376
 
1377
  begin
1378
    $display("(%0t) Task xxx", $time);
1379
    tms_pad_i<=#1 1;
1380
    gen_clk(1);
1381
    tms_pad_i<=#1 0;
1382
    gen_clk(2);  // we are in shiftDR
1383
 
1384
    for(i=0; i<4; i=i+1)
1385 73 mohor
    begin
1386 80 mohor
      tdi_pad_i<=#1 data[i];
1387
      gen_clk(1);
1388 73 mohor
    end
1389
 
1390 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
1391
    begin
1392
      tdi_pad_i<=#1 crc[`CRC_LEN - 1 - i];
1393
      gen_clk(1);
1394
    end
1395 73 mohor
 
1396 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
1397 73 mohor
 
1398
 
1399 80 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)
1400
    begin
1401
      tdi_pad_i<=#1 1'b0;
1402
      gen_clk(1);
1403
    end
1404 73 mohor
 
1405 80 mohor
    tdi_pad_i<=#1 crc[i]; // last crc
1406
    tms_pad_i<=#1 1;
1407
    gen_clk(1);         // to exit1_dr
1408 73 mohor
 
1409 80 mohor
    tdi_pad_i<=#1 'hz;  // tri-state
1410
    tms_pad_i<=#1 1;
1411
    gen_clk(1);         // to update_dr
1412
    tms_pad_i<=#1 0;
1413
    gen_clk(1);         // to run_test_idle
1414
  end
1415
endtask
1416 2 mohor
 
1417
 
1418 80 mohor
 
1419 88 mohor
// Detecting CRC error
1420 99 mohor
always @ (posedge dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_end or posedge dbg_tb.i_dbg_top.chain_latch_en)
1421 88 mohor
begin
1422
  #2;
1423
  if (~dbg_tb.i_dbg_top.crc_match)
1424
    begin
1425
      $display("\t\tCRC ERROR !!!");
1426 90 mohor
      $stop;
1427 88 mohor
    end
1428
end
1429 80 mohor
 
1430 88 mohor
 
1431 90 mohor
 
1432
// Detecting errors in counters
1433
always @ (dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt or
1434
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end or
1435
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt or
1436
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_end or
1437
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt or
1438
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end or
1439
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_en or
1440
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en or
1441
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en or
1442
          dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en or
1443
          dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1444
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt2 or
1445
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt3 or
1446
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt4
1447
          // dbg_tb.i_dbg_top.i_dbg_wb. or
1448
         )
1449
begin
1450
  if ((~dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end) & (
1451
                                                  dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en |
1452
                                                  dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en     |
1453
                                                  dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en      |
1454
                                                  dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1455
                                                 )
1456
     )
1457
    begin
1458
      $display("\n\n\t\t(%0t) ERROR in counters !!!", $time);
1459
      #10000;
1460
      $stop;
1461
    end
1462
 
1463
 
1464
 
1465
end
1466
 
1467
 
1468
 
1469
 
1470
 
1471 91 mohor
 
1472 80 mohor
endmodule // dbg_tb
1473
 
1474
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.