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

Subversion Repositories dbg_interface

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

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 139 igorm
////  This file is part of the SoC Debug 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 139 igorm
// Revision 1.40  2004/03/22 16:36:06  igorm
47
// Temp version before changing dbg interface.
48
//
49 138 igorm
// Revision 1.39  2004/03/15 16:17:07  igorm
50
// 'hz changed to 1'hz because Icarus complains.
51
//
52 135 igorm
// Revision 1.38  2004/01/30 10:24:02  mohor
53
// Defines WISHBONE_SUPPORTED and CPU_SUPPORTED added. By default both are
54
// turned on.
55
//
56 128 mohor
// Revision 1.37  2004/01/25 14:10:25  mohor
57
// Display for VATS added.
58
//
59 124 mohor
// Revision 1.36  2004/01/22 13:58:51  mohor
60
// Port signals are all set to zero after reset.
61
//
62 121 mohor
// Revision 1.35  2004/01/22 11:07:28  mohor
63
// test stall_test added.
64
//
65 120 mohor
// Revision 1.34  2004/01/20 14:24:08  mohor
66
// Define name changed.
67
//
68 117 mohor
// Revision 1.33  2004/01/20 14:05:26  mohor
69
// Data latching changed when testing WB.
70
//
71 116 mohor
// Revision 1.32  2004/01/20 10:23:21  mohor
72
// More debug data added.
73
//
74 115 mohor
// Revision 1.31  2004/01/20 09:07:44  mohor
75
// CRC generation iand verification in bench changed.
76
//
77 114 mohor
// Revision 1.30  2004/01/20 08:03:35  mohor
78
// IDCODE test improved.
79
//
80 113 mohor
// Revision 1.29  2004/01/19 13:13:18  mohor
81
// Define tap_defines.v added to test bench.
82
//
83 111 mohor
// Revision 1.28  2004/01/19 12:38:10  mohor
84
// Waiting for "ready" improved.
85
//
86 110 mohor
// Revision 1.27  2004/01/17 18:01:31  mohor
87
// New version.
88
//
89 102 mohor
// Revision 1.26  2004/01/17 17:01:25  mohor
90
// Almost finished.
91
//
92 101 mohor
// Revision 1.25  2004/01/16 14:51:24  mohor
93
// cpu registers added.
94
//
95 99 mohor
// Revision 1.24  2004/01/15 10:47:13  mohor
96
// Working.
97
//
98 96 mohor
// Revision 1.23  2004/01/14 22:59:01  mohor
99
// Temp version.
100
//
101 95 mohor
// Revision 1.22  2004/01/13 11:28:30  mohor
102
// tmp version.
103
//
104 93 mohor
// Revision 1.21  2004/01/10 07:50:41  mohor
105
// temp version.
106
//
107 92 mohor
// Revision 1.20  2004/01/09 12:49:23  mohor
108
// tmp version.
109
//
110 91 mohor
// Revision 1.19  2004/01/08 17:53:12  mohor
111
// tmp version.
112
//
113 90 mohor
// Revision 1.18  2004/01/07 11:59:48  mohor
114
// temp4 version.
115
//
116 89 mohor
// Revision 1.17  2004/01/06 17:14:59  mohor
117
// temp3 version.
118
//
119 88 mohor
// Revision 1.16  2004/01/05 12:16:50  mohor
120
// tmp2 version.
121
//
122 87 mohor
// Revision 1.15  2003/12/23 14:26:01  mohor
123
// New version of the debug interface. Not finished, yet.
124
//
125 80 mohor
// Revision 1.14  2003/10/23 16:16:30  mohor
126
// CRC logic changed.
127
//
128 73 mohor
// Revision 1.13  2003/08/28 13:54:33  simons
129
// Three more chains added for cpu debug access.
130
//
131 63 simons
// Revision 1.12  2002/05/07 14:44:52  mohor
132
// mon_cntl_o signals that controls monitor mux added.
133
//
134 47 mohor
// Revision 1.11  2002/03/12 14:32:26  mohor
135
// Few outputs for boundary scan chain added.
136
//
137 38 mohor
// Revision 1.10  2002/03/08 15:27:08  mohor
138
// Structure changed. Hooks for jtag chain added.
139
//
140 36 mohor
// Revision 1.9  2001/10/19 11:39:20  mohor
141
// dbg_timescale.v changed to timescale.v This is done for the simulation of
142
// few different cores in a single project.
143
//
144 17 mohor
// Revision 1.8  2001/10/17 10:39:17  mohor
145
// bs_chain_o added.
146
//
147 15 mohor
// Revision 1.7  2001/10/16 10:10:18  mohor
148
// Signal names changed to lowercase.
149
//
150 13 mohor
// Revision 1.6  2001/10/15 09:52:50  mohor
151
// Wishbone interface added, few fixes for better performance,
152
// hooks for boundary scan testing added.
153
//
154 12 mohor
// Revision 1.5  2001/09/24 14:06:12  mohor
155
// Changes connected to the OpenRISC access (SPR read, SPR write).
156
//
157 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
158
// Working version. Few bugs fixed, comments added.
159
//
160 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
161
// Minor changes for simulation.
162
//
163 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
164
// Trace fixed. Some registers changed, trace simplified.
165
//
166 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
167
// Initial official release.
168
//
169 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
170
// This is a backup. It is not a fully working version. Not for use, yet.
171
//
172
// Revision 1.2  2001/05/18 13:10:05  mohor
173
// Headers changed. All additional information is now avaliable in the README.txt file.
174
//
175
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
176
// Initial release
177
//
178
//
179
 
180
 
181 17 mohor
`include "timescale.v"
182 111 mohor
`include "tap_defines.v"
183 2 mohor
`include "dbg_defines.v"
184 80 mohor
`include "dbg_wb_defines.v"
185 99 mohor
`include "dbg_cpu_defines.v"
186 2 mohor
 
187 139 igorm
`define DBG_TEXT(TEXT)   $display("%0s", TEXT);
188
//  `DBG_TEXT("Bla bla bla") 
189
//  $sformat(dbg_text, "\n\nbla 0x%0x 0x%0x\n\n", 32'h12345678, 16'h543);
190
//  `DBG_TEXT(dbg_text) 
191
 
192
 
193
 
194 2 mohor
// Test bench
195
module dbg_tb;
196
 
197 80 mohor
parameter TCLK = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
198 2 mohor
 
199 139 igorm
reg   [999:0] dbg_text;
200 80 mohor
reg   tms_pad_i;
201
reg   tck_pad_i;
202
reg   trst_pad_i;
203
reg   tdi_pad_i;
204
wire  tdo_pad_o;
205
wire  tdo_padoe_o;
206 2 mohor
 
207 80 mohor
wire  shift_dr_o;
208
wire  pause_dr_o;
209
wire  update_dr_o;
210 102 mohor
wire  capture_dr_o;
211 2 mohor
 
212 80 mohor
wire  extest_select_o;
213
wire  sample_preload_select_o;
214
wire  mbist_select_o;
215
wire  debug_select_o;
216 2 mohor
 
217 128 mohor
reg   rst_i;
218
 
219 139 igorm
`ifdef DBG_WISHBONE_SUPPORTED
220 80 mohor
// WISHBONE common signals
221
reg   wb_clk_i;
222
 
223
// WISHBONE master interface
224
wire [31:0] wb_adr_o;
225
wire [31:0] wb_dat_o;
226
wire [31:0] wb_dat_i;
227
wire        wb_cyc_o;
228
wire        wb_stb_o;
229
wire  [3:0] wb_sel_o;
230
wire        wb_we_o;
231
wire        wb_ack_i;
232
wire        wb_cab_o;
233
wire        wb_err_i;
234
wire  [2:0] wb_cti_o;
235
wire  [1:0] wb_bte_o;
236 128 mohor
`endif
237 2 mohor
 
238 139 igorm
`ifdef DBG_CPU_SUPPORTED
239 101 mohor
// CPU signals
240
wire        cpu_clk_i;
241
wire [31:0] cpu_addr_o;
242
wire [31:0] cpu_data_i;
243
wire [31:0] cpu_data_o;
244
wire        cpu_bp_i;
245
wire        cpu_stall_o;
246
wire        cpu_stb_o;
247
wire        cpu_we_o;
248
wire        cpu_ack_i;
249
wire        cpu_rst_o;
250 128 mohor
`endif
251 101 mohor
 
252 87 mohor
// Text used for easier debugging
253 99 mohor
reg [199:0] test_text;
254 139 igorm
reg [`DBG_WB_CMD_LEN -1:0]  last_wb_cmd;
255
reg [`DBG_CPU_CMD_LEN -1:0] last_cpu_cmd;
256 99 mohor
reg [199:0] last_wb_cmd_text;
257 139 igorm
reg [199:0] last_cpu_cmd_text;
258 2 mohor
 
259 116 mohor
reg  [31:0] wb_data [0:4095];   // Data that is written to (read from) wishbone is stored here. 
260 2 mohor
 
261 12 mohor
 
262 116 mohor
 
263 80 mohor
wire  tdo_o;
264 12 mohor
 
265 80 mohor
wire  debug_tdi_i;
266
wire  bs_chain_tdi_i;
267
wire  mbist_tdi_i;
268 73 mohor
 
269 80 mohor
reg   test_enabled;
270 73 mohor
 
271 80 mohor
reg [31:0] result;
272 113 mohor
reg [31:0] in_data_le, in_data_be;
273
reg [31:0] id;
274 88 mohor
 
