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 140

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

powered by: WebSVN 2.1.0

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