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 121

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

powered by: WebSVN 2.1.0

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