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 124

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

powered by: WebSVN 2.1.0

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