275 110 mohor
wire crc_match_in;
276 114 mohor
reg [31:0] crc_in;
277
reg [31:0] crc_out;
278 138 igorm
reg [`DBG_TOP_STATUS_LEN -1:0] status;
279 139 igorm
reg [`DBG_WB_STATUS_LEN -1:0]  status_wb;
280
reg [`DBG_CPU_STATUS_LEN -1:0] status_cpu;
281 99 mohor
 
282 139 igorm
reg [`DBG_WB_ACC_TYPE_LEN -1:0]  read_acc_type;
283
reg [`DBG_WB_ADR_LEN -1:0]       read_addr;
284
reg [`DBG_WB_LEN_LEN -1:0]       read_length;
285
reg [`DBG_CPU_CTRL_LEN -1:0]     read_ctrl_reg;
286
 
287 80 mohor
wire tdo;
288 73 mohor
 
289 80 mohor
assign tdo = tdo_padoe_o? tdo_pad_o : 1'hz;
290 73 mohor
 
291 80 mohor
// Connecting TAP module
292
tap_top i_tap_top (
293 101 mohor
                    .tms_pad_i        (tms_pad_i),
294
                    .tck_pad_i        (tck_pad_i),
295
                    .trst_pad_i       (!trst_pad_i),
296
                    .tdi_pad_i        (tdi_pad_i),
297
                    .tdo_pad_o        (tdo_pad_o),
298
                    .tdo_padoe_o      (tdo_padoe_o),
299 38 mohor
 
300 80 mohor
                    // TAP states
301 101 mohor
                    .shift_dr_o       (shift_dr_o),
302
                    .pause_dr_o       (pause_dr_o),
303
                    .update_dr_o      (update_dr_o),
304 102 mohor
                    .capture_dr_o     (capture_dr_o),
305 38 mohor
 
306 80 mohor
                    // Select signals for boundary scan or mbist
307 101 mohor
                    .extest_select_o  (extest_select_o),
308 80 mohor
                    .sample_preload_select_o(sample_preload_select_o),
309 101 mohor
                    .mbist_select_o   (mbist_select_o),
310
                    .debug_select_o   (debug_select_o),
311 2 mohor
 
312 80 mohor
                    // TDO signal that is connected to TDI of sub-modules.
313 101 mohor
                    .tdo_o            (tdo_o),
314 38 mohor
 
315 80 mohor
                    // TDI signals from sub-modules
316 101 mohor
                    .debug_tdi_i      (debug_tdi_i),        // from debug module
317
                    .bs_chain_tdi_i   (bs_chain_tdi_i),  // from Boundary Scan Chain
318
                    .mbist_tdi_i      (mbist_tdi_i)         // from Mbist Chain
319 73 mohor
 
320 38 mohor
               );
321 2 mohor
 
322
 
323 99 mohor
// Connecting debug top module
324 80 mohor
dbg_top i_dbg_top  (
325 101 mohor
                    .tck_i            (tck_pad_i),
326
                    .tdi_i            (tdo_o),
327
                    .tdo_o            (debug_tdi_i),
328 128 mohor
                    .rst_i            (rst_i),
329 80 mohor
 
330
                    // TAP states
331 101 mohor
                    .shift_dr_i       (shift_dr_o),
332
                    .pause_dr_i       (pause_dr_o),
333
                    .update_dr_i      (update_dr_o),
334 80 mohor
 
335
                    // Instructions
336 128 mohor
                    .debug_select_i   (debug_select_o)
337 12 mohor
 
338 139 igorm
                    `ifdef DBG_WISHBONE_SUPPORTED
339 80 mohor
                    // WISHBONE common signals
340 128 mohor
                    ,
341 101 mohor
                    .wb_clk_i         (wb_clk_i),
342 80 mohor
 
343
                    // WISHBONE master interface
344 101 mohor
                    .wb_adr_o         (wb_adr_o),
345
                    .wb_dat_o         (wb_dat_o),
346
                    .wb_dat_i         (wb_dat_i),
347
                    .wb_cyc_o         (wb_cyc_o),
348
                    .wb_stb_o         (wb_stb_o),
349
                    .wb_sel_o         (wb_sel_o),
350
                    .wb_we_o          (wb_we_o),
351
                    .wb_ack_i         (wb_ack_i),
352
                    .wb_cab_o         (wb_cab_o),
353
                    .wb_err_i         (wb_err_i),
354
                    .wb_cti_o         (wb_cti_o),
355 128 mohor
                    .wb_bte_o         (wb_bte_o)
356
                    `endif
357 101 mohor
 
358 139 igorm
                    `ifdef DBG_CPU_SUPPORTED
359 101 mohor
                    // CPU signals
360 128 mohor
                    ,
361 101 mohor
                    .cpu_clk_i        (cpu_clk_i),
362
                    .cpu_addr_o       (cpu_addr_o),
363
                    .cpu_data_i       (cpu_data_i),
364
                    .cpu_data_o       (cpu_data_o),
365
                    .cpu_bp_i         (cpu_bp_i),
366
                    .cpu_stall_o      (cpu_stall_o),
367
                    .cpu_stb_o        (cpu_stb_o),
368
                    .cpu_we_o         (cpu_we_o),
369
                    .cpu_ack_i        (cpu_ack_i),
370
                    .cpu_rst_o        (cpu_rst_o)
371 128 mohor
                    `endif
372 101 mohor
 
373
 
374
 
375 80 mohor
                   );
376 12 mohor
 
377
 
378 139 igorm
`ifdef DBG_WISHBONE_SUPPORTED
379 80 mohor
wb_slave_behavioral wb_slave
380
                   (
381 101 mohor
                    .CLK_I            (wb_clk_i),
382 128 mohor
                    .RST_I            (rst_i),
383 101 mohor
                    .ACK_O            (wb_ack_i),
384
                    .ADR_I            (wb_adr_o),
385
                    .CYC_I            (wb_cyc_o),
386
                    .DAT_O            (wb_dat_i),
387
                    .DAT_I            (wb_dat_o),
388
                    .ERR_O            (wb_err_i),
389
                    .RTY_O            (),      // NOT USED for now!
390
                    .SEL_I            (wb_sel_o),
391
                    .STB_I            (wb_stb_o),
392
                    .WE_I             (wb_we_o),
393
                    .CAB_I            (1'b0)
394 80 mohor
                   );
395 128 mohor
`endif
396 2 mohor
 
397
 
398 139 igorm
`ifdef DBG_CPU_SUPPORTED
399 101 mohor
cpu_behavioral i_cpu_behavioral
400
                   (
401
                    // CPU signals
402 128 mohor
                    .cpu_rst_i        (rst_i),
403 101 mohor
                    .cpu_clk_o        (cpu_clk_i),
404
                    .cpu_addr_i       (cpu_addr_o),
405
                    .cpu_data_o       (cpu_data_i),
406
                    .cpu_data_i       (cpu_data_o),
407
                    .cpu_bp_o         (cpu_bp_i),
408
                    .cpu_stall_i      (cpu_stall_o),
409
                    .cpu_stb_i        (cpu_stb_o),
410
                    .cpu_we_i         (cpu_we_o),
411
                    .cpu_ack_o        (cpu_ack_i),
412
                    .cpu_rst_o        (cpu_rst_o)
413
                   );
414 128 mohor
`endif
415 101 mohor
 
416
 
417
 
418 80 mohor
// Initial values
419 2 mohor
initial
420
begin
421 80 mohor
  trst_pad_i = 1'b1;
422
  tms_pad_i = 1'hz;
423
  tck_pad_i = 1'hz;
424
  tdi_pad_i = 1'hz;
425
 
426
  #100;
427
  trst_pad_i = 1'b0;
428
  #100;
429
  trst_pad_i = 1'b1;
430 2 mohor
end
431
 
432 80 mohor
initial
433
begin
434 120 mohor
  test_enabled = 1'b0;
435 128 mohor
  rst_i = 1'b0;
436 80 mohor
  #1000;
437 128 mohor
  rst_i = 1'b1;
438 80 mohor
  #1000;
439 128 mohor
  rst_i = 1'b0;
440 2 mohor
 
441 80 mohor
  // Initial values for wishbone slave model
442 139 igorm
  `ifdef DBG_WISHBONE_SUPPORTED
443
//  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
444
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h35, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
445 128 mohor
  `endif
446 120 mohor
  #1 test_enabled<=#1 1'b1;
447 80 mohor
end
448
 
449 139 igorm
`ifdef DBG_WISHBONE_SUPPORTED
450 80 mohor
initial
451 2 mohor
begin
452 80 mohor
  wb_clk_i = 1'b0;
453
  forever #5 wb_clk_i = ~wb_clk_i;
454 2 mohor
end
455 128 mohor
`endif
456 2 mohor
 
457 80 mohor
always @ (posedge test_enabled)
458
begin
459
  $display("//////////////////////////////////////////////////////////////////");
460
  $display("//                                                              //");
461
  $display("//  (%0t) dbg_tb starting                                     //", $time);
462
  $display("//                                                              //");
463
  $display("//////////////////////////////////////////////////////////////////");
464 2 mohor
 
465 124 mohor
  $display("TEST: DBG_TEST");
466
 
467
 
468 80 mohor
  initialize_memory(32'h12340000, 32'h00100000);  // Initialize 0x100000 bytes starting from address 0x12340000
469 2 mohor
 
470 80 mohor
  reset_tap;
471 95 mohor
 
472
  #500;
473 80 mohor
  goto_run_test_idle;
474 12 mohor
 
475 139 igorm
//  `ifdef DBG_CPU_SUPPORTED
476
//  // Test stall signal
477
//  stall_test;
478
//  `endif
479 120 mohor
 
480 80 mohor
  // Testing read and write to internal registers
481
  #10000;
482 111 mohor
 
483 138 igorm
  id_test;
484 12 mohor
 
485 80 mohor
  set_instruction(`DEBUG);
486
  #10000;
487 2 mohor
 
488 138 igorm
 
489
 
490
 
491
 
492
 
493
 
494
 
495
 
496
  #100000;
497 139 igorm
  `ifdef DBG_WISHBONE_SUPPORTED
498
  module_select(`DBG_TOP_WISHBONE_DEBUG_MODULE, 1'b0);   // {module_id, gen_crc_err}
499 12 mohor
 
500 80 mohor
  #10000;
501 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b0, 32'h12345678, 16'h3, 1'b0, "read32 1"); // {command, ready, addr, length, gen_crc_err, text}
502
//  debug_wishbone(`DBG_WB_WRITE8, 1'b0, 32'h23456788, 16'h7, 1'b0, "write32 1"); // {command, ready, addr, length, gen_crc_err, text}
503
  debug_wishbone(`DBG_WB_WRITE32, 1'b0, 32'h23456788, 16'h7, 1'b0, "write32 1"); // {command, ready, addr, length, gen_crc_err, text}
504 2 mohor
 
505 139 igorm
  #10000;
506
  test_text = "debug_wishbone_rd_comm";
507
  debug_wishbone_rd_comm(read_acc_type, read_addr, read_length);
508
  $display("debug_wishbone_rd_comm returns: acc_type = 0x%0x, addr = 0x%0x, length = 0x%0x", read_acc_type, read_addr, read_length);
509
  debug_wishbone_go(1'b0, 1'b0);
510
  debug_wishbone_rd_comm(read_acc_type, read_addr, read_length);
511
  $display("debug_wishbone_rd_comm returns: acc_type = 0x%0x, addr = 0x%0x, length = 0x%0x", read_acc_type, read_addr, read_length);
512
 
513
  debug_wishbone_go(1'b0, 1'b0);
514
 
515 138 igorm
  #100000;
516 139 igorm
//  debug_wishbone(`DBG_WB_READ32, 1'b0, 32'h12345224, 16'h7, 1'b0, "read32 1"); // {command, ready, addr, length, gen_crc_err, text}
517
  debug_wishbone(`DBG_WB_READ8, 1'b0, 32'h12345223, 16'h8, 1'b0, "read8 1"); // {command, ready, addr, length, gen_crc_err, text}
518
  #100000;
519
  debug_wishbone_go(1'b0, 1'b0);
520 138 igorm
 
521 139 igorm
 
522
/*
523
//  debug_wishbone(`DBG_WB_READ8, 1'b0, 32'h12345678, 16'h4, 1'b0, "abc 1"); // {command, ready, addr, length, gen_crc_err, text}
524
//  debug_wishbone(`DBG_WB_READ8, 1'b0, 32'h12345679, 16'h4, 1'b0, "abc 2"); // {command, ready, addr, length, gen_crc_err, text}
525
//  debug_wishbone(`DBG_WB_READ8, 1'b0, 32'h1234567a, 16'h4, 1'b0, "abc 3"); // {command, ready, addr, length, gen_crc_err, text}
526 88 mohor
//
527 139 igorm
//  debug_wishbone(`DBG_WB_READ16, 1'b0, 32'h12345678, 16'h4, 1'b0, "abc 4"); // {command, ready, addr, length, gen_crc_err, text}
528
//  debug_wishbone(`DBG_WB_READ16, 1'b0, 32'h1234567a, 16'h4, 1'b0, "abc 5"); // {command, ready, addr, length, gen_crc_err, text}
529 88 mohor
//
530 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b0, 32'h12345678, 16'h4, 1'b0, "read32 1"); // {command, ready, addr, length, gen_crc_err, text}
531 88 mohor
//
532 139 igorm
//  debug_wishbone(`DBG_WB_READ16, 1'b0, 32'h12345679, 16'h4, 1'b0, "abc 6"); // {command, ready, addr, length, gen_crc_err, text}
533 2 mohor
 
534 80 mohor
  #10000;
535
 
536 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12345678, 16'h4, 1'b0, "read32 2"); // {command, ready, addr, length, gen_crc_err, text}
537 87 mohor
 
538
  #10000;
539 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
540 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, "read32 3"); // {command, ready, addr, length, gen_crc_err, text}
541 80 mohor
 
542
  #10000;
543 96 mohor
  wb_slave.cycle_response(`ERR_RESPONSE, 9'h03, 8'h2);   // (`ERR_RESPONSE, wbs_waits, wbs_retries);
544 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, "read32 4"); // {command, ready, addr, length, gen_crc_err, text}
545 80 mohor
 
