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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_21/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 158

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

powered by: WebSVN 2.1.0

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