OpenCores
URL https://opencores.org/ocsvn/dbg_interface/dbg_interface/trunk

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_13/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 87

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 80 mohor
//// Copyright (C) 2000 - 2003 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 87 mohor
// Revision 1.15  2003/12/23 14:26:01  mohor
47
// New version of the debug interface. Not finished, yet.
48
//
49 80 mohor
// Revision 1.14  2003/10/23 16:16:30  mohor
50
// CRC logic changed.
51
//
52 73 mohor
// Revision 1.13  2003/08/28 13:54:33  simons
53
// Three more chains added for cpu debug access.
54
//
55 63 simons
// Revision 1.12  2002/05/07 14:44:52  mohor
56
// mon_cntl_o signals that controls monitor mux added.
57
//
58 47 mohor
// Revision 1.11  2002/03/12 14:32:26  mohor
59
// Few outputs for boundary scan chain added.
60
//
61 38 mohor
// Revision 1.10  2002/03/08 15:27:08  mohor
62
// Structure changed. Hooks for jtag chain added.
63
//
64 36 mohor
// Revision 1.9  2001/10/19 11:39:20  mohor
65
// dbg_timescale.v changed to timescale.v This is done for the simulation of
66
// few different cores in a single project.
67
//
68 17 mohor
// Revision 1.8  2001/10/17 10:39:17  mohor
69
// bs_chain_o added.
70
//
71 15 mohor
// Revision 1.7  2001/10/16 10:10:18  mohor
72
// Signal names changed to lowercase.
73
//
74 13 mohor
// Revision 1.6  2001/10/15 09:52:50  mohor
75
// Wishbone interface added, few fixes for better performance,
76
// hooks for boundary scan testing added.
77
//
78 12 mohor
// Revision 1.5  2001/09/24 14:06:12  mohor
79
// Changes connected to the OpenRISC access (SPR read, SPR write).
80
//
81 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
82
// Working version. Few bugs fixed, comments added.
83
//
84 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
85
// Minor changes for simulation.
86
//
87 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
88
// Trace fixed. Some registers changed, trace simplified.
89
//
90 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
91
// Initial official release.
92
//
93 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
94
// This is a backup. It is not a fully working version. Not for use, yet.
95
//
96
// Revision 1.2  2001/05/18 13:10:05  mohor
97
// Headers changed. All additional information is now avaliable in the README.txt file.
98
//
99
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
100
// Initial release
101
//
102
//
103
 
104
 
105 17 mohor
`include "timescale.v"
106 2 mohor
`include "dbg_defines.v"
107 80 mohor
`include "dbg_wb_defines.v"
108
//`include "dbg_tb_defines.v"
109 2 mohor
 
110
// Test bench
111
module dbg_tb;
112
 
113 80 mohor
parameter TCLK = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
114 2 mohor
 
115 80 mohor
reg   tms_pad_i;
116
reg   tck_pad_i;
117
reg   trst_pad_i;
118
reg   tdi_pad_i;
119
wire  tdo_pad_o;
120
wire  tdo_padoe_o;
121 2 mohor
 
122 80 mohor
wire  shift_dr_o;
123
wire  pause_dr_o;
124
wire  update_dr_o;
125 2 mohor
 
126 80 mohor
wire  extest_select_o;
127
wire  sample_preload_select_o;
128
wire  mbist_select_o;
129
wire  debug_select_o;
130 2 mohor
 
131 80 mohor
// WISHBONE common signals
132
reg   wb_rst_i;
133
reg   wb_clk_i;
134
 
135
// WISHBONE master interface
136
wire [31:0] wb_adr_o;
137
wire [31:0] wb_dat_o;
138
wire [31:0] wb_dat_i;
139
wire        wb_cyc_o;
140
wire        wb_stb_o;
141
wire  [3:0] wb_sel_o;
142
wire        wb_we_o;
143
wire        wb_ack_i;
144
wire        wb_cab_o;
145
wire        wb_err_i;
146
wire  [2:0] wb_cti_o;
147
wire  [1:0] wb_bte_o;
148 2 mohor
 
149 87 mohor
// Text used for easier debugging
150
reg  [99:0] test_text;
151 2 mohor
 
152
 
153 12 mohor
 
154
 
155 80 mohor
wire  tdo_o;
156 12 mohor
 
157 80 mohor
wire  debug_tdi_i;
158
wire  bs_chain_tdi_i;
159
wire  mbist_tdi_i;
160 73 mohor
 
161 80 mohor
reg   test_enabled;
162 73 mohor
 
163 80 mohor
reg [31:0] result;
164 2 mohor
 
165 80 mohor
wire tdo;
166 73 mohor
 
167 80 mohor
assign tdo = tdo_padoe_o? tdo_pad_o : 1'hz;
168 73 mohor
 
169 80 mohor
// Connecting TAP module
170
tap_top i_tap_top (
171
                    .tms_pad_i(tms_pad_i),
172
                    .tck_pad_i(tck_pad_i),
173
                    .trst_pad_i(!trst_pad_i),
174
                    .tdi_pad_i(tdi_pad_i),
175
                    .tdo_pad_o(tdo_pad_o),
176
                    .tdo_padoe_o(tdo_padoe_o),
177 38 mohor
 
178 80 mohor
                    // TAP states
179
                    .shift_dr_o(shift_dr_o),
180
                    .pause_dr_o(pause_dr_o),
181
                    .update_dr_o(update_dr_o),
182 38 mohor
 
183 80 mohor
                    // Select signals for boundary scan or mbist
184
                    .extest_select_o(extest_select_o),
185
                    .sample_preload_select_o(sample_preload_select_o),
186
                    .mbist_select_o(mbist_select_o),
187
                    .debug_select_o(debug_select_o),
188 2 mohor
 
189 80 mohor
                    // TDO signal that is connected to TDI of sub-modules.
190
                    .tdo_o(tdo_o),
191 38 mohor
 
192 80 mohor
                    // TDI signals from sub-modules
193
                    .debug_tdi_i(debug_tdi_i),        // from debug module
194
                    .bs_chain_tdi_i(bs_chain_tdi_i),  // from Boundary Scan Chain
195
                    .mbist_tdi_i(mbist_tdi_i)         // from Mbist Chain
196 73 mohor
 
197 38 mohor
               );
