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 138

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

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

powered by: WebSVN 2.1.0

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