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 120

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

powered by: WebSVN 2.1.0

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