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 111

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

powered by: WebSVN 2.1.0

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