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 101

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

powered by: WebSVN 2.1.0

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