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 113

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

powered by: WebSVN 2.1.0

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