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 80

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

powered by: WebSVN 2.1.0

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