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 135

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

powered by: WebSVN 2.1.0

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