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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_21/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 110

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

powered by: WebSVN 2.1.0

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