546
  #10000;
547 116 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, "status 1"); // {command, ready, addr, length, gen_crc_err, text}
548 80 mohor
 
549 87 mohor
  #10000;
550 116 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, "status 2"); // {command, ready, addr, length, gen_crc_err, text}
551 80 mohor
 
552 87 mohor
  #10000;
553 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h012, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
554 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12347778, 16'hc, 1'b0, "read32 5"); // {command, ready, addr, length, gen_crc_err, text}
555 80 mohor
 
556 87 mohor
  #10000;
557 139 igorm
  debug_wishbone(`DBG_WB_WRITE32, 1'b0, 32'h12346668, 16'h8, 1'b0, "wr32 len8"); // {command, ready, addr, length, gen_crc_err, text}
558 87 mohor
 
559
  #10000;
560 139 igorm
  debug_wishbone(`DBG_WB_WRITE16, 1'b0, 32'h12344446, 16'h8, 1'b0, "wr16 len8"); // {command, ready, addr, length, gen_crc_err, text}
561 87 mohor
 
562 88 mohor
  #10000;
563 139 igorm
  debug_wishbone(`DBG_WB_WRITE8, 1'b0, 32'h1234010e, 16'h8, 1'b0, "wr8 len8"); // {command, ready, addr, length, gen_crc_err, text}
564 87 mohor
 
565 88 mohor
  #10000;
566 116 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, "go 1"); // {command, ready, addr, length, gen_crc_err, text}
567 87 mohor
 
568 89 mohor
  #10000;
569 139 igorm
  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12340100, 16'hc, 1'b0, "read32 6"); // {command, ready, addr, length, gen_crc_err, text}
570
//  debug_wishbone(`DBG_WB_READ32, 1'b1, 32'h12340100, 16'hfffc, 1'b0, "read32 6"); // {command, ready, addr, length, gen_crc_err, text}
571 88 mohor
 
572 89 mohor
  #10000;
573 139 igorm
//  debug_wishbone(`DBG_WB_READ16, 1'b1, 32'h12340102, 16'he, 1'b0, "read16 7"); // {command, ready, addr, length, gen_crc_err, text}
574
//  debug_wishbone(`DBG_WB_READ16, 1'b1, 32'h12340102, 16'hfffe, 1'b0, "read16 7"); // {command, ready, addr, length, gen_crc_err, text}
575 88 mohor
 
576 90 mohor
  #10000;
577 139 igorm
//  debug_wishbone(`DBG_WB_READ8, 1'b1, 32'h12348804, 16'h6, 1'b0, "read8 8"); // {command, ready, addr, length, gen_crc_err, text}
578
//  debug_wishbone(`DBG_WB_READ8, 1'b1, 32'h12348804, 16'hfffc, 1'b0, "read8 8"); // {command, ready, addr, length, gen_crc_err, text}
579 89 mohor
 
580 90 mohor
  #10000;
581 116 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, "go 2"); // {command, ready, addr, length, gen_crc_err, text}
582 139 igorm
*/
583
  `endif  // DBG_WISHBONE_SUPPORTED
584 89 mohor
 
585 139 igorm
  `ifdef DBG_CPU_SUPPORTED
586 99 mohor
  #10000;
587 139 igorm
  module_select(`DBG_TOP_CPU_DEBUG_MODULE, 1'b0);   // {module_id, gen_crc_err}
588 89 mohor
 
589 101 mohor
 
590
 
591
 
592
  // Select cpu0
593 139 igorm
 
594 99 mohor
  #10000;
595 139 igorm
  debug_cpu(`DBG_CPU_WRITE, 1'b0, 32'h23456788, 16'h3, 1'b0, "cpu write 1"); // {command, ready, addr, length, gen_crc_err, text}
596 90 mohor
 
597 99 mohor
  #10000;
598 139 igorm
  debug_cpu(`DBG_CPU_READ, 1'b0, 32'h23456788, 16'h3, 1'b0, "cpu read 1"); // {command, ready, addr, length, gen_crc_err, text}
599 101 mohor
  // Read register
600
  #10000;
601
 
602 139 igorm
  debug_cpu(`DBG_CPU_WRITE, 1'b0, 32'h32323232, 16'h3, 1'b0, "cpu write 1"); // {command, ready, addr, length, gen_crc_err, text}
603
 
604 101 mohor
  #10000;