198 2 mohor
 
199
 
200 80 mohor
dbg_top i_dbg_top  (
201
 
202
                    .trst_i(!trst_pad_i),
203
                    .tck_i(tck_pad_i),
204
                    .tdi_i(tdo_o),
205
                    .tdo_o(debug_tdi_i),
206
 
207
                    // TAP states
208
                    .shift_dr_i   (shift_dr_o),
209
                    .pause_dr_i   (pause_dr_o),
210
                    .update_dr_i  (update_dr_o),
211
 
212
                    // Instructions
213
                    .debug_select_i(debug_select_o),
214 12 mohor
 
215 80 mohor
                    // WISHBONE common signals
216
                    .wb_rst_i      (wb_rst_i),
217
                    .wb_clk_i      (wb_clk_i),
218
 
219
                    // WISHBONE master interface
220
                    .wb_adr_o      (wb_adr_o),
221
                    .wb_dat_o      (wb_dat_o),
222
                    .wb_dat_i      (wb_dat_i),
223
                    .wb_cyc_o      (wb_cyc_o),
224
                    .wb_stb_o      (wb_stb_o),
225
                    .wb_sel_o      (wb_sel_o),
226
                    .wb_we_o       (wb_we_o),
227
                    .wb_ack_i      (wb_ack_i),
228
                    .wb_cab_o      (wb_cab_o),
229
                    .wb_err_i      (wb_err_i),
230
                    .wb_cti_o      (wb_cti_o),
231
                    .wb_bte_o      (wb_bte_o)
232
                   );
233 12 mohor
 
234
 