605 139 igorm
  debug_cpu(`DBG_CPU_READ, 1'b0, 32'h77665544, 16'h3, 1'b0, "cpu read 1"); // {command, ready, addr, length, gen_crc_err, text}
606
  // Read register
607
  #10000;
608 90 mohor
 
609 139 igorm
  // Reset cpu on
610
  debug_cpu_wr_ctrl(`DBG_CPU_CTRL_LEN'b10, "rst cpu on"); // {data, text} igor !!! poglej endian
611 101 mohor
  #10000;
612 99 mohor
 
613 139 igorm
  // Reset cpu off
614
  debug_cpu_wr_ctrl(`DBG_CPU_CTRL_LEN'b00, "rst cpu off"); // {data, text}
615 101 mohor
  #10000;
616
 
617 139 igorm
  // Stall cpu
618
  debug_cpu_wr_ctrl(`DBG_CPU_CTRL_LEN'b01, "stall on"); // {data, text}
619 101 mohor
  #10000;
620
 
621 139 igorm
  debug_cpu_wr_ctrl(`DBG_CPU_CTRL_LEN'b00, "stall off"); // {data, text}
622 101 mohor
  #10000;
623
 
624 139 igorm
  // Stall cpu0
625
  debug_cpu_rd_ctrl(read_ctrl_reg, "read ctrl");
626
  $display("debug_cpu_rd_ctrl returns: read_ctrl_reg = 0x%0x", read_ctrl_reg);
627 101 mohor
  #10000;
628
 
629 139 igorm
  debug_cpu(`DBG_CPU_READ, 1'b0, 32'h23456788, 16'h3, 1'b0, "cpu read 2"); // {command, ready, addr, length, gen_crc_err, text}
630
  // write to cpu 32-bit
631 101 mohor
  #10000;
632
 
633 139 igorm
  debug_cpu(`DBG_CPU_WRITE, 1'b0, 32'h32323232, 16'hf, 1'b0, "cpu write 2"); // {command, ready, addr, length, gen_crc_err, text}
634
 
635 101 mohor
  #10000;
636
 
637 139 igorm
  // read from cpu 32-bit
638 101 mohor
  #10000;
639
 
640
  #10000;
641
 
642 128 mohor
  `endif
643 101 mohor
 
644 110 mohor
 
645
 
646
 
647
 
648
 
649
 
650
 
651 80 mohor
  #5000 gen_clk(1);            // One extra TCLK for debugging purposes
652 124 mohor
  $display("STATUS: passed");
653 95 mohor
  $display("\n\nSimulation end.");
654 5 mohor
  #1000 $stop;
655 80 mohor
 
656 2 mohor
end
657
 
658 80 mohor
 
659 139 igorm
`ifdef DBG_CPU_SUPPORTED
660 120 mohor
task stall_test;
661
  integer i;
662
 
663
  begin
664 121 mohor
    test_text = "stall_test";
665 120 mohor
    $display("\n\n(%0t) stall_test started", $time);
666
 
667
    // Set bp_i active for 1 clock cycle and check is stall is set or not
668
    check_stall(0); // Should not be set at the beginning
669 128 mohor
    @ (posedge cpu_clk_i);
670 121 mohor
    #1 dbg_tb.i_cpu_behavioral.cpu_bp_o = 1'b1;
671
    #1 check_stall(1); // set?
672 128 mohor
    @ (posedge cpu_clk_i);
673 121 mohor
    #1 dbg_tb.i_cpu_behavioral.cpu_bp_o = 1'b0;
674
    #1 check_stall(1); // set?
675 120 mohor
 
676
    gen_clk(1);
677 121 mohor
    #1 check_stall(1); // set?
678 120 mohor
 
679
    // Unstall with register
680
    set_instruction(`DEBUG);
681 139 igorm
    module_select(`DBG_TOP_CPU_DEBUG_MODULE, 1'b0);   // {module_id, gen_crc_err}
682 121 mohor
    #1 check_stall(1); // set?
683 139 igorm
// igor !!!    debug_cpu(`CPU_WRITE_REG, `CPU_OP_ADR, 32'h0, 1'b0, result, "clr unstall"); // {command, addr, data, gen_crc_err, result, text}
684 121 mohor
    #1 check_stall(1); // set?
685 139 igorm
    debug_cpu(`DBG_CPU_WR_COMM, 32'h0, 32'h0, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
686 121 mohor
    #1 check_stall(0); // reset?
687 120 mohor
 
688
    // Set stall with register
689 139 igorm
// igor !!!    debug_cpu(`CPU_WRITE_REG, `CPU_OP_ADR, 32'h0, 1'b0, result, "clr stall"); // {command, addr, data, gen_crc_err, result, text}
690 121 mohor
    #1 check_stall(0); // reset?
691 139 igorm
    debug_cpu(`DBG_CPU_WR_COMM, 32'h0, 32'h1, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
692 121 mohor
    #1 check_stall(1); // set?
693 120 mohor
 
694
    // Unstall with register
695 139 igorm
// igor !!!    debug_cpu(`CPU_WRITE_REG, `CPU_OP_ADR, 32'h0, 1'b0, result, "clr unstall"); // {command, addr, data, gen_crc_err, result, text}
696 121 mohor
    #1 check_stall(1); // set?
697 139 igorm
    debug_cpu(`DBG_CPU_WR_COMM, 32'h0, 32'h0, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
698 121 mohor
    #1 check_stall(0); // reset?
699 120 mohor
 
700
    $display("\n\n(%0t) stall_test passed\n\n", $time);
701
  end
702
endtask   // stall_test
703
 
704
 
705
task check_stall;
706
  input should_be_set;
707
  begin
708
    if (should_be_set && (!cpu_stall_o))
709
      begin
710
        $display ("\t\t(%0t) ERROR: cpu_stall_o is not set but should be.", $time);
711
        $stop;
712
      end
713
    if ((!should_be_set) && cpu_stall_o)
714
      begin
715
        $display ("\t\t(%0t) ERROR: cpu_stall_o set but shouldn't be.", $time);
716
        $stop;
717
      end
718
  end
719
endtask   // check_stall
720 128 mohor
`endif
721 120 mohor
 
722
 
723 80 mohor
task initialize_memory;
724
  input [31:0] start_addr;
725
  input [31:0] length;
726
  integer i;
727
  reg [31:0] addr;
728
  begin
729 116 mohor
    for (i=0; i<length; i=i+4)  // This data will be return from wb slave
730 80 mohor
      begin
731
        addr = start_addr + i;
732 139 igorm
        `ifdef DBG_WISHBONE_SUPPORTED
733 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
734 128 mohor
        `endif
735 80 mohor
      end
736 116 mohor
    for (i=0; i<4096; i=i+1)  // This data will be written to wb slave
737
      begin
738
        wb_data[i] <= {i[7:0], i[7:0]+2'd1, i[7:0]+2'd2, i[7:0]+2'd3};
739
      end
740 80 mohor
  end
741
endtask
742
 
743
 
744 138 igorm
task id_test;
745
  begin
746
    test_text = "id_test";
747
    $display("\n\n(%0t) TEST: id_test", $time);
748 80 mohor
 
749 138 igorm
    set_instruction(`IDCODE);
750
    read_id_code(id);
751
 
752 139 igorm
    `ifdef DBG_MORE_INFO
753 138 igorm
      $display("\tRead ID     = 0x%0x", id);
754
      $display("\tExpected ID = 0x%0x", `IDCODE_VALUE);
755
    `endif
756
 
757
    if (id==`IDCODE_VALUE)
758
      $display("(%0t) STATUS: passed\n", $time);
759
    else
760
      $display("(%0t) STATUS: failed (Read ID = 0x%0x, Expected ID = 0x%0x\n", $time, id, `IDCODE_VALUE);
761
  end
762
endtask // id_test
763
 
764
 
765 2 mohor
// Generation of the TCLK signal
766 80 mohor
task gen_clk;
767
  input [7:0] num;
768 2 mohor
  integer i;
769
  begin
770 80 mohor
    for(i=0; i<num; i=i+1)
771 2 mohor
      begin
772 80 mohor
        #TCLK tck_pad_i<=1;
773
        #TCLK tck_pad_i<=0;
774 2 mohor
      end
775
  end
776
endtask
777
 
778
 
779
// TAP reset
780 80 mohor
task reset_tap;
781 2 mohor
  begin
782 80 mohor
    $display("(%0t) Task reset_tap", $time);
783
    tms_pad_i<=#1 1'b1;
784 95 mohor
    gen_clk(5);
785 2 mohor
  end
786
endtask
787
 
788
 
789
// Goes to RunTestIdle state
790 80 mohor
task goto_run_test_idle;
791 2 mohor
  begin
792 80 mohor
    $display("(%0t) Task goto_run_test_idle", $time);
793
    tms_pad_i<=#1 1'b0;
794
    gen_clk(1);
795 2 mohor
  end
796
endtask
797
 
798
 
799 115 mohor
 
800 2 mohor
// sets the instruction to the IR register and goes to the RunTestIdle state
801 80 mohor
task set_instruction;
802
  input [3:0] instr;
803 2 mohor
  integer i;
804
 
805
  begin
806 115 mohor
    case (instr)
807 139 igorm
      `ifdef DBG_MORE_INFO
808 138 igorm
        `EXTEST          : $display("(%0t) Task set_instruction (EXTEST)", $time);
809
        `SAMPLE_PRELOAD  : $display("(%0t) Task set_instruction (SAMPLE_PRELOAD)", $time);
810
        `IDCODE          : $display("(%0t) Task set_instruction (IDCODE)", $time);
811
        `DEBUG           : $display("(%0t) Task set_instruction (DEBUG)", $time);
812
        `MBIST           : $display("(%0t) Task set_instruction (MBIST)", $time);
813
        `BYPASS          : $display("(%0t) Task set_instruction (BYPASS)", $time);
814
      `else
815
        `EXTEST          : ;
816
        `SAMPLE_PRELOAD  : ;
817
        `IDCODE          : ;
818
        `DEBUG           : ;
819
        `MBIST           : ;
820
        `BYPASS          : ;
821
      `endif
822
        default
823
                         begin
824
                           $display("(*E) (%0t) Task set_instruction: Unsupported instruction !!!", $time);
825
                           $stop;
826
                         end
827 115 mohor
    endcase
828
 
829 80 mohor
    tms_pad_i<=#1 1;
830
    gen_clk(2);
831
    tms_pad_i<=#1 0;
832
    gen_clk(2);  // we are in shiftIR
833 2 mohor
 
834
    for(i=0; i<`IR_LENGTH-1; i=i+1)
835
    begin
836 80 mohor
      tdi_pad_i<=#1 instr[i];
837
      gen_clk(1);
838 2 mohor
    end
839
 
840 80 mohor
    tdi_pad_i<=#1 instr[i]; // last shift
841
    tms_pad_i<=#1 1;        // going out of shiftIR
842
    gen_clk(1);
843 135 igorm
    tdi_pad_i<=#1 1'hz;    // tri-state
844 80 mohor
    gen_clk(1);
845
    tms_pad_i<=#1 0;
846
    gen_clk(1);       // we are in RunTestIdle
847 2 mohor
  end
848
endtask
849
 
850
 
851 80 mohor
// Reads the ID code
852
task read_id_code;
853 113 mohor
  output [31:0] code;
854
  reg    [31:0] code;
855 80 mohor
  begin
856 139 igorm
    `ifdef DBG_MORE_INFO
857 138 igorm
      $display("(%0t) Task read_id_code", $time);
858
    `endif
859 80 mohor
    tms_pad_i<=#1 1;
860
    gen_clk(1);
861
    tms_pad_i<=#1 0;
862
    gen_clk(2);  // we are in shiftDR
863
 
864
    tdi_pad_i<=#1 0;
865
    gen_clk(31);
866
 
867
    tms_pad_i<=#1 1;        // going out of shiftIR
868
    gen_clk(1);
869
 
870 113 mohor
    code = in_data_le;
871
 
872 135 igorm
    tdi_pad_i<=#1 1'hz; // tri-state
873 80 mohor
    gen_clk(1);
874
    tms_pad_i<=#1 0;
875
    gen_clk(1);       // we are in RunTestIdle
876
  end
877
endtask
878
 
879
 
880 138 igorm
// sets the selected module and goes to the RunTestIdle state
881
task module_select;
882 139 igorm
  input [`DBG_TOP_MODULE_ID_LENGTH -1:0]  data;
883 138 igorm
  input                           gen_crc_err;
884
  integer                         i;
885
 
886 2 mohor
  begin
887 99 mohor
    case (data)
888 139 igorm
      `DBG_TOP_CPU_DEBUG_MODULE      : $display("(%0t) Task module_select (DBG_TOP_CPU_DEBUG_MODULE, gen_crc_err=%0d)", $time, gen_crc_err);
889
      `DBG_TOP_WISHBONE_DEBUG_MODULE : $display("(%0t) Task module_select (DBG_TOP_WISHBONE_DEBUG_MODULE, gen_crc_err=%0d)", $time, gen_crc_err);
890 138 igorm
      default                : $display("(%0t) Task module_select (ERROR!!! Unknown module selected)", $time);
891 99 mohor
    endcase
892
 
893 138 igorm
    tms_pad_i<=#1 1'b1;
894 80 mohor
    gen_clk(1);
895 138 igorm
    tms_pad_i<=#1 1'b0;
896 80 mohor
    gen_clk(2);  // we are in shiftDR
897 2 mohor
 
898 138 igorm
    status = {`DBG_TOP_STATUS_LEN{1'b0}};    // Initialize status to all 0's
899
    crc_out = {`DBG_TOP_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
900
    tdi_pad_i<=#1 1'b1; // module_select bit
901 114 mohor
    calculate_crc(1'b1);
902 80 mohor
    gen_clk(1);
903
 
904 139 igorm
    for(i=`DBG_TOP_MODULE_ID_LENGTH -1; i>=0; i=i-1) // Shifting module ID
905 2 mohor
    begin
906 80 mohor
      tdi_pad_i<=#1 data[i];
907 114 mohor
      calculate_crc(data[i]);
908 80 mohor
      gen_clk(1);
909 2 mohor
    end
910
 
911 138 igorm
    for(i=`DBG_TOP_CRC_LEN -1; i>=0; i=i-1)
912 2 mohor
    begin
913 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
914 114 mohor
        tdi_pad_i<=#1 ~crc_out[i];   // error crc
915 99 mohor
      else
916 114 mohor
        tdi_pad_i<=#1 crc_out[i];    // ok crc
917 99 mohor
 
918 80 mohor
      gen_clk(1);
919 2 mohor
    end
920
 
921 135 igorm
    tdi_pad_i<=#1 1'hz;  // tri-state
922 99 mohor
 
923 138 igorm
    crc_in = {`DBG_TOP_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
924 80 mohor
 
925 138 igorm
    for(i=`DBG_TOP_STATUS_LEN -1; i>=0; i=i-1)
926
      begin
927
        gen_clk(1);     // Generating 1 clock to read out a status bit.
928
        status[i] = tdo;
929
      end
930 110 mohor
 
931 138 igorm
    for(i=0; i<`DBG_TOP_CRC_LEN -1; i=i+1)
932 80 mohor
      gen_clk(1);
933
 
934 138 igorm
    tms_pad_i<=#1 1'b1;
935 80 mohor
    gen_clk(1);         // to exit1_dr
936
 
937 138 igorm
    tms_pad_i<=#1 1'b1;
938
    gen_clk(1);         // to update_dr
939
    tms_pad_i<=#1 1'b0;
940
    gen_clk(1);         // to run_test_idle
941
 
942
    if (|status)
943 110 mohor
      begin
944 138 igorm
        $write("(*E) (%0t) Chain select error: ", $time);
945
        casex (status)
946
          4'b1xxx : $display("CRC error !!!\n\n", $time);
947 139 igorm
          4'bx1xx : $display("Non-existing module selected !!!\n\n", $time);
948
          4'bxx1x : $display("Status[1] should be 1'b0 !!!\n\n", $time);
949 138 igorm
          4'bxxx1 : $display("Status[0] should be 1'b0 !!!\n\n", $time);
950
        endcase
951 110 mohor
        $stop;
952
      end
953 2 mohor
  end
954 138 igorm
endtask   // module_select
955 2 mohor
 
956
 
957 87 mohor
 
958
 
959 139 igorm
`ifdef DBG_WISHBONE_SUPPORTED
960 80 mohor
task debug_wishbone;
961 138 igorm
  input [`DBG_WB_CMD_LEN -1:0]   command;
962 87 mohor
  input         ready;
963 138 igorm
  input [`DBG_WB_ADR_LEN -1:0]  addr;
964
  input [`DBG_WB_LEN_LEN -1:0]  length;
965 99 mohor
  input         gen_crc_err;
966 87 mohor
  input [99:0]  text;
967 80 mohor
  integer i;
968
 
969 2 mohor
  begin
970 80 mohor
   $write("(%0t) Task debug_wishbone: ", $time);
971 2 mohor
 
972 87 mohor
    test_text = text;
973 36 mohor
 
974 80 mohor
    case (command)
975 139 igorm
      `DBG_WB_READ8    :
976 80 mohor
        begin
977 110 mohor
          $display("wb_read8 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
978 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_READ8, addr, length, gen_crc_err);
979
          last_wb_cmd = `DBG_WB_READ8;  last_wb_cmd_text = "DBG_WB_READ8";
980
#10000;
981
          debug_wishbone_go(ready, gen_crc_err);
982 80 mohor
        end
983 139 igorm
      `DBG_WB_READ16   :
984 80 mohor
        begin
985 110 mohor
          $display("wb_read16 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
986 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_READ16, addr, length, gen_crc_err);
987
          last_wb_cmd = `DBG_WB_READ16;  last_wb_cmd_text = "DBG_WB_READ16";
988
#10000;
989
          debug_wishbone_go(ready, gen_crc_err);
990 80 mohor
        end
991 139 igorm
      `DBG_WB_READ32   :
992 80 mohor
        begin
993 110 mohor
          $display("wb_read32 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
994 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_READ32, addr, length, gen_crc_err);
995
          last_wb_cmd = `DBG_WB_READ32;  last_wb_cmd_text = "DBG_WB_READ32";
996
#10000;
997
          debug_wishbone_go(ready, gen_crc_err);
998 80 mohor
        end
999 139 igorm
      `DBG_WB_WRITE8   :
1000 80 mohor
        begin
1001 99 mohor
          $display("wb_write8 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
1002 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_WRITE8, addr, length, gen_crc_err);
1003
          last_wb_cmd = `DBG_WB_WRITE8;  last_wb_cmd_text = "DBG_WB_WRITE8";
1004
#10000;
1005
          debug_wishbone_go(ready, gen_crc_err);
1006 80 mohor
        end
1007 139 igorm
      `DBG_WB_WRITE16  :
1008 80 mohor
        begin
1009 99 mohor
          $display("wb_write16 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
1010 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_WRITE16, addr, length, gen_crc_err);
1011
          last_wb_cmd = `DBG_WB_WRITE16;  last_wb_cmd_text = "DBG_WB_WRITE16";
1012
#10000;
1013
          debug_wishbone_go(ready, gen_crc_err);
1014 80 mohor
        end
1015 139 igorm
      `DBG_WB_WRITE32  :
1016 80 mohor
        begin
1017 99 mohor
          $display("wb_write32 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
1018 139 igorm
          debug_wishbone_wr_comm(`DBG_WB_WRITE32, addr, length, gen_crc_err);
1019
          last_wb_cmd = `DBG_WB_WRITE32;  last_wb_cmd_text = "DBG_WB_WRITE32";
1020
#10000;
1021
          debug_wishbone_go(ready, gen_crc_err);
1022 80 mohor
        end
1023 139 igorm
      default:
1024 80 mohor
        begin
1025 139 igorm
          $display("(*E) debug_wishbone : Unsupported instruction !!!");
1026
          $stop;
1027 80 mohor
        end
1028
    endcase
1029 2 mohor
  end
1030 87 mohor
endtask       // debug_wishbone
1031 2 mohor
 
1032
 
1033 80 mohor
 
1034
 
1035
 
1036
 
1037 139 igorm
task debug_wishbone_wr_comm;
1038
  input [`DBG_WB_ACC_TYPE_LEN -1:0]   acc_type;
1039
  input [`DBG_WB_ADR_LEN -1:0]        addr;
1040
  input [`DBG_WB_LEN_LEN -1:0]        length;
1041
  input                               gen_crc_err;
1042
  integer                             i;
1043
  reg   [`DBG_WB_CMD_LEN -1:0]        command;
1044 80 mohor
 
1045
  begin
1046 139 igorm
    $display("(%0t) Task debug_wishbone_wr_comm: ", $time);
1047 80 mohor
 
1048 139 igorm
    command = `DBG_WB_WR_COMM;
1049 138 igorm
    tms_pad_i<=#1 1'b1;
1050 80 mohor
    gen_clk(1);
1051 138 igorm
    tms_pad_i<=#1 1'b0;
1052 80 mohor
    gen_clk(2);  // we are in shiftDR
1053
 
1054 138 igorm
    crc_out = {`DBG_WB_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1055 99 mohor
 
1056 138 igorm
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1057 114 mohor
    calculate_crc(1'b0);
1058 80 mohor
    gen_clk(1);
1059
 
1060 138 igorm
    for(i=`DBG_WB_CMD_LEN -1; i>=0; i=i-1)
1061 80 mohor
    begin
1062
      tdi_pad_i<=#1 command[i]; // command
1063 114 mohor
      calculate_crc(command[i]);
1064 80 mohor
      gen_clk(1);
1065
    end
1066
 
1067 139 igorm
    for(i=`DBG_WB_ACC_TYPE_LEN -1; i>=0; i=i-1)
1068
    begin
1069
      tdi_pad_i<=#1 acc_type[i]; // command
1070
      calculate_crc(acc_type[i]);
1071
      gen_clk(1);
1072
    end
1073
 
1074 138 igorm
    for(i=`DBG_WB_ADR_LEN -1; i>=0; i=i-1)       // address
1075 80 mohor
    begin
1076
      tdi_pad_i<=#1 addr[i];
1077 114 mohor
      calculate_crc(addr[i]);
1078 80 mohor
      gen_clk(1);
1079
    end
1080 87 mohor
 
1081 138 igorm
    for(i=`DBG_WB_LEN_LEN -1; i>=0; i=i-1)       // length
1082 80 mohor
    begin
1083
      tdi_pad_i<=#1 length[i];
1084 114 mohor
      calculate_crc(length[i]);
1085 80 mohor
      gen_clk(1);
1086
    end
1087
 
1088 138 igorm
    for(i=`DBG_WB_CRC_LEN -1; i>=0; i=i-1)
1089 80 mohor
    begin
1090 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1091 114 mohor
        tdi_pad_i<=#1 ~crc_out[i];   // error crc
1092 99 mohor
      else
1093 114 mohor
        tdi_pad_i<=#1 crc_out[i];    // ok crc
1094 99 mohor
 
1095 80 mohor
      gen_clk(1);
1096
    end
1097
 
1098 135 igorm
    tdi_pad_i<=#1 1'hz;
1099 80 mohor
 
1100 138 igorm
    crc_in = {`DBG_WB_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1101 110 mohor
 
1102 139 igorm
    for(i=`DBG_WB_STATUS_LEN -1; i>=0; i=i-1)
1103
      begin
1104
        gen_clk(1);     // Generating clock to read out a status bit.
1105
        status_wb[i] = tdo;
1106
      end
1107
 
1108
    if (|status_wb)
1109
      begin
1110
        $write("(*E) (%0t) debug_wishbone_wr_comm error: ", $time);
1111
        casex (status_wb)
1112
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1113
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1114
          4'bxx1x : $display("WISHBONE error !!!\n\n", $time);
1115
          4'bxxx1 : $display("Overrun/Underrun !!!\n\n", $time);
1116
        endcase
1117
        $stop;
1118
      end
1119
 
1120
 
1121 138 igorm
    for(i=0; i<`DBG_WB_CRC_LEN -1; i=i+1)  // Getting in the CRC
1122 80 mohor
    begin
1123
      gen_clk(1);
1124
    end
1125
 
1126 138 igorm
    tms_pad_i<=#1 1'b1;
1127 80 mohor
    gen_clk(1);         // to exit1_dr
1128
 
1129 138 igorm
    tms_pad_i<=#1 1'b1;
1130 80 mohor
    gen_clk(1);         // to update_dr
1131 138 igorm
    tms_pad_i<=#1 1'b0;
1132 80 mohor
    gen_clk(1);         // to run_test_idle
1133
  end
1134 139 igorm
endtask       // debug_wishbone_wr_comm
1135 80 mohor
 
1136
 
1137
 
1138
 
1139
 
1140 139 igorm
task debug_wishbone_rd_comm;
1141
  output [`DBG_WB_ACC_TYPE_LEN -1:0]  acc_type;
1142
  output [`DBG_WB_ADR_LEN -1:0]       addr;
1143
  output [`DBG_WB_LEN_LEN -1:0]       length;
1144
  integer                             i;
1145
  reg   [`DBG_WB_CMD_LEN -1:0]        command;
1146 88 mohor
 
1147
  begin
1148 139 igorm
    $display("(%0t) Task debug_wishbone_rd_comm: ", $time);
1149 80 mohor
 
1150 139 igorm
    command = `DBG_WB_RD_COMM;
1151
    tms_pad_i<=#1 1'b1;
1152 88 mohor
    gen_clk(1);
1153 139 igorm
    tms_pad_i<=#1 1'b0;
1154 88 mohor
    gen_clk(2);  // we are in shiftDR
1155 87 mohor
 
1156 139 igorm
    crc_out = {`DBG_WB_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1157 99 mohor
 
1158 138 igorm
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1159 114 mohor
    calculate_crc(1'b0);
1160 88 mohor
    gen_clk(1);
1161 87 mohor
 
1162 139 igorm
    for(i=`DBG_WB_CMD_LEN -1; i>=0; i=i-1)
1163 88 mohor
    begin
1164
      tdi_pad_i<=#1 command[i]; // command
1165 114 mohor
      calculate_crc(command[i]);
1166 88 mohor
      gen_clk(1);
1167
    end
1168 87 mohor
 
1169 139 igorm
    for(i=`DBG_WB_CRC_LEN -1; i>=0; i=i-1)
1170 88 mohor
    begin
1171 139 igorm
      tdi_pad_i<=#1 crc_out[i];
1172 88 mohor
      gen_clk(1);
1173
    end
1174
 
1175 92 mohor
    tdi_pad_i<=#1 1'hz;
1176 110 mohor
 
1177 139 igorm
    crc_in = {`DBG_WB_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1178 110 mohor
 
1179 139 igorm
    for(i=`DBG_WB_ACC_TYPE_LEN -1; i>=0; i=i-1)
1180
    begin
1181
      gen_clk(1);
1182
      acc_type[i] = tdo;
1183
    end
1184 88 mohor
 
1185 139 igorm
    for(i=`DBG_WB_ADR_LEN -1; i>=0; i=i-1)       // address
1186 88 mohor
    begin
1187
      gen_clk(1);
1188 139 igorm
      addr[i] = tdo;
1189 88 mohor
    end
1190 139 igorm
 
1191
    for(i=`DBG_WB_LEN_LEN -1; i>=0; i=i-1)       // length
1192
    begin
1193
      gen_clk(1);
1194
      length[i] = tdo;
1195
    end
1196 88 mohor
 
1197 139 igorm
    for(i=`DBG_WB_STATUS_LEN -1; i>=0; i=i-1)
1198
      begin
1199
        gen_clk(1);     // Generating clock to read out a status bit.
1200
        status_wb[i] = tdo;
1201
      end
1202 88 mohor
 
1203 139 igorm
    if (|status_wb)
1204 110 mohor
      begin
1205 139 igorm
        $write("(*E) (%0t) debug_wishbone_rd_comm: ", $time);
1206
        casex (status_wb)
1207
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1208
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1209
          4'bxx1x : $display("Unknown command !!!\n\n", $time);
1210
          4'bxxx1 : $display("Unknown command !!!\n\n", $time);
1211
        endcase
1212 110 mohor
        $stop;
1213
      end
1214
 
1215 139 igorm
 
1216
    for(i=0; i<`DBG_WB_CRC_LEN -1; i=i+1)  // Getting in the CRC
1217
    begin
1218
      gen_clk(1);
1219
    end
1220
 
1221
    tms_pad_i<=#1 1'b1;
1222
    gen_clk(1);         // to exit1_dr
1223
 
1224
    tms_pad_i<=#1 1'b1;
1225 88 mohor
    gen_clk(1);         // to update_dr
1226 139 igorm
    tms_pad_i<=#1 1'b0;
1227 88 mohor
    gen_clk(1);         // to run_test_idle
1228
  end
1229 139 igorm
endtask       // debug_wishbone_rd_comm
1230 88 mohor
 
1231
 
1232
 
1233
 
1234 139 igorm
 
1235 88 mohor
task debug_wishbone_go;
1236 110 mohor
  input         wait_for_wb_ready;
1237 99 mohor
  input         gen_crc_err;
1238 90 mohor
  integer i;
1239 116 mohor
  reg   [4:0]   bit_pointer;
1240
  integer       word_pointer;
1241
  reg  [31:0]   tmp_data;
1242 139 igorm
  reg [`DBG_WB_CMD_LEN -1:0]        command;
1243
 
1244 90 mohor
 
1245 2 mohor
  begin
1246 88 mohor
    $display("(%0t) Task debug_wishbone_go (previous command was %0s): ", $time, last_wb_cmd_text);
1247 139 igorm
    command = `DBG_WB_GO;
1248 116 mohor
    word_pointer = 0;
1249 88 mohor
 
1250 139 igorm
    tms_pad_i<=#1 1'b1;
1251 80 mohor
    gen_clk(1);
1252 139 igorm
    tms_pad_i<=#1 1'b0;
1253 80 mohor
    gen_clk(2);  // we are in shiftDR
1254 2 mohor
 
1255 139 igorm
    crc_out = {`DBG_WB_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1256 99 mohor
 
1257 138 igorm
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1258 114 mohor
    calculate_crc(1'b0);
1259 80 mohor
    gen_clk(1);
1260 88 mohor
 
1261 139 igorm
    for(i=`DBG_WB_CMD_LEN -1; i>=0; i=i-1)
1262 88 mohor
    begin
1263
      tdi_pad_i<=#1 command[i]; // command
1264 114 mohor
      calculate_crc(command[i]);
1265 88 mohor
      gen_clk(1);
1266
    end
1267
 
1268
 
1269 139 igorm
    if ((last_wb_cmd == `DBG_WB_WRITE8) | (last_wb_cmd == `DBG_WB_WRITE16) | (last_wb_cmd == `DBG_WB_WRITE32))  // When WB_WRITEx was previously activated, data needs to be shifted.
1270 88 mohor
      begin
1271 139 igorm
        for (i=0; i<((dbg_tb.i_dbg_top.i_dbg_wb.len_var) << 3); i=i+1)
1272 88 mohor
          begin
1273 116 mohor
            tmp_data = wb_data[word_pointer];
1274
            if ((!(i%32)) && (i>0))
1275 88 mohor
              begin
1276 116 mohor
                word_pointer = word_pointer + 1;
1277 88 mohor
              end
1278 116 mohor
            bit_pointer = 31-i[4:0];
1279
            tdi_pad_i<=#1 tmp_data[bit_pointer];
1280
            calculate_crc(tmp_data[bit_pointer]);
1281 90 mohor
            gen_clk(1);
1282
 
1283 88 mohor
          end
1284
      end
1285
 
1286 139 igorm
    for(i=`DBG_WB_CRC_LEN -1; i>=1; i=i-1)
1287 88 mohor
    begin
1288 114 mohor
      tdi_pad_i<=#1 crc_out[i];
1289 88 mohor
      gen_clk(1);
1290
    end
1291
 
1292 110 mohor
    if (gen_crc_err)  // Generate crc error at last crc bit
1293 114 mohor
      tdi_pad_i<=#1 ~crc_out[0];   // error crc
1294 110 mohor
    else
1295 114 mohor
      tdi_pad_i<=#1 crc_out[0];    // ok crc
1296 99 mohor
 
1297 110 mohor
    if (wait_for_wb_ready)
1298
      begin
1299 139 igorm
        tms_pad_i<=#1 1'b1;
1300 110 mohor
        gen_clk(1);       // to exit1_dr. Last CRC is shifted on this clk
1301 139 igorm
        tms_pad_i<=#1 1'b0;
1302 110 mohor
        gen_clk(1);       // to pause_dr
1303 90 mohor
 
1304 110 mohor
        #2;             // wait a bit for tdo to activate
1305
        while (tdo)     // waiting for wb to send "ready"
1306
        begin
1307
          gen_clk(1);       // staying in pause_dr
1308
        end
1309
 
1310 139 igorm
        tms_pad_i<=#1 1'b1;
1311 110 mohor
        gen_clk(1);       // to exit2_dr
1312 139 igorm
        tms_pad_i<=#1 1'b0;
1313 110 mohor
        gen_clk(1);       // to shift_dr
1314
      end
1315
    else
1316
      begin
1317
        gen_clk(1);       // Last CRC is shifted on this clk
1318
      end
1319 90 mohor
 
1320
 
1321 110 mohor
    tdi_pad_i<=#1 1'hz;
1322 139 igorm
    crc_in = {`DBG_WB_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1323 110 mohor
 
1324 139 igorm
    if ((last_wb_cmd == `DBG_WB_READ8) | (last_wb_cmd == `DBG_WB_READ16) | (last_wb_cmd == `DBG_WB_READ32))  // When WB_READx was previously activated, data needs to be shifted.
1325 90 mohor
      begin
1326 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);
1327 116 mohor
        word_pointer = 0; // Reset pointer
1328 95 mohor
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit); i=i+1)
1329 116 mohor
          begin
1330
            gen_clk(1);
1331
            if (i[4:0] == 31)   // Latching data
1332
              begin
1333
                wb_data[word_pointer] = in_data_be;
1334
                $display("\t\tin_data_be = 0x%x", in_data_be);
1335
                word_pointer = word_pointer + 1;
1336
              end
1337
          end
1338 90 mohor
      end
1339
 
1340
 
1341 139 igorm
    for(i=`DBG_WB_STATUS_LEN -1; i>=0; i=i-1)
1342
      begin
1343
        gen_clk(1);     // Generating clock to read out a status bit.
1344
        status_wb[i] = tdo;
1345
      end
1346 88 mohor
 
1347 139 igorm
    if (|status_wb)
1348
      begin
1349
        $write("(*E) (%0t) debug_wishbone_go error: ", $time);
1350
        casex (status_wb)
1351
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1352
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1353
          4'bxx1x : $display("WISHBONE error !!!\n\n", $time);
1354
          4'bxxx1 : $display("Overrun/Underrun !!!\n\n", $time);
1355
        endcase
1356
        $stop;
1357
      end
1358
 
1359
 
1360 138 igorm
    for(i=0; i<`DBG_WB_CRC_LEN -1; i=i+1)  // Getting in the CRC
1361 88 mohor
    begin
1362
      gen_clk(1);
1363
    end
1364
 
1365 139 igorm
    tms_pad_i<=#1 1'b1;
1366 88 mohor
    gen_clk(1);         // to exit1_dr
1367
 
1368 110 mohor
    if (~crc_match_in)
1369
      begin
1370
        $display("(%0t) Incoming CRC failed !!!", $time);
1371
        $stop;
1372
      end
1373
 
1374 139 igorm
    tms_pad_i<=#1 1'b1;
1375 88 mohor
    gen_clk(1);         // to update_dr
1376 139 igorm
    tms_pad_i<=#1 1'b0;
1377 88 mohor
    gen_clk(1);         // to run_test_idle
1378 2 mohor
  end
1379 88 mohor
endtask       // debug_wishbone_go
1380 2 mohor
 
1381
 
1382 139 igorm
`endif // DBG_WISHBONE_SUPPORTED
1383 88 mohor
 
1384
 
1385 139 igorm
`ifdef DBG_CPU_SUPPORTED
1386 99 mohor
task debug_cpu;
1387 139 igorm
  input [`DBG_CPU_CMD_LEN -1:0]   command;
1388
  input                           ready;
1389
  input [`DBG_CPU_ADR_LEN -1:0]   addr;
1390
  input [`DBG_CPU_LEN_LEN -1:0]   length;
1391
  input                           gen_crc_err;
1392
  input [99:0]                    text;
1393 99 mohor
  integer i;
1394
 
1395
  begin
1396
   $write("(%0t) Task debug_cpu: ", $time);
1397 88 mohor
 
1398 99 mohor
    test_text = text;
1399
 
1400
    case (command)
1401 139 igorm
      `DBG_CPU_READ   :
1402 99 mohor
        begin
1403 139 igorm
          $display("cpu_read (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
1404
          debug_cpu_wr_comm(`DBG_CPU_READ, addr, length, gen_crc_err);
1405
          last_cpu_cmd = `DBG_CPU_READ;  last_cpu_cmd_text = "DBG_CPU_READ";
1406
#10000;
1407
          debug_cpu_go(ready, gen_crc_err);
1408 99 mohor
        end
1409 139 igorm
      `DBG_CPU_WRITE  :
1410 99 mohor
        begin
1411 139 igorm
          $display("cpu_write (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
1412
          debug_cpu_wr_comm(`DBG_CPU_WRITE, addr, length, gen_crc_err);
1413
          last_cpu_cmd = `DBG_CPU_WRITE;  last_cpu_cmd_text = "DBG_CPU_WRITE";
1414
#10000;
1415
          debug_cpu_go(ready, gen_crc_err);
1416 99 mohor
        end
1417 139 igorm
      default:
1418 99 mohor
        begin
1419 139 igorm
          $display("(*E) debug_cpu : Unsupported instruction !!!");
1420 99 mohor
          $stop;
1421
        end
1422
    endcase
1423
  end
1424
endtask       // debug_cpu
1425
 
1426
 
1427
 
1428 139 igorm
task debug_cpu_wr_comm;
1429
  input [`DBG_CPU_ACC_TYPE_LEN -1:0]  acc_type;
1430
  input [`DBG_CPU_ADR_LEN -1:0]       addr;
1431
  input [`DBG_CPU_LEN_LEN -1:0]       length;
1432
  input                               gen_crc_err;
1433
  integer                             i;
1434
  reg   [`DBG_CPU_CMD_LEN -1:0]       command;
1435 99 mohor
 
1436
  begin
1437 139 igorm
    $display("(%0t) Task debug_cpu_wr_comm: ", $time);
1438 99 mohor
 
1439 139 igorm
    command = `DBG_CPU_WR_COMM;
1440
    tms_pad_i<=#1 1'b1;
1441 99 mohor
    gen_clk(1);
1442 139 igorm
    tms_pad_i<=#1 1'b0;
1443 99 mohor
    gen_clk(2);  // we are in shiftDR
1444
 
1445 139 igorm
    crc_out = {`DBG_CPU_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1446 99 mohor
 
1447 138 igorm
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1448 114 mohor
    calculate_crc(1'b0);
1449 99 mohor
    gen_clk(1);
1450
 
1451 139 igorm
    for(i=`DBG_CPU_CMD_LEN -1; i>=0; i=i-1)
1452 99 mohor
    begin
1453
      tdi_pad_i<=#1 command[i]; // command
1454 114 mohor
      calculate_crc(command[i]);
1455 99 mohor
      gen_clk(1);
1456
    end
1457
 
1458 139 igorm
    for(i=`DBG_CPU_ACC_TYPE_LEN -1; i>=0; i=i-1)
1459 99 mohor
    begin
1460 139 igorm
      tdi_pad_i<=#1 acc_type[i]; // command
1461
      calculate_crc(acc_type[i]);
1462
      gen_clk(1);
1463
    end
1464
 
1465
    for(i=`DBG_CPU_ADR_LEN -1; i>=0; i=i-1)       // address
1466
    begin
1467 99 mohor
      tdi_pad_i<=#1 addr[i];
1468 114 mohor
      calculate_crc(addr[i]);
1469 99 mohor
      gen_clk(1);
1470
    end
1471 93 mohor
 
1472 139 igorm
    for(i=`DBG_CPU_LEN_LEN -1; i>=0; i=i-1)       // length
1473 99 mohor
    begin
1474 139 igorm
      tdi_pad_i<=#1 length[i];
1475
      calculate_crc(length[i]);
1476
      gen_clk(1);
1477
    end
1478
 
1479
    for(i=`DBG_CPU_CRC_LEN -1; i>=0; i=i-1)
1480
    begin
1481
      if (gen_crc_err & (i==0))      // Generate crc error at last crc bit
1482 114 mohor
        tdi_pad_i<=#1 ~crc_out[i];   // error crc
1483 99 mohor
      else
1484 114 mohor
        tdi_pad_i<=#1 crc_out[i];    // ok crc
1485 99 mohor
 
1486
      gen_clk(1);
1487
    end
1488
 
1489 135 igorm
    tdi_pad_i<=#1 1'hz;
1490 110 mohor
 
1491 139 igorm
    crc_in = {`DBG_CPU_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1492 99 mohor
 
1493 139 igorm
    for(i=`DBG_CPU_STATUS_LEN -1; i>=0; i=i-1)
1494
      begin
1495
        gen_clk(1);     // Generating clock to read out a status bit.
1496
        status_cpu[i] = tdo;
1497
      end
1498
 
1499
    if (|status_cpu)
1500
      begin
1501
        $write("(*E) (%0t) debug_cpu_wr_comm error: ", $time);
1502
        casex (status_cpu)
1503
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1504
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1505
          4'bxx1x : $display("??? error !!!\n\n", $time);
1506
          4'bxxx1 : $display("Overrun/Underrun !!!\n\n", $time);
1507
        endcase
1508
        $stop;
1509
      end
1510
 
1511
 
1512 138 igorm
    for(i=0; i<`DBG_CPU_CRC_LEN -1; i=i+1)  // Getting in the CRC
1513 99 mohor
    begin
1514
      gen_clk(1);
1515
    end
1516
 
1517 139 igorm
    tms_pad_i<=#1 1'b1;
1518 99 mohor
    gen_clk(1);         // to exit1_dr
1519
 
1520 139 igorm
    tms_pad_i<=#1 1'b1;
1521
    gen_clk(1);         // to update_dr
1522
    tms_pad_i<=#1 1'b0;
1523
    gen_clk(1);         // to run_test_idle
1524
  end
1525
endtask       // debug_cpu_wr_comm
1526
 
1527
 
1528
 
1529
task debug_cpu_wr_ctrl;
1530
  input [`DBG_CPU_DR_LEN -1:0]  data;
1531
  input [99:0]                  text;
1532
  integer                       i;
1533
  reg   [`DBG_CPU_CMD_LEN -1:0] command;
1534
 
1535
  begin
1536
    test_text = text;
1537
 
1538
    $display("(%0t) Task debug_cpu_wr_ctrl (data=0x%0x (%0s))", $time, data, text);
1539
 
1540
    command = `DBG_CPU_WR_CTRL;
1541
    tms_pad_i<=#1 1'b1;
1542
    gen_clk(1);
1543
    tms_pad_i<=#1 1'b0;
1544
    gen_clk(2);  // we are in shiftDR
1545
 
1546
    crc_out = {`DBG_CPU_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1547
 
1548
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1549
    calculate_crc(1'b0);
1550
    gen_clk(1);
1551
 
1552
    for(i=`DBG_CPU_CMD_LEN -1; i>=0; i=i-1)
1553
    begin
1554
      tdi_pad_i<=#1 command[i]; // command
1555
      calculate_crc(command[i]);
1556
      gen_clk(1);
1557
    end
1558
 
1559
    for(i=`DBG_CPU_CTRL_LEN -1; i>=0; i=i-1)
1560
    begin
1561
      tdi_pad_i<=#1 data[i];                                    // data (used cotrol bits
1562
      calculate_crc(data[i]);
1563
      gen_clk(1);
1564
    end
1565
 
1566
    for(i=`DBG_CPU_DR_LEN - `DBG_CPU_CTRL_LEN -1; i>=0; i=i-1)  // unused control bits
1567
    begin
1568
      tdi_pad_i<=#1 1'b0;
1569
      calculate_crc(1'b0);
1570
      gen_clk(1);
1571
    end
1572
 
1573
    for(i=`DBG_CPU_CRC_LEN -1; i>=0; i=i-1)
1574
    begin
1575
      tdi_pad_i<=#1 crc_out[i];    // ok crc
1576
      gen_clk(1);
1577
    end
1578
 
1579
    tdi_pad_i<=#1 1'hz;
1580
 
1581
    crc_in = {`DBG_CPU_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1582
 
1583
    for(i=`DBG_CPU_STATUS_LEN -1; i>=0; i=i-1)
1584 110 mohor
      begin
1585 139 igorm
        gen_clk(1);     // Generating clock to read out a status bit.
1586
        status_cpu[i] = tdo;
1587
      end
1588
 
1589
    if (|status_cpu)
1590
      begin
1591
        $write("(*E) (%0t) debug_cpu_wr_ctrl error: ", $time);
1592
        casex (status_cpu)
1593
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1594
          4'bx1xx : $display("??? error !!!\n\n", $time);
1595
          4'bxx1x : $display("??? error !!!\n\n", $time);
1596
          4'bxxx1 : $display("??? error !!!\n\n", $time);
1597
        endcase
1598 110 mohor
        $stop;
1599
      end
1600
 
1601 139 igorm
 
1602
    for(i=0; i<`DBG_CPU_CRC_LEN -1; i=i+1)  // Getting in the CRC
1603
    begin
1604
      gen_clk(1);
1605
    end
1606
 
1607
    tms_pad_i<=#1 1'b1;
1608
    gen_clk(1);         // to exit1_dr
1609
 
1610
    tms_pad_i<=#1 1'b1;
1611 99 mohor
    gen_clk(1);         // to update_dr
1612 139 igorm
    tms_pad_i<=#1 1'b0;
1613 99 mohor
    gen_clk(1);         // to run_test_idle
1614
  end
1615 139 igorm
endtask       // debug_cpu_wr_ctrl
1616 99 mohor
 
1617
 
1618
 
1619 139 igorm
task debug_cpu_rd_ctrl;
1620
  output [`DBG_CPU_CTRL_LEN -1:0] data;
1621
  input  [99:0] text;
1622
  integer                         i;
1623
  reg   [`DBG_CPU_CMD_LEN -1:0]   command;
1624
 
1625
  begin
1626
    test_text = text;
1627
    $display("(%0t) Task debug_cpu_rd_ctrl: ", $time);
1628 99 mohor
 
1629 139 igorm
    command = `DBG_CPU_RD_CTRL;
1630
    tms_pad_i<=#1 1'b1;
1631
    gen_clk(1);
1632
    tms_pad_i<=#1 1'b0;
1633
    gen_clk(2);  // we are in shiftDR
1634
 
1635
    crc_out = {`DBG_CPU_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1636
 
1637
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1638
    calculate_crc(1'b0);
1639
    gen_clk(1);
1640
 
1641
    for(i=`DBG_CPU_CMD_LEN -1; i>=0; i=i-1)
1642
    begin
1643
      tdi_pad_i<=#1 command[i]; // command
1644
      calculate_crc(command[i]);
1645
      gen_clk(1);
1646
    end
1647
 
1648
    for(i=`DBG_CPU_CRC_LEN -1; i>=0; i=i-1)
1649
    begin
1650
      tdi_pad_i<=#1 crc_out[i];
1651
      gen_clk(1);
1652
    end
1653
 
1654
    tdi_pad_i<=#1 1'hz;
1655
 
1656
    crc_in = {`DBG_CPU_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1657
 
1658
    for(i=`DBG_CPU_CTRL_LEN -1; i>=0; i=i-1)     // data (used control bits)
1659
    begin
1660
      gen_clk(1);
1661
      data[i] = tdo;
1662
    end
1663
 
1664
    for(i=`DBG_CPU_DR_LEN - `DBG_CPU_CTRL_LEN -1; i>=0; i=i-1)       // unused control bits
1665
    begin
1666
      gen_clk(1);
1667
    end
1668
 
1669
    for(i=`DBG_CPU_STATUS_LEN -1; i>=0; i=i-1)
1670
      begin
1671
        gen_clk(1);     // Generating clock to read out a status bit.
1672
        status_cpu[i] = tdo;
1673
      end
1674
 
1675
    if (|status_cpu)
1676
      begin
1677
        $write("(*E) (%0t) debug_cpu_rd_ctrl: ", $time);
1678
        casex (status_cpu)
1679
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1680
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1681
          4'bxx1x : $display("Unknown command !!!\n\n", $time);
1682
          4'bxxx1 : $display("Unknown command !!!\n\n", $time);
1683
        endcase
1684
        $stop;
1685
      end
1686
 
1687
 
1688
    for(i=0; i<`DBG_CPU_CRC_LEN -1; i=i+1)  // Getting in the CRC
1689
    begin
1690
      gen_clk(1);
1691
    end
1692
 
1693
    tms_pad_i<=#1 1'b1;
1694
    gen_clk(1);         // to exit1_dr
1695
 
1696
    tms_pad_i<=#1 1'b1;
1697
    gen_clk(1);         // to update_dr
1698
    tms_pad_i<=#1 1'b0;
1699
    gen_clk(1);         // to run_test_idle
1700
  end
1701
endtask       // debug_cpu_rd_ctrl
1702
 
1703
 
1704
 
1705 99 mohor
task debug_cpu_go;
1706 139 igorm
  input         wait_for_cpu_ready;
1707 99 mohor
  input         gen_crc_err;
1708 139 igorm
  integer i;
1709
  reg   [4:0]   bit_pointer;
1710
  integer       word_pointer;
1711
  reg  [31:0]   tmp_data;
1712
  reg [`DBG_CPU_CMD_LEN -1:0]       command;
1713 99 mohor
 
1714
 
1715 93 mohor
  begin
1716 139 igorm
    $display("(%0t) Task debug_cpu_go (previous command was %0s): ", $time, last_cpu_cmd_text);
1717
    command = `DBG_CPU_GO;
1718
    word_pointer = 0;
1719 88 mohor
 
1720 139 igorm
    tms_pad_i<=#1 1'b1;
1721 93 mohor
    gen_clk(1);
1722 139 igorm
    tms_pad_i<=#1 1'b0;
1723 93 mohor
    gen_clk(2);  // we are in shiftDR
1724 88 mohor
 
1725 139 igorm
    crc_out = {`DBG_CPU_CRC_LEN{1'b1}}; // Initialize outgoing CRC to all ff
1726
 
1727 138 igorm
    tdi_pad_i<=#1 1'b0; // module_select bit = 0
1728 114 mohor
    calculate_crc(1'b0);
1729 93 mohor
    gen_clk(1);
1730 88 mohor
 
1731 139 igorm
    for(i=`DBG_CPU_CMD_LEN -1; i>=0; i=i-1)
1732 93 mohor
    begin
1733
      tdi_pad_i<=#1 command[i]; // command
1734 114 mohor
      calculate_crc(command[i]);
1735 93 mohor
      gen_clk(1);
1736
    end
1737 88 mohor
 
1738
 
1739 139 igorm
    if (last_cpu_cmd == `DBG_CPU_WRITE)  // When DBG_CPU_WRITE was previously activated, data needs to be shifted.
1740 93 mohor
      begin
1741 139 igorm
        for (i=0; i<((dbg_tb.i_dbg_top.i_dbg_cpu.len_var) << 3); i=i+1)
1742 93 mohor
          begin
1743 139 igorm
            tmp_data = wb_data[word_pointer];
1744
            if ((!(i%32)) && (i>0))
1745
              begin
1746
                word_pointer = word_pointer + 1;
1747
              end
1748
            bit_pointer = 31-i[4:0];
1749
            tdi_pad_i<=#1 tmp_data[bit_pointer];
1750
            calculate_crc(tmp_data[bit_pointer]);
1751 93 mohor
            gen_clk(1);
1752 139 igorm
 
1753 93 mohor
          end
1754
      end
1755 2 mohor
 
1756 139 igorm
    for(i=`DBG_CPU_CRC_LEN -1; i>=1; i=i-1)
1757 93 mohor
    begin
1758 139 igorm
      tdi_pad_i<=#1 crc_out[i];
1759 93 mohor
      gen_clk(1);
1760
    end
1761
 
1762 139 igorm
    if (gen_crc_err)  // Generate crc error at last crc bit
1763
      tdi_pad_i<=#1 ~crc_out[0];   // error crc
1764
    else
1765
      tdi_pad_i<=#1 crc_out[0];    // ok crc
1766 93 mohor
 
1767 139 igorm
    if (wait_for_cpu_ready)
1768
      begin
1769
        tms_pad_i<=#1 1'b1;
1770
        gen_clk(1);       // to exit1_dr. Last CRC is shifted on this clk
1771
        tms_pad_i<=#1 1'b0;
1772
        gen_clk(1);       // to pause_dr
1773 93 mohor
 
1774 139 igorm
        #2;             // wait a bit for tdo to activate
1775
        while (tdo)     // waiting for wb to send "ready"
1776
        begin
1777
          gen_clk(1);       // staying in pause_dr
1778
        end
1779
 
1780
        tms_pad_i<=#1 1'b1;
1781
        gen_clk(1);       // to exit2_dr
1782
        tms_pad_i<=#1 1'b0;
1783
        gen_clk(1);       // to shift_dr
1784
      end
1785 99 mohor
    else
1786 139 igorm
      begin
1787
        gen_clk(1);       // Last CRC is shifted on this clk
1788
      end
1789 93 mohor
 
1790 139 igorm
 
1791
    tdi_pad_i<=#1 1'hz;
1792
    crc_in = {`DBG_CPU_CRC_LEN{1'b1}};  // Initialize incoming CRC to all ff
1793
 
1794
    if (last_cpu_cmd == `DBG_CPU_READ)  // When DBG_CPU_READ was previously activated, data needs to be shifted.
1795 93 mohor
      begin
1796 139 igorm
        $display("\t\tGenerating %0d clocks to read %0d data bytes.", dbg_tb.i_dbg_top.i_dbg_cpu.data_cnt_limit, dbg_tb.i_dbg_top.i_dbg_cpu.data_cnt_limit>>3);
1797
        word_pointer = 0; // Reset pointer
1798
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_cpu.data_cnt_limit); i=i+1)
1799
          begin
1800
            gen_clk(1);
1801
            if (i[4:0] == 31)   // Latching data
1802
              begin
1803
                wb_data[word_pointer] = in_data_be;
1804
                $display("\t\tin_data_be = 0x%x", in_data_be);
1805
                word_pointer = word_pointer + 1;
1806
              end
1807
          end
1808 93 mohor
      end
1809
 
1810
 
1811 139 igorm
    for(i=`DBG_CPU_STATUS_LEN -1; i>=0; i=i-1)
1812
      begin
1813
        gen_clk(1);     // Generating clock to read out a status bit.
1814
        status_cpu[i] = tdo;
1815
      end
1816 93 mohor
 
1817 139 igorm
    if (|status_cpu)
1818
      begin
1819
        $write("(*E) (%0t) debug_cpu_go error: ", $time);
1820
        casex (status_cpu)
1821
          4'b1xxx : $display("CRC error !!!\n\n", $time);
1822
          4'bx1xx : $display("Unknown command !!!\n\n", $time);
1823
          4'bxx1x : $display("??? error !!!\n\n", $time);
1824
          4'bxxx1 : $display("Overrun/Underrun !!!\n\n", $time);
1825
        endcase
1826
        $stop;
1827
      end
1828
 
1829
 
1830 138 igorm
    for(i=0; i<`DBG_CPU_CRC_LEN -1; i=i+1)  // Getting in the CRC
1831 93 mohor
    begin
1832
      gen_clk(1);
1833
    end
1834
 
1835 139 igorm
    tms_pad_i<=#1 1'b1;
1836 93 mohor
    gen_clk(1);         // to exit1_dr
1837
 
1838 110 mohor
    if (~crc_match_in)
1839
      begin
1840
        $display("(%0t) Incoming CRC failed !!!", $time);
1841
        $stop;
1842
      end
1843
 
1844 139 igorm
    tms_pad_i<=#1 1'b1;
1845 93 mohor
    gen_clk(1);         // to update_dr
1846 139 igorm
    tms_pad_i<=#1 1'b0;
1847 93 mohor
    gen_clk(1);         // to run_test_idle
1848
  end
1849 99 mohor
endtask       // debug_cpu_go
1850 139 igorm
`endif  // DBG_CPU_SUPPORTED
1851 93 mohor
 
1852
 
1853
 
1854 113 mohor
always @ (posedge tck_pad_i)
1855
begin
1856
  in_data_be[31:1] <= #1 in_data_be[30:0];
1857
  in_data_be[0]    <= #1 tdo;
1858 93 mohor
 
1859 113 mohor
  in_data_le[31]   <= #1 tdo;
1860
  in_data_le[30:0] <= #1 in_data_le[31:1];
1861
end
1862 93 mohor
 
1863
 
1864
 
1865 114 mohor
// Calculating outgoing CRC
1866
task calculate_crc;
1867
  input data;
1868
 
1869
  begin
1870
    crc_out[0]  <= #1 data          ^ crc_out[31];
1871
    crc_out[1]  <= #1 data          ^ crc_out[0]  ^ crc_out[31];
1872
    crc_out[2]  <= #1 data          ^ crc_out[1]  ^ crc_out[31];
1873
    crc_out[3]  <= #1 crc_out[2];
1874
    crc_out[4]  <= #1 data          ^ crc_out[3]  ^ crc_out[31];
1875
    crc_out[5]  <= #1 data          ^ crc_out[4]  ^ crc_out[31];
1876
    crc_out[6]  <= #1 crc_out[5];
1877
    crc_out[7]  <= #1 data          ^ crc_out[6]  ^ crc_out[31];
1878
    crc_out[8]  <= #1 data          ^ crc_out[7]  ^ crc_out[31];
1879
    crc_out[9]  <= #1 crc_out[8];
1880
    crc_out[10] <= #1 data         ^ crc_out[9]  ^ crc_out[31];
1881
    crc_out[11] <= #1 data         ^ crc_out[10] ^ crc_out[31];
1882
    crc_out[12] <= #1 data         ^ crc_out[11] ^ crc_out[31];
1883
    crc_out[13] <= #1 crc_out[12];
1884
    crc_out[14] <= #1 crc_out[13];
1885
    crc_out[15] <= #1 crc_out[14];
1886
    crc_out[16] <= #1 data         ^ crc_out[15] ^ crc_out[31];
1887
    crc_out[17] <= #1 crc_out[16];
1888
    crc_out[18] <= #1 crc_out[17];
1889
    crc_out[19] <= #1 crc_out[18];
1890
    crc_out[20] <= #1 crc_out[19];
1891
    crc_out[21] <= #1 crc_out[20];
1892
    crc_out[22] <= #1 data         ^ crc_out[21] ^ crc_out[31];
1893
    crc_out[23] <= #1 data         ^ crc_out[22] ^ crc_out[31];
1894
    crc_out[24] <= #1 crc_out[23];
1895
    crc_out[25] <= #1 crc_out[24];
1896
    crc_out[26] <= #1 data         ^ crc_out[25] ^ crc_out[31];
1897
    crc_out[27] <= #1 crc_out[26];
1898
    crc_out[28] <= #1 crc_out[27];
1899
    crc_out[29] <= #1 crc_out[28];
1900
    crc_out[30] <= #1 crc_out[29];
1901
    crc_out[31] <= #1 crc_out[30];
1902
  end
1903
endtask // calculate_crc
1904 93 mohor
 
1905
 
1906 114 mohor
// Calculating and checking input CRC
1907
always @(posedge tck_pad_i)
1908
begin
1909
  crc_in[0]  <= #1 tdo           ^ crc_in[31];
1910
  crc_in[1]  <= #1 tdo           ^ crc_in[0]  ^ crc_in[31];
1911
  crc_in[2]  <= #1 tdo           ^ crc_in[1]  ^ crc_in[31];
1912
  crc_in[3]  <= #1 crc_in[2];
1913
  crc_in[4]  <= #1 tdo           ^ crc_in[3]  ^ crc_in[31];
1914
  crc_in[5]  <= #1 tdo           ^ crc_in[4]  ^ crc_in[31];
1915
  crc_in[6]  <= #1 crc_in[5];
1916
  crc_in[7]  <= #1 tdo           ^ crc_in[6]  ^ crc_in[31];
1917
  crc_in[8]  <= #1 tdo           ^ crc_in[7]  ^ crc_in[31];
1918
  crc_in[9]  <= #1 crc_in[8];
1919
  crc_in[10] <= #1 tdo          ^ crc_in[9]  ^ crc_in[31];
1920
  crc_in[11] <= #1 tdo          ^ crc_in[10] ^ crc_in[31];
1921
  crc_in[12] <= #1 tdo          ^ crc_in[11] ^ crc_in[31];
1922
  crc_in[13] <= #1 crc_in[12];
1923
  crc_in[14] <= #1 crc_in[13];
1924
  crc_in[15] <= #1 crc_in[14];
1925
  crc_in[16] <= #1 tdo          ^ crc_in[15] ^ crc_in[31];
1926
  crc_in[17] <= #1 crc_in[16];
1927
  crc_in[18] <= #1 crc_in[17];
1928
  crc_in[19] <= #1 crc_in[18];
1929
  crc_in[20] <= #1 crc_in[19];
1930
  crc_in[21] <= #1 crc_in[20];
1931
  crc_in[22] <= #1 tdo          ^ crc_in[21] ^ crc_in[31];
1932
  crc_in[23] <= #1 tdo          ^ crc_in[22] ^ crc_in[31];
1933
  crc_in[24] <= #1 crc_in[23];
1934
  crc_in[25] <= #1 crc_in[24];
1935
  crc_in[26] <= #1 tdo          ^ crc_in[25] ^ crc_in[31];
1936
  crc_in[27] <= #1 crc_in[26];
1937
  crc_in[28] <= #1 crc_in[27];
1938
  crc_in[29] <= #1 crc_in[28];
1939
  crc_in[30] <= #1 crc_in[29];
1940
  crc_in[31] <= #1 crc_in[30];
1941
end
1942 93 mohor
 
1943 114 mohor
assign crc_match_in = crc_in == 32'h0;
1944
 
1945
 
1946
 
1947 2 mohor
/**********************************************************************************
1948
*                                                                                 *
1949
*   Printing the information to the screen                                        *
1950
*                                                                                 *
1951
**********************************************************************************/
1952
 
1953 139 igorm
`ifdef DBG_MORE_INFO
1954 80 mohor
always @ (posedge tck_pad_i)
1955 2 mohor
begin
1956 80 mohor
  if(dbg_tb.i_tap_top.update_ir)
1957
    case(dbg_tb.i_tap_top.jtag_ir[`IR_LENGTH-1:0])
1958
      `EXTEST         : $display("\tInstruction EXTEST entered");
1959
      `SAMPLE_PRELOAD : $display("\tInstruction SAMPLE_PRELOAD entered");
1960
      `IDCODE         : $display("\tInstruction IDCODE entered");
1961
      `MBIST          : $display("\tInstruction MBIST entered");
1962
      `DEBUG          : $display("\tInstruction DEBUG entered");
1963
      `BYPASS         : $display("\tInstruction BYPASS entered");
1964
                default           :     $display("\n\tInstruction not valid. Instruction BYPASS activated !!!");
1965 2 mohor
    endcase
1966
end
1967 138 igorm
`endif
1968 2 mohor
 
1969
 
1970 80 mohor
// We never use following states: exit2_ir,  exit2_dr,  pause_ir or pause_dr
1971
always @ (posedge tck_pad_i)
1972 2 mohor
begin
1973 80 mohor
  if(dbg_tb.i_tap_top.pause_ir | dbg_tb.i_tap_top.exit2_ir)
1974 2 mohor
    begin
1975 80 mohor
      $display("\n(%0t) ERROR: State pause_ir or exit2_ir detected.", $time);
1976
      $display("(%0t) Simulation stopped !!!", $time);
1977
      $stop;
1978 2 mohor
    end
1979
end
1980
 
1981
 
1982 80 mohor
 
1983 73 mohor
 
1984 88 mohor
// Detecting CRC error
1985 138 igorm
/*
1986 128 mohor
always @ (
1987 138 igorm
           posedge dbg_tb.i_dbg_top.module_latch_en
1988 139 igorm
           `ifdef DBG_WISHBONE_SUPPORTED
1989 128 mohor
           or posedge dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_end
1990
           `endif
1991 139 igorm
           `ifdef DBG_CPU_SUPPORTED
1992 128 mohor
           or posedge dbg_tb.i_dbg_top.i_dbg_cpu.crc_cnt_end
1993
           `endif
1994
         )
1995
 
1996
 
1997 88 mohor
begin
1998
  #2;
1999
  if (~dbg_tb.i_dbg_top.crc_match)
2000
    begin
2001
      $display("\t\tCRC ERROR !!!");
2002 90 mohor
      $stop;
2003 88 mohor
    end
2004
end
2005 138 igorm
*/
2006 80 mohor
 
2007 88 mohor
 
2008 80 mohor
endmodule // dbg_tb
2009
 
2010
 

powered by: WebSVN 2.1.0

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