235 80 mohor
wb_slave_behavioral wb_slave
236
                   (
237
                    .CLK_I(wb_clk_i),
238
                    .RST_I(wb_rst_i),
239
                    .ACK_O(wb_ack_i),
240
                    .ADR_I(wb_adr_o),
241
                    .CYC_I(wb_cyc_o),
242
                    .DAT_O(wb_dat_i),
243
                    .DAT_I(wb_dat_o),
244
                    .ERR_O(wb_err_i),
245
                    .RTY_O(),      // NOT USED for now!
246
                    .SEL_I(wb_sel_o),
247
                    .STB_I(wb_stb_o),
248
                    .WE_I (wb_we_o),
249
                    .CAB_I(1'b0)
250
                   );
251 2 mohor
 
252
 
253 80 mohor
// Initial values
254 2 mohor
initial
255
begin
256 80 mohor
  test_enabled = 1'b0;
257
  trst_pad_i = 1'b1;
258
  tms_pad_i = 1'hz;
259
  tck_pad_i = 1'hz;
260
  tdi_pad_i = 1'hz;
261
 
262
  #100;
263
  trst_pad_i = 1'b0;
264
  #100;
265
  trst_pad_i = 1'b1;
266
  #1 test_enabled<=#1 1'b1;
267 2 mohor
end
268
 
269 80 mohor
initial
270
begin
271
  wb_rst_i = 1'b0;
272
  #1000;
273
  wb_rst_i = 1'b1;
274
  #1000;
275
  wb_rst_i = 1'b0;
276 2 mohor
 
277 80 mohor
  // Initial values for wishbone slave model
278
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
279
end
280
 
281
initial
282 2 mohor
begin
283 80 mohor
  wb_clk_i = 1'b0;
284
  forever #5 wb_clk_i = ~wb_clk_i;
285 2 mohor
end
286
 
287 80 mohor
always @ (posedge test_enabled)
288
begin
289 2 mohor
 
290 80 mohor
  $display("//////////////////////////////////////////////////////////////////");
291
  $display("//                                                              //");
292
  $display("//  (%0t) dbg_tb starting                                     //", $time);
293
  $display("//                                                              //");
294
  $display("//////////////////////////////////////////////////////////////////");
295 2 mohor
 
296 80 mohor
  initialize_memory(32'h12340000, 32'h00100000);  // Initialize 0x100000 bytes starting from address 0x12340000
297 2 mohor
 
298 80 mohor
  reset_tap;
299
  goto_run_test_idle;
300 12 mohor
 
301 80 mohor
  // Testing read and write to internal registers
302
  #10000;
303
  set_instruction(`IDCODE);
304
  read_id_code;
305 12 mohor
 
306 80 mohor
  set_instruction(`DEBUG);
307
  #10000;
308 2 mohor
 
309 80 mohor
  chain_select(`WISHBONE_SCAN_CHAIN, 32'hf2bcd929);
310 12 mohor
 
311 80 mohor
//  #10000;
312
//  xxx(4'b1001, 32'he579b242);
313 12 mohor
 
314 80 mohor
  #10000;
315 2 mohor
 
316 87 mohor
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345678, 32'h0, 16'h4, 32'h08359131, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
317
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345679, 32'h0, 16'h4, 32'hadfeabe2, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
318
//  debug_wishbone(`WB_READ8, 1'b0, 32'h1234567a, 32'h0, 16'h4, 32'hd8b08283, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
319 2 mohor
 
320 87 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345678, 32'h0, 16'h4, 32'haf07fce0, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
321
//  debug_wishbone(`WB_READ16, 1'b0, 32'h1234567a, 32'h0, 16'h4, 32'h7f82ef52, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
322 2 mohor
 
323 87 mohor
  debug_wishbone(`WB_READ32, 1'b0, 32'h12345678, 32'h0, 16'h4, 32'h969b4113, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
324 2 mohor
 
325 87 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345679, 32'h0, 16'h4, 32'h0accc633, result, "abc"); // {command, ready, addr, data, length, crc, result, text}
326 5 mohor
 
327 80 mohor
  #10000;
328
//  xxx(4'b1001, 32'he579b242);
329
 
330
  wb_slave.cycle_response(`NO_RESPONSE, 8'h03, 8'h2);   // (`NO_RESPONSE, wbs_waits, wbs_retries);
331 87 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12345678, 32'h0, 16'h4, 32'h969b4113, result, "pac 1"); // {command, ready, addr, data, length, crc, result, text}
332
 
333
  #10000;
334 80 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
335 87 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 32'h0, 16'h4, 32'h2ec6ae56, result, "pac 2"); // {command, ready, addr, data, length, crc, result, text}
336 80 mohor
 
337
  #10000;
338 87 mohor
  wb_slave.cycle_response(`ERR_RESPONSE, 8'h03, 8'h2);   // (`NO_RESPONSE, wbs_waits, wbs_retries);
339
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 32'h0, 16'h4, 32'h2ec6ae56, result, "pac 3"); // {command, ready, addr, data, length, crc, result, text}
340 80 mohor
 
341
  #10000;
342 87 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 32'h0, 16'h0, 32'haae8e1f9, result, "status 1"); // {command, ready, addr, data, length, crc, result, text}
343 80 mohor
 
344 87 mohor
  #10000;
345
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 32'h0, 16'h0, 32'haae8e1f9, result, "status 2"); // {command, ready, addr, data, length, crc, result, text}
346 80 mohor
 
347 87 mohor
  #10000;
348
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
349
  debug_wishbone(`WB_READ32, 1'b1, 32'h12347778, 32'h0, 16'hc, 32'habaa5f3f, result, "rst_status"); // {command, ready, addr, data, length, crc, result, text}
350 80 mohor
 
351 87 mohor
  #10000;
352
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 32'h0, 16'h4, 32'h2ec6ae56, result, "tre 8"); // {command, ready, addr, data, length, crc, result, text}
353
 
354
  #10000;
355
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 32'h0, 16'h0, 32'haae8e1f9, result, "go 1"); // {command, ready, addr, data, length, crc, result, text}
356
 
357
 
358
 
359 80 mohor
/*
360
  // Testing read and write to CPU0 registers
361
  #10000;
362
  set_instruction(`CHAIN_SELECT);
363
  chain_select(`CPU_DEBUG_CHAIN_0, 8'h12);  // {chain, crc}
364
  set_instruction(`DEBUG);
365
  WriteCPURegister(32'h11001100, 32'h00110011, 8'h86);  // {data, addr, crc}
366
 
367
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
368
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
369
*/
370
  #5000 gen_clk(1);            // One extra TCLK for debugging purposes
371 5 mohor
  #1000 $stop;
372 80 mohor
 
373 2 mohor
end
374
 
375 80 mohor
 
376
task initialize_memory;
377
  input [31:0] start_addr;
378
  input [31:0] length;
379
  integer i;
380
  reg [31:0] addr;
381
  begin
382
    for (i=0; i<length; i=i+4)
383
      begin
384
        addr = start_addr + i;
385
        wb_slave.wr_mem(addr, {addr[7:0], addr[15:8], addr[23:16], addr[31:24]}, 4'hf);    // adr, data, sel
386
      end
387
  end
388
endtask
389
 
390
 
391
 
392 2 mohor
// Generation of the TCLK signal
393 80 mohor
task gen_clk;
394
  input [7:0] num;
395 2 mohor
  integer i;
396
  begin
397 80 mohor
    for(i=0; i<num; i=i+1)
398 2 mohor
      begin
399 80 mohor
        #TCLK tck_pad_i<=1;
400
        #TCLK tck_pad_i<=0;
401 2 mohor
      end
402
  end
403
endtask
404
 
405
 
406
// TAP reset
407 80 mohor
task reset_tap;
408 2 mohor
  begin
409 80 mohor
    $display("(%0t) Task reset_tap", $time);
410
    tms_pad_i<=#1 1'b1;
411
    gen_clk(7);
412 2 mohor
  end
413
endtask
414
 
415
 
416
// Goes to RunTestIdle state
417 80 mohor
task goto_run_test_idle;
418 2 mohor
  begin
419 80 mohor
    $display("(%0t) Task goto_run_test_idle", $time);
420
    tms_pad_i<=#1 1'b0;
421
    gen_clk(1);
422 2 mohor
  end
423
endtask
424
 
425
 
426
// sets the instruction to the IR register and goes to the RunTestIdle state
427 80 mohor
task set_instruction;
428
  input [3:0] instr;
429 2 mohor
  integer i;
430
 
431
  begin
432 80 mohor
    $display("(%0t) Task set_instruction", $time);
433
    tms_pad_i<=#1 1;
434
    gen_clk(2);
435
    tms_pad_i<=#1 0;
436
    gen_clk(2);  // we are in shiftIR
437 2 mohor
 
438
    for(i=0; i<`IR_LENGTH-1; i=i+1)
439
    begin
440 80 mohor
      tdi_pad_i<=#1 instr[i];
441
      gen_clk(1);
442 2 mohor
    end
443
 
444 80 mohor
    tdi_pad_i<=#1 instr[i]; // last shift
445
    tms_pad_i<=#1 1;        // going out of shiftIR
446
    gen_clk(1);
447
      tdi_pad_i<=#1 'hz;    // tri-state
448
    gen_clk(1);
449
    tms_pad_i<=#1 0;
450
    gen_clk(1);       // we are in RunTestIdle
451 2 mohor
  end
452
endtask
453
 
454
 
455 80 mohor
// Reads the ID code
456
task read_id_code;
457
  begin
458
    $display("(%0t) Task read_id_code", $time);
459
    tms_pad_i<=#1 1;
460
    gen_clk(1);
461
    tms_pad_i<=#1 0;
462
    gen_clk(2);  // we are in shiftDR
463
 
464
    tdi_pad_i<=#1 0;
465
    gen_clk(31);
466
 
467
    tms_pad_i<=#1 1;        // going out of shiftIR
468
    gen_clk(1);
469
 
470
    tdi_pad_i<=#1 'hz; // tri-state
471
    gen_clk(1);
472
    tms_pad_i<=#1 0;
473
    gen_clk(1);       // we are in RunTestIdle
474
  end
475
endtask
476
 
477
 
478 2 mohor
// sets the selected scan chain and goes to the RunTestIdle state
479 80 mohor
task chain_select;
480
  input [3:0]  data;
481
  input [31:0] crc;
482 2 mohor
  integer i;
483
 
484
  begin
485 80 mohor
    $display("(%0t) Task chain_select", $time);
486
    tms_pad_i<=#1 1;
487
    gen_clk(1);
488
    tms_pad_i<=#1 0;
489
    gen_clk(2);  // we are in shiftDR
490 2 mohor
 
491 80 mohor
    tdi_pad_i<=#1 1'b1; // chain_select bit
492
    gen_clk(1);
493
 
494 2 mohor
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
495
    begin
496 80 mohor
      tdi_pad_i<=#1 data[i];
497
      gen_clk(1);
498 2 mohor
    end
499
 
500 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
501 2 mohor
    begin
502 80 mohor
      tdi_pad_i<=#1 crc[`CRC_LEN -1-i];
503
      gen_clk(1);
504 2 mohor
    end
505
 
506 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
507
 
508
 
509
    for(i=0; i<`CRC_LEN -1; i=i+1)
510
    begin
511
      tdi_pad_i<=#1 1'b0;
512
      gen_clk(1);
513
    end
514
 
515
    tdi_pad_i<=#1 crc[i]; // last crc
516
    tms_pad_i<=#1 1;
517
    gen_clk(1);         // to exit1_dr
518
 
519
    tdi_pad_i<=#1 'hz;  // tri-state
520
    tms_pad_i<=#1 1;
521
    gen_clk(1);         // to update_dr
522
    tms_pad_i<=#1 0;
523
    gen_clk(1);         // to run_test_idle
524 2 mohor
  end
525
endtask
526
 
527
 
528 87 mohor
 
529
 
530
 
531
 
532
 
533 80 mohor
task debug_wishbone;
534
  input [2:0]   command;
535 87 mohor
  input         ready;
536 80 mohor
  input [31:0]  addr;
537
  input [31:0]  data;
538
  input [15:0]  length;
539
  input [31:0]  crc;
540
  output [31:0] result;
541 87 mohor
  input [99:0]  text;
542 80 mohor
  integer i;
543
 
544 2 mohor
  begin
545 80 mohor
   $write("(%0t) Task debug_wishbone: ", $time);
546 2 mohor
 
547 87 mohor
    test_text = text;
548 36 mohor
 
549 80 mohor
    case (command)
550
      `WB_STATUS   :
551
        begin
552 87 mohor
//          $display("wb_status (%0s)", text);
553
          $display("wb_status (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
554
          debug_wishbone_set_addr(command, ready, addr, length, crc);
555 80 mohor
        end
556
      `WB_READ8    :
557
        begin
558 87 mohor
          $display("wb_read8 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
559
          debug_wishbone_set_addr(command, ready, addr, length, crc);
560 80 mohor
        end
561
      `WB_READ16   :
562
        begin
563 87 mohor
          $display("wb_read16 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
564
          debug_wishbone_set_addr(command, ready, addr, length, crc);
565 80 mohor
        end
566
      `WB_READ32   :
567
        begin
568 87 mohor
          $display("wb_read32 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
569
          debug_wishbone_set_addr(command, ready, addr, length, crc);
570 80 mohor
        end
571
      `WB_WRITE8   :
572
        begin
573 87 mohor
          $display("wb_write8 (adr=0x%0x, data=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, data, length, crc, text);
574
          debug_wishbone_set_addr(command, ready, addr, length, crc);
575 80 mohor
        end
576
      `WB_WRITE16  :
577
        begin
578 87 mohor
          $display("wb_write16 (adr=0x%0x, data=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, data, length, crc, text);
579
          debug_wishbone_set_addr(command, ready, addr, length, crc);
580 80 mohor
        end
581
      `WB_WRITE32  :
582
        begin
583 87 mohor
          $display("wb_write32 (adr=0x%0x, data=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, data, length, crc, text);
584
          debug_wishbone_set_addr(command, ready, addr, length, crc);
585 80 mohor
        end
586
      `WB_GO       :
587
        begin
588 87 mohor
          $display("wb_go, crc=0x%0x (%0s))", crc, text);
589
          debug_wishbone_set_addr(command, ready, addr, length, crc);
590 80 mohor
        end
591
    endcase
592
 
593
 
594
 
595
 
596 2 mohor
  end
597 87 mohor
endtask       // debug_wishbone
598 2 mohor
 
599
 
600 80 mohor
 
601
 
602
 
603
 
604 87 mohor
task debug_wishbone_set_addr;
605 80 mohor
  input [2:0]   command;
606 87 mohor
  input         wait_for_wb_ready;
607 80 mohor
  input [31:0]  addr;
608
  input [15:0]  length;
609
  input [31:0]  crc;
610
  integer i;
611
 
612
  begin
613 87 mohor
    $display("(%0t) Task debug_wishbone_set_addr: ", $time);
614 80 mohor
 
615
    tms_pad_i<=#1 1;
616
    gen_clk(1);
617
    tms_pad_i<=#1 0;
618
    gen_clk(2);  // we are in shiftDR
619
 
620
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
621
    gen_clk(1);
622
 
623
    for(i=0; i<3; i=i+1)
624
    begin
625
      tdi_pad_i<=#1 command[i]; // command
626
      gen_clk(1);
627
    end
628
 
629
    for(i=0; i<32; i=i+1)       // address
630
    begin
631
      tdi_pad_i<=#1 addr[i];
632
      gen_clk(1);
633
    end
634 87 mohor
 
635 80 mohor
    for(i=0; i<16; i=i+1)       // length
636
    begin
637
      tdi_pad_i<=#1 length[i];
638
      gen_clk(1);
639
    end
640
 
641
    for(i=0; i<`CRC_LEN; i=i+1)
642
    begin
643
      tdi_pad_i<=#1 crc[`CRC_LEN -1-i];
644
      gen_clk(1);
645
    end
646
 
647 87 mohor
    if (wait_for_wb_ready)
648
      begin
649
        gen_clk(`STATUS_LEN -1);   // Generating 4 clocks to read out status. Going to pause_dr at the end
650
        tdi_pad_i<=#1 'hz;
651
        tms_pad_i<=#1 1;
652
        gen_clk(1);       // to exit1_dr
653
        tms_pad_i<=#1 0;
654
        gen_clk(1);       // to pause_dr
655
 
656
        while (dbg_tb.tdo_pad_o)     // waiting for wb to send "ready" 
657
        begin
658
          gen_clk(1);       // staying in pause_dr
659
        end
660
 
661
        tms_pad_i<=#1 1;
662
        gen_clk(1);       // to exit2_dr
663
        tms_pad_i<=#1 0;
664
        gen_clk(1);       // to shift_dr
665
      end
666
    else
667
      gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
668 80 mohor
 
669
    for(i=0; i<`CRC_LEN -1; i=i+1)
670
    begin
671
      tdi_pad_i<=#1 1'b0;
672
      gen_clk(1);
673
    end
674
 
675
    tdi_pad_i<=#1 crc[i]; // last crc
676
    tms_pad_i<=#1 1;
677
    gen_clk(1);         // to exit1_dr
678
 
679
    tdi_pad_i<=#1 'hz;  // tri-state
680
    tms_pad_i<=#1 1;
681
    gen_clk(1);         // to update_dr
682
    tms_pad_i<=#1 0;
683
    gen_clk(1);         // to run_test_idle
684
  end
685 87 mohor
endtask       // debug_wishbone_set_addr
686 80 mohor
 
687
 
688
 
689
 
690
 
691
 
692 87 mohor
 
693
 
694
 
695 2 mohor
// Reads sample from the Trace Buffer
696
task ReadTraceBuffer;
697
  begin
698 73 mohor
    $display("(%0t) Task ReadTraceBuffer", $time);
699 80 mohor
    tms_pad_i<=#1 1;
700
    gen_clk(1);
701
    tms_pad_i<=#1 0;
702
    gen_clk(2);  // we are in shiftDR
703 2 mohor
 
704 80 mohor
    tdi_pad_i<=#1 0;
705
    gen_clk(47);
706
    tms_pad_i<=#1 1;        // going out of shiftIR
707
    gen_clk(1);
708
      tdi_pad_i<=#1 'hz; // tri-state
709
    gen_clk(1);
710
    tms_pad_i<=#1 0;
711
    gen_clk(1);       // we are in RunTestIdle
712 2 mohor
  end
713
endtask
714
 
715
 
716 73 mohor
// Reads the CPU register and latches the data so it is ready for reading
717
task ReadCPURegister;
718 2 mohor
  input [31:0] Address;
719 80 mohor
  input [7:0] crc;
720 2 mohor
  integer i;
721
 
722
  begin
723 73 mohor
    $display("(%0t) Task ReadCPURegister", $time);
724 80 mohor
    tms_pad_i<=#1 1;
725
    gen_clk(1);
726
    tms_pad_i<=#1 0;
727
    gen_clk(2);  // we are in shiftDR
728 2 mohor
 
729
    for(i=0; i<32; i=i+1)
730
    begin
731 80 mohor
      tdi_pad_i<=#1 Address[i];  // Shifting address
732
      gen_clk(1);
733 2 mohor
    end
734
 
735 80 mohor
    tdi_pad_i<=#1 0;             // shifting RW bit = read
736
    gen_clk(1);
737 2 mohor
 
738
    for(i=0; i<32; i=i+1)
739
    begin
740 80 mohor
      tdi_pad_i<=#1 0;     // Shifting data. Data is not important in read cycle.
741
      gen_clk(1);
742 2 mohor
    end
743
 
744 80 mohor
//    for(i=0; i<`CRC_LEN -1; i=i+1)
745
    for(i=0; i<`CRC_LEN; i=i+1)      // crc is 9 bit long
746 2 mohor
    begin
747 80 mohor
      tdi_pad_i<=#1 crc[i];     // Shifting CRC.
748
      gen_clk(1);
749 2 mohor
    end
750
 
751 80 mohor
//    tdi_pad_i<=#1 crc[i];   // Shifting last bit of CRC.
752
    tdi_pad_i<=#1 1'b0;       // crc[i];   // Shifting last bit of CRC.
753
    tms_pad_i<=#1 1;        // going out of shiftIR
754
    gen_clk(1);
755
      tdi_pad_i<=#1 'hz;   // Tristate TDI.
756
    gen_clk(1);
757 2 mohor
 
758 80 mohor
    tms_pad_i<=#1 0;
759
    gen_clk(1);       // we are in RunTestIdle
760 2 mohor
  end
761
endtask
762
 
763
 
764 73 mohor
// Write the CPU register
765
task WriteCPURegister;
766 80 mohor
  input [31:0] data;
767 2 mohor
  input [31:0] Address;
768 80 mohor
  input [`CRC_LEN -1:0] crc;
769 2 mohor
  integer i;
770
 
771
  begin
772 73 mohor
    $display("(%0t) Task WriteCPURegister", $time);
773 80 mohor
    tms_pad_i<=#1 1;
774
    gen_clk(1);
775
    tms_pad_i<=#1 0;
776
    gen_clk(2);  // we are in shiftDR
777 2 mohor
 
778
    for(i=0; i<32; i=i+1)
779
    begin
780 80 mohor
      tdi_pad_i<=#1 Address[i];  // Shifting address
781
      gen_clk(1);
782 2 mohor
    end
783
 
784 80 mohor
    tdi_pad_i<=#1 1;             // shifting RW bit = write
785
    gen_clk(1);
786 2 mohor
 
787
    for(i=0; i<32; i=i+1)
788
    begin
789 80 mohor
      tdi_pad_i<=#1 data[i];     // Shifting data
790
      gen_clk(1);
791 2 mohor
    end
792
 
793 80 mohor
//    for(i=0; i<`CRC_LEN -1; i=i+1)
794
    for(i=0; i<`CRC_LEN; i=i+1)      // crc is 9 bit long
795 2 mohor
    begin
796 80 mohor
      tdi_pad_i<=#1 crc[i];     // Shifting CRC
797
      gen_clk(1);
798 2 mohor
    end
799
 
800 80 mohor
//    tdi_pad_i<=#1 crc[i];        // shifting last bit of CRC
801
    tdi_pad_i<=#1 1'b0;            // crc[i];        // shifting last bit of CRC
802
    tms_pad_i<=#1 1;        // going out of shiftIR
803
    gen_clk(1);
804
      tdi_pad_i<=#1 'hz;        // tristate TDI
805
    gen_clk(1);
806 2 mohor
 
807 80 mohor
    tms_pad_i<=#1 0;
808
    gen_clk(1);       // we are in RunTestIdle
809 2 mohor
 
810 80 mohor
    gen_clk(10);      // Generating few clock cycles needed for the write operation to accomplish
811 2 mohor
  end
812
endtask
813
 
814
 
815
// Reads the register and latches the data so it is ready for reading
816
task ReadRegister;
817
  input [4:0] Address;
818 80 mohor
  input [7:0] crc;
819 2 mohor
  integer i;
820
 
821
  begin
822 73 mohor
    $display("(%0t) Task ReadRegister", $time);
823 80 mohor
    tms_pad_i<=#1 1;
824
    gen_clk(1);
825
    tms_pad_i<=#1 0;
826
    gen_clk(2);  // we are in shiftDR
827 2 mohor
 
828
    for(i=0; i<5; i=i+1)
829
    begin
830 80 mohor
      tdi_pad_i<=#1 Address[i];  // Shifting address
831
      gen_clk(1);
832 2 mohor
    end
833
 
834 80 mohor
    tdi_pad_i<=#1 0;             // shifting RW bit = read
835
    gen_clk(1);
836 2 mohor
 
837
    for(i=0; i<32; i=i+1)
838
    begin
839 80 mohor
      tdi_pad_i<=#1 0;     // Shifting data. Data is not important in read cycle.
840
      gen_clk(1);
841 2 mohor
    end
842
 
843 80 mohor
//    for(i=0; i<`CRC_LEN -1; i=i+1)
844
    for(i=0; i<`CRC_LEN; i=i+1)      // crc is 9 bit long
845 2 mohor
    begin
846 80 mohor
      tdi_pad_i<=#1 crc[i];     // Shifting CRC. CRC is not important in read cycle.
847
      gen_clk(1);
848 2 mohor
    end
849
 
850 80 mohor
//    tdi_pad_i<=#1 crc[i];     // Shifting last bit of CRC.
851
    tdi_pad_i<=#1 1'b0;         // crc[i];     // Shifting last bit of CRC.
852
    tms_pad_i<=#1 1;        // going out of shiftIR
853
    gen_clk(1);
854
      tdi_pad_i<=#1 'hz;     // Tri state TDI
855
    gen_clk(1);
856
    tms_pad_i<=#1 0;
857
    gen_clk(1);       // we are in RunTestIdle
858 2 mohor
 
859 80 mohor
    gen_clk(10);      // Generating few clock cycles needed for the read operation to accomplish
860 2 mohor
  end
861
endtask
862
 
863
 
864
// Write the register
865
task WriteRegister;
866 80 mohor
  input [31:0] data;
867 2 mohor
  input [4:0] Address;
868 80 mohor
  input [`CRC_LEN -1:0] crc;
869 2 mohor
  integer i;
870
 
871
  begin
872 73 mohor
    $display("(%0t) Task WriteRegister", $time);
873 80 mohor
    tms_pad_i<=#1 1;
874
    gen_clk(1);
875
    tms_pad_i<=#1 0;
876
    gen_clk(2);  // we are in shiftDR
877 2 mohor
 
878
    for(i=0; i<5; i=i+1)
879
    begin
880 80 mohor
      tdi_pad_i<=#1 Address[i];  // Shifting address
881
      gen_clk(1);
882 2 mohor
    end
883
 
884 80 mohor
    tdi_pad_i<=#1 1;             // shifting RW bit = write
885
    gen_clk(1);
886 2 mohor
 
887
    for(i=0; i<32; i=i+1)
888
    begin
889 80 mohor
      tdi_pad_i<=#1 data[i];     // Shifting data
890
      gen_clk(1);
891 2 mohor
    end
892
 
893 80 mohor
//    for(i=0; i<`CRC_LEN -1; i=i+1)
894
    for(i=0; i<`CRC_LEN; i=i+1)      // crc is 9 bit long
895 2 mohor
    begin
896 80 mohor
      tdi_pad_i<=#1 crc[i];     // Shifting CRC
897
      gen_clk(1);
898 2 mohor
    end
899
 
900 80 mohor
//    tdi_pad_i<=#1 crc[i];   // Shifting last bit of CRC
901
    tdi_pad_i<=#1 1'b0;       // crc[i];   // Shifting last bit of CRC
902
    tms_pad_i<=#1 1;        // going out of shiftIR
903
    gen_clk(1);
904
      tdi_pad_i<=#1 'hz;   // Tri state TDI
905
    gen_clk(1);
906 2 mohor
 
907 80 mohor
    tms_pad_i<=#1 0;
908
    gen_clk(1);       // we are in RunTestIdle
909 5 mohor
 
910 80 mohor
    gen_clk(5);       // Extra clocks needed for operations to finish 
911 5 mohor
 
912 2 mohor
  end
913
endtask
914
 
915 80 mohor
/*
916 12 mohor
task EnableWishboneSlave;
917
begin
918 73 mohor
$display("(%0t) Task EnableWishboneSlave", $time);
919 12 mohor
while(1)
920
  begin
921 73 mohor
    @ (posedge Mclk);
922 12 mohor
    if(wb_stb_i & wb_cyc_i) // WB access
923
//    wait (wb_stb_i & wb_cyc_i) // WB access
924
      begin
925
        @ (posedge Mclk);
926
        @ (posedge Mclk);
927
        @ (posedge Mclk);
928
        #1 wb_ack_o = 1;
929
        if(~wb_we_i) // read
930
          wb_dat_o = 32'hbeefdead;
931 73 mohor
          wb_dat_o = {wb_adr_i[3:0],   wb_adr_i[7:4],   wb_adr_i[11:8],  wb_adr_i[15:12],
932
                      wb_adr_i[19:16], wb_adr_i[23:20], wb_adr_i[27:24], wb_adr_i[31:28]};
933 12 mohor
        if(wb_we_i & wb_stb_i & wb_cyc_i) // write
934 80 mohor
          $display("\nWISHBONE write data=%0h, Addr=%0h", wb_dat_i, wb_adr_i);
935 12 mohor
        if(~wb_we_i & wb_stb_i & wb_cyc_i) // read
936 80 mohor
          $display("\nWISHBONE read data=%0h, Addr=%0h", wb_dat_o, wb_adr_i);
937 12 mohor
      end
938
    @ (posedge Mclk);
939
    #1 wb_ack_o = 0;
940
    wb_dat_o = 32'h0;
941
  end
942 80 mohor
 
943 12 mohor
end
944
endtask
945 80 mohor
*/
946 2 mohor
 
947 12 mohor
 
948
 
949
 
950
 
951 2 mohor
/**********************************************************************************
952
*                                                                                 *
953
*   Printing the information to the screen                                        *
954
*                                                                                 *
955
**********************************************************************************/
956
 
957 80 mohor
always @ (posedge tck_pad_i)
958 2 mohor
begin
959 80 mohor
  if(dbg_tb.i_tap_top.update_ir)
960
    case(dbg_tb.i_tap_top.jtag_ir[`IR_LENGTH-1:0])
961
      `EXTEST         : $display("\tInstruction EXTEST entered");
962
      `SAMPLE_PRELOAD : $display("\tInstruction SAMPLE_PRELOAD entered");
963
      `IDCODE         : $display("\tInstruction IDCODE entered");
964
      `MBIST          : $display("\tInstruction MBIST entered");
965
      `DEBUG          : $display("\tInstruction DEBUG entered");
966
      `BYPASS         : $display("\tInstruction BYPASS entered");
967
                default           :     $display("\n\tInstruction not valid. Instruction BYPASS activated !!!");
968 2 mohor
    endcase
969
end
970
 
971
 
972
// Print selected chain
973 80 mohor
/*
974
always @ (posedge tck_pad_i)
975 2 mohor
begin
976 80 mohor
  if(dbg_tb.i_tap_top.chain_select & dbg_tb.i_dbg_top.update_dr_q)
977 38 mohor
    case(dbg_tb.i_dbg_top.Chain[`CHAIN_ID_LENGTH-1:0])
978 2 mohor
      `GLOBAL_BS_CHAIN      : $write("\nChain GLOBAL_BS_CHAIN");
979 73 mohor
      `CPU_DEBUG_CHAIN_0    : $write("\nChain CPU_DEBUG_CHAIN_0");
980
      `CPU_DEBUG_CHAIN_1    : $write("\nChain CPU_DEBUG_CHAIN_1");
981
      `CPU_DEBUG_CHAIN_2    : $write("\nChain CPU_DEBUG_CHAIN_2");
982
      `CPU_DEBUG_CHAIN_3    : $write("\nChain CPU_DEBUG_CHAIN_3");
983
      `CPU_TEST_CHAIN       : $write("\nChain CPU_TEST_CHAIN");
984 2 mohor
      `TRACE_TEST_CHAIN     : $write("\nChain TRACE_TEST_CHAIN");
985
      `REGISTER_SCAN_CHAIN  : $write("\nChain REGISTER_SCAN_CHAIN");
986 12 mohor
      `WISHBONE_SCAN_CHAIN  : $write("\nChain WISHBONE_SCAN_CHAIN");
987 2 mohor
    endcase
988
end
989 80 mohor
*/
990 2 mohor
 
991 73 mohor
// print CPU registers read/write
992 80 mohor
/*
993 2 mohor
always @ (posedge Mclk)
994
begin
995 73 mohor
  if(dbg_tb.i_dbg_top.CPUAccess0 & ~dbg_tb.i_dbg_top.CPUAccess_q & dbg_tb.i_dbg_top.RW)
996
    $write("\n\t\tWrite to CPU Register (addr=0x%h, data=0x%h)", dbg_tb.i_dbg_top.ADDR[31:0], dbg_tb.i_dbg_top.DataOut[31:0]);
997 11 mohor
  else
998 73 mohor
  if(dbg_tb.i_dbg_top.CPUAccess_q & ~dbg_tb.i_dbg_top.CPUAccess_q2 & ~dbg_tb.i_dbg_top.RW)
999
    $write("\n\t\tRead from CPU Register (addr=0x%h, data=0x%h)", dbg_tb.i_dbg_top.ADDR[31:0], dbg_tb.i_dbg_top.cpu_data_i[31:0]);
1000 2 mohor
end
1001 80 mohor
*/
1002 2 mohor
 
1003
// print registers read/write
1004 80 mohor
/*
1005 2 mohor
always @ (posedge Mclk)
1006
begin
1007 38 mohor
  if(dbg_tb.i_dbg_top.RegAccess_q & ~dbg_tb.i_dbg_top.RegAccess_q2)
1008 2 mohor
    begin
1009 38 mohor
      if(dbg_tb.i_dbg_top.RW)
1010
        $write("\n\t\tWrite to Register (addr=0x%h, data=0x%h)", dbg_tb.i_dbg_top.ADDR[4:0], dbg_tb.i_dbg_top.DataOut[31:0]);
1011 2 mohor
      else
1012 38 mohor
        $write("\n\t\tRead from Register (addr=0x%h, data=0x%h). This data will be shifted out on next read request.", dbg_tb.i_dbg_top.ADDR[4:0], dbg_tb.i_dbg_top.RegDataIn[31:0]);
1013 2 mohor
    end
1014
end
1015 80 mohor
*/
1016 2 mohor
 
1017
// print CRC error
1018 80 mohor
/*
1019 2 mohor
`ifdef TRACE_ENABLED
1020 80 mohor
  wire CRCErrorReport = ~(dbg_tb.i_dbg_top.CrcMatch & (dbg_tb.i_dbg_top.chain_select | dbg_tb.i_dbg_top.debug_select & register_scan_chain | dbg_tb.i_dbg_top.debug_select & (cpu_debug_scan_chain0 | cpu_debug_scan_chain1 | cpu_debug_scan_chain2 | cpu_debug_scan_chain3) | dbg_tb.i_dbg_top.debug_select & dbg_tb.i_dbg_top.TraceTestScanChain | dbg_tb.i_dbg_top.debug_select & wishbone_scan_chain));
1021 2 mohor
`else  // TRACE_ENABLED not enabled
1022 80 mohor
  wire CRCErrorReport = ~(dbg_tb.i_dbg_top.CrcMatch & (dbg_tb.i_tap_top.chain_select | dbg_tb.i_tap_top.debug_select & register_scan_chain | dbg_tb.i_tap_top.debug_select & (cpu_debug_scan_chain0 | cpu_debug_scan_chain1 | cpu_debug_scan_chain2 | cpu_debug_scan_chain3) | dbg_tb.i_tap_top.debug_select & wishbone_scan_chain));
1023 2 mohor
`endif
1024 80 mohor
*/
1025 2 mohor
 
1026 80 mohor
/*
1027
// print crc
1028 2 mohor
always @ (posedge P_TCK)
1029
begin
1030 80 mohor
  if(dbg_tb.i_tap_top.update_dr & ~dbg_tb.i_tap_top.idcode_select)
1031 2 mohor
    begin
1032 80 mohor
      if(dbg_tb.i_tap_top.chain_select)
1033
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.i_dbg_top.JTAG_DR_IN[11:4], dbg_tb.i_dbg_top.CalculatedCrcOut[`CRC_LEN -1:0]);
1034 2 mohor
      else
1035 80 mohor
      if(register_scan_chain & ~dbg_tb.i_tap_top.chain_select)
1036
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.i_dbg_top.JTAG_DR_IN[45:38], dbg_tb.i_dbg_top.CalculatedCrcOut[`CRC_LEN -1:0]);
1037 2 mohor
      else
1038 80 mohor
      if((cpu_debug_scan_chain0 | cpu_debug_scan_chain1 | cpu_debug_scan_chain2 | cpu_debug_scan_chain3) & ~dbg_tb.i_tap_top.chain_select)
1039
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.i_dbg_top.JTAG_DR_IN[72:65], dbg_tb.i_dbg_top.CalculatedCrcOut[`CRC_LEN -1:0]);
1040
      if(wishbone_scan_chain & ~dbg_tb.i_tap_top.chain_select)
1041
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.i_dbg_top.JTAG_DR_IN[72:65], dbg_tb.i_dbg_top.CalculatedCrcOut[`CRC_LEN -1:0]);
1042 2 mohor
 
1043
      if(CRCErrorReport)
1044
        begin
1045 38 mohor
          $write("\n\t\t\t\tCrc Error when receiving data (read or write) !!!  CrcIn should be: 0x%h\n", dbg_tb.i_dbg_top.CalculatedCrcIn);
1046 2 mohor
          #1000 $stop;
1047
        end
1048 73 mohor
      $display("\n");
1049 2 mohor
    end
1050
end
1051 80 mohor
*/
1052 2 mohor
 
1053
// Print shifted IDCode
1054 80 mohor
reg [31:0] tmp_data;
1055
always @ (posedge tck_pad_i)
1056 2 mohor
begin
1057 80 mohor
  if(dbg_tb.i_tap_top.idcode_select)
1058 2 mohor
    begin
1059 80 mohor
      if(dbg_tb.i_tap_top.shift_dr)
1060
        tmp_data[31:0]<=#1 {dbg_tb.tdo, tmp_data[31:1]};
1061 2 mohor
      else
1062 80 mohor
      if(dbg_tb.i_tap_top.update_dr)
1063
        if (tmp_data[31:0] != `IDCODE_VALUE)
1064 73 mohor
          begin
1065
            $display("(%0t) ERROR: IDCODE not correct", $time);
1066
            $stop;
1067
          end
1068
        else
1069 80 mohor
          $display("\t\tIDCode = 0x%h", tmp_data[31:0]);
1070 2 mohor
    end
1071
end
1072
 
1073
 
1074 80 mohor
// We never use following states: exit2_ir,  exit2_dr,  pause_ir or pause_dr
1075
always @ (posedge tck_pad_i)
1076 2 mohor
begin
1077 80 mohor
  if(dbg_tb.i_tap_top.pause_ir | dbg_tb.i_tap_top.exit2_ir)
1078 2 mohor
    begin
1079 80 mohor
      $display("\n(%0t) ERROR: State pause_ir or exit2_ir detected.", $time);
1080
      $display("(%0t) Simulation stopped !!!", $time);
1081
      $stop;
1082 2 mohor
    end
1083
end
1084
 
1085
 
1086 80 mohor
// sets the selected scan chain and goes to the RunTestIdle state
1087
task xxx;
1088
  input [3:0]  data;
1089
  input [31:0] crc;
1090
  integer i;
1091
 
1092
  begin
1093
    $display("(%0t) Task xxx", $time);
1094
    tms_pad_i<=#1 1;
1095
    gen_clk(1);
1096
    tms_pad_i<=#1 0;
1097
    gen_clk(2);  // we are in shiftDR
1098
 
1099
    for(i=0; i<4; i=i+1)
1100 73 mohor
    begin
1101 80 mohor
      tdi_pad_i<=#1 data[i];
1102
      gen_clk(1);
1103 73 mohor
    end
1104
 
1105 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
1106
    begin
1107
      tdi_pad_i<=#1 crc[`CRC_LEN - 1 - i];
1108
      gen_clk(1);
1109
    end
1110 73 mohor
 
1111 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
1112 73 mohor
 
1113
 
1114 80 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)
1115
    begin
1116
      tdi_pad_i<=#1 1'b0;
1117
      gen_clk(1);
1118
    end
1119 73 mohor
 
1120 80 mohor
    tdi_pad_i<=#1 crc[i]; // last crc
1121
    tms_pad_i<=#1 1;
1122
    gen_clk(1);         // to exit1_dr
1123 73 mohor
 
1124 80 mohor
    tdi_pad_i<=#1 'hz;  // tri-state
1125
    tms_pad_i<=#1 1;
1126
    gen_clk(1);         // to update_dr
1127
    tms_pad_i<=#1 0;
1128
    gen_clk(1);         // to run_test_idle
1129
  end
1130
endtask
1131 2 mohor
 
1132
 
1133 80 mohor
 
1134
 
1135
 
1136
endmodule // dbg_tb
1137
 
1138
 

powered by: WebSVN 2.1.0

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