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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_3/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 11

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
////  http://www.opencores.org/cores/DebugInterface/              ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is avaliable in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000,2001 Authors                              ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
49
// Working version. Few bugs fixed, comments added.
50
//
51 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
52
// Minor changes for simulation.
53
//
54 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
55
// Trace fixed. Some registers changed, trace simplified.
56
//
57 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
58
// Initial official release.
59
//
60 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
61
// This is a backup. It is not a fully working version. Not for use, yet.
62
//
63
// Revision 1.2  2001/05/18 13:10:05  mohor
64
// Headers changed. All additional information is now avaliable in the README.txt file.
65
//
66
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
67
// Initial release
68
//
69
//
70
 
71
 
72
`include "dbg_timescale.v"
73
`include "dbg_defines.v"
74
`include "dbg_tb_defines.v"
75
 
76
// Test bench
77
module dbg_tb;
78
 
79
parameter Tp = 1;
80
parameter Tclk = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
81
 
82
 
83
reg  P_TMS, P_TCK;
84
reg  P_TRST, P_TDI;
85 9 mohor
reg  wb_rst_i;
86 2 mohor
reg  Mclk;
87
 
88
reg [10:0] Wp;
89
reg Bp;
90
reg [3:0] LsStatus;
91
reg [1:0] IStatus;
92 5 mohor
reg BS_CHAIN_I;
93 2 mohor
 
94
wire P_TDO;
95
wire [31:0] ADDR_RISC;
96
wire [31:0] DATAIN_RISC;     // DATAIN_RISC is connect to DATAOUT
97
 
98
wire  [31:0] DATAOUT_RISC;   // DATAOUT_RISC is connect to DATAIN
99
 
100
wire   [`OPSELECTWIDTH-1:0] OpSelect;
101
 
102
// Connecting TAP module
103 9 mohor
dbg_top dbgTAP1(.tms_pad_i(P_TMS), .tck_pad_i(P_TCK), .trst_pad_i(P_TRST), .tdi_pad_i(P_TDI),
104 11 mohor
                .tdo_pad_o(P_TDO), .wb_rst_i(wb_rst_i), .risc_clk_i(Mclk),
105 9 mohor
                .risc_addr_o(ADDR_RISC), .risc_data_i(DATAOUT_RISC), .risc_data_o(DATAIN_RISC),
106 11 mohor
                .wp_i(Wp), .bp_i(Bp),
107 9 mohor
                .opselect_o(OpSelect), .lsstatus_i(LsStatus), .istatus_i(IStatus),
108 11 mohor
                .risc_stall_o(), .reset_o()
109 2 mohor
                );
110
 
111
 
112
reg TestEnabled;
113
 
114
 
115
 
116
initial
117
begin
118
  TestEnabled<=#Tp 0;
119
  P_TMS<=#Tp 0;
120
  P_TCK<=#Tp 0;
121
  P_TDI<=#Tp 0;
122
 
123
  Wp<=#Tp 0;
124
  Bp<=#Tp 0;
125
  LsStatus<=#Tp 0;
126
  IStatus<=#Tp 0;
127
 
128 9 mohor
  wb_rst_i<=#Tp 0;
129
  P_TRST<=#Tp 1;
130
  #100 wb_rst_i<=#Tp 1;
131
  P_TRST<=#Tp 0;
132
  #100 wb_rst_i<=#Tp 0;
133
  P_TRST<=#Tp 1;
134 2 mohor
  #Tp TestEnabled<=#Tp 1;
135
end
136
 
137
 
138
// Generating master clock (RISC clock) 200 MHz
139
initial
140
begin
141
  Mclk<=#Tp 0;
142
  #1 forever #`RISC_CLOCK Mclk<=~Mclk;
143
end
144
 
145
 
146
// Generating random number for use in DATAOUT_RISC[31:0]
147
reg [31:0] RandNumb;
148 9 mohor
always @ (posedge Mclk or posedge wb_rst_i)
149 2 mohor
begin
150 9 mohor
  if(wb_rst_i)
151 2 mohor
    RandNumb[31:0]<=#Tp 0;
152
  else
153
    RandNumb[31:0]<=#Tp RandNumb[31:0] + 1;
154
end
155
 
156
 
157
assign DATAOUT_RISC[31:0] = RandNumb[31:0];
158
 
159
 
160
 
161
always @ (posedge TestEnabled)
162
begin
163
  ResetTAP;
164
  GotoRunTestIdle;
165
 
166
// Testing read and write to RISC registers
167
  SetInstruction(`CHAIN_SELECT);
168
  ChainSelect(`RISC_DEBUG_CHAIN, 8'h38);  // {chain, crc}
169
  SetInstruction(`DEBUG);
170
  ReadRISCRegister(32'h12345ead, 8'hbf);                 // {addr, crc}
171
  WriteRISCRegister(32'h11223344, 32'h12345678, 8'haf);  // {data, addr, crc}
172
//
173
 
174
 
175
 
176
// Testing read and write to internal registers
177
  SetInstruction(`IDCODE);
178
  ReadIDCode;
179
 
180
  SetInstruction(`CHAIN_SELECT);
181
  ChainSelect(`REGISTER_SCAN_CHAIN, 8'h0e);  // {chain, crc}
182
  SetInstruction(`DEBUG);
183
 
184 5 mohor
 
185 9 mohor
//
186 5 mohor
//  Testing internal registers
187 2 mohor
    ReadRegister(`MODER_ADR, 8'h00);           // {addr, crc}
188
    ReadRegister(`TSEL_ADR, 8'h64);            // {addr, crc}
189
    ReadRegister(`QSEL_ADR, 8'h32);            // {addr, crc}
190
    ReadRegister(`SSEL_ADR, 8'h56);            // {addr, crc}
191 5 mohor
    ReadRegister(`RECSEL_ADR, 8'hc4);          // {addr, crc}
192 2 mohor
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
193
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
194
 
195
    WriteRegister(32'h00000001, `MODER_ADR,   8'h53); // {data, addr, crc}
196
    WriteRegister(32'h00000020, `TSEL_ADR,    8'h5e); // {data, addr, crc}
197
    WriteRegister(32'h00000300, `QSEL_ADR,    8'hdd); // {data, addr, crc}
198
    WriteRegister(32'h00004000, `SSEL_ADR,    8'he2); // {data, addr, crc}
199 5 mohor
    WriteRegister(32'h0000dead, `RECSEL_ADR,  8'hfb); // {data, addr, crc}
200 2 mohor
 
201
    ReadRegister(`MODER_ADR, 8'h00);           // {addr, crc}
202
    ReadRegister(`TSEL_ADR, 8'h64);            // {addr, crc}
203
    ReadRegister(`QSEL_ADR, 8'h32);            // {addr, crc}
204
    ReadRegister(`SSEL_ADR, 8'h56);            // {addr, crc}
205 5 mohor
    ReadRegister(`RECSEL_ADR, 8'hc4);          // {addr, crc}
206 2 mohor
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
207
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
208 9 mohor
//
209 2 mohor
 
210
 
211
// testing trigger and qualifier
212
`ifdef TRACE_ENABLED
213
 
214
 
215
 
216
 
217
 
218 6 mohor
// Anything starts trigger and qualifier
219 5 mohor
    #1000 WriteRegister(32'h00000000, `QSEL_ADR,   8'h50);    // Any qualifier
220
    #1000 WriteRegister(32'h00000000, `TSEL_ADR,   8'h06);    // Any trigger
221
    #1000 WriteRegister(32'h00000003, `RECSEL_ADR,   8'h0c);  // Two samples are selected for recording (RECPC and RECLSEA)
222
    #100  WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
223
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
224 6 mohor
// End: Anything starts trigger and qualifier //
225 2 mohor
 
226
 
227 6 mohor
/* Anything starts trigger, breakpoint starts qualifier
228 9 mohor
// Uncomment this part when you want to test it.
229 5 mohor
    #1000 WriteRegister(`QUALIFOP_OR | `BPQUALIFVALID | `BPQUALIF, `QSEL_ADR,   8'had);    // Any qualifier
230
    #1000 WriteRegister(32'h00000000, `TSEL_ADR,   8'h06);    // Any trigger
231 6 mohor
    #1000 WriteRegister(32'h0000000c, `RECSEL_ADR,   8'h0f);  // Two samples are selected for recording (RECSDATA and RECLDATA)
232 5 mohor
    #1000 WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
233
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
234
    wait(dbg_tb.dbgTAP1.TraceEnable)
235
    @ (posedge Mclk);
236
      #1 Bp = 1;                                                 // Set breakpoint
237
    repeat(8) @(posedge Mclk);
238
    wait(dbg_tb.dbgTAP1.dbgTrace1.RiscStall)
239
      #1 Bp = 0;                                                 // Clear breakpoint
240 6 mohor
// End: Anything starts trigger, breakpoint starts qualifier */
241 2 mohor
 
242
 
243 5 mohor
/* Anything starts qualifier, breakpoint starts trigger
244 9 mohor
// Uncomment this part when you want to test it.
245 5 mohor
    #1000 WriteRegister(32'h00000000, `QSEL_ADR,   8'h50);    // Any qualifier
246
    #1000 WriteRegister(`LSSTRIG_0 | `LSSTRIG_2 | `LSSTRIGVALID | `WPTRIG_4 | `WPTRIGVALID | `TRIGOP_AND, `TSEL_ADR,   8'had);    // Trigger is AND of Watchpoint4 and LSSTRIG[0] and LSSTRIG[2]
247
    #1000 WriteRegister(32'h00000003, `RECSEL_ADR,   8'h0c);  // Two samples are selected for recording (RECPC and RECLSEA)
248
    #1000 WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
249
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
250
    wait(dbg_tb.dbgTAP1.TraceEnable)
251
    @ (posedge Mclk)
252
      Wp[4] = 1;                                              // Set watchpoint[4]
253
      LsStatus = 4'h5;                                        // LsStatus[0] and LsStatus[2] are active
254
    @ (posedge Mclk)
255
      Wp[4] = 0;                                              // Clear watchpoint[4]
256
      LsStatus = 4'h0;                                        // LsStatus[0] and LsStatus[2] are cleared
257
// End: Anything starts trigger and qualifier */
258 2 mohor
 
259
 
260 5 mohor
 
261
 
262
 
263
 
264 9 mohor
// Reading data from the trace buffer
265 2 mohor
  SetInstruction(`CHAIN_SELECT);
266
  ChainSelect(`TRACE_TEST_CHAIN, 8'h24);  // {chain, crc}
267
  SetInstruction(`DEBUG);
268
  ReadTraceBuffer;
269
  ReadTraceBuffer;
270
  ReadTraceBuffer;
271
  ReadTraceBuffer;
272
  ReadTraceBuffer;
273
  ReadTraceBuffer;
274
  ReadTraceBuffer;
275
  ReadTraceBuffer;
276
  ReadTraceBuffer;
277
  ReadTraceBuffer;
278
  ReadTraceBuffer;
279
  ReadTraceBuffer;
280
 
281
 
282
`endif  // TRACE_ENABLED
283
 
284
 
285
 
286
 
287
  #5000 GenClk(1);            // One extra TCLK for debugging purposes
288 5 mohor
  #1000 $stop;
289 2 mohor
 
290
end
291
 
292
 
293
 
294
// Generation of the TCLK signal
295
task GenClk;
296
  input [7:0] Number;
297
  integer i;
298
  begin
299
    for(i=0; i<Number; i=i+1)
300
      begin
301
        #Tclk P_TCK<=1;
302
        #Tclk P_TCK<=0;
303
      end
304
  end
305
endtask
306
 
307
 
308
// TAP reset
309
task ResetTAP;
310
  begin
311
    P_TMS<=#Tp 1;
312
    GenClk(7);
313
  end
314
endtask
315
 
316
 
317
// Goes to RunTestIdle state
318
task GotoRunTestIdle;
319
  begin
320
    P_TMS<=#Tp 0;
321
    GenClk(1);
322
  end
323
endtask
324
 
325
 
326
// sets the instruction to the IR register and goes to the RunTestIdle state
327
task SetInstruction;
328
  input [3:0] Instr;
329
  integer i;
330
 
331
  begin
332
    P_TMS<=#Tp 1;
333
    GenClk(2);
334
    P_TMS<=#Tp 0;
335
    GenClk(2);  // we are in shiftIR
336
 
337
    for(i=0; i<`IR_LENGTH-1; i=i+1)
338
    begin
339
      P_TDI<=#Tp Instr[i];
340
      GenClk(1);
341
    end
342
 
343
    P_TDI<=#Tp Instr[i]; // last shift
344
    P_TMS<=#Tp 1;        // going out of shiftIR
345
    GenClk(1);
346
      P_TDI<=#Tp 'hz;    // tri-state
347
    GenClk(1);
348
    P_TMS<=#Tp 0;
349
    GenClk(1);       // we are in RunTestIdle
350
  end
351
endtask
352
 
353
 
354
// sets the selected scan chain and goes to the RunTestIdle state
355
task ChainSelect;
356
  input [3:0] Data;
357
  input [7:0] Crc;
358
  integer i;
359
 
360
  begin
361
    P_TMS<=#Tp 1;
362
    GenClk(1);
363
    P_TMS<=#Tp 0;
364
    GenClk(2);  // we are in shiftDR
365
 
366
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
367
    begin
368
      P_TDI<=#Tp Data[i];
369
      GenClk(1);
370
    end
371
 
372
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
373
    begin
374
      P_TDI<=#Tp Crc[i];
375
      GenClk(1);
376
    end
377
 
378
    P_TDI<=#Tp Crc[i]; // last shift
379
    P_TMS<=#Tp 1;        // going out of shiftIR
380
    GenClk(1);
381
      P_TDI<=#Tp 'hz; // tri-state
382
    GenClk(1);
383
    P_TMS<=#Tp 0;
384
    GenClk(1);       // we are in RunTestIdle
385
  end
386
endtask
387
 
388
 
389
// Reads the ID code
390
task ReadIDCode;
391
  begin
392
    P_TMS<=#Tp 1;
393
    GenClk(1);
394
    P_TMS<=#Tp 0;
395
    GenClk(2);  // we are in shiftDR
396
 
397
    P_TDI<=#Tp 0;
398
    GenClk(31);
399
    P_TMS<=#Tp 1;        // going out of shiftIR
400
    GenClk(1);
401
      P_TDI<=#Tp 'hz; // tri-state
402
    GenClk(1);
403
    P_TMS<=#Tp 0;
404
    GenClk(1);       // we are in RunTestIdle
405
  end
406
endtask
407
 
408
 
409
// Reads sample from the Trace Buffer
410
task ReadTraceBuffer;
411
  begin
412
    P_TMS<=#Tp 1;
413
    GenClk(1);
414
    P_TMS<=#Tp 0;
415
    GenClk(2);  // we are in shiftDR
416
 
417
    P_TDI<=#Tp 0;
418
    GenClk(47);
419
    P_TMS<=#Tp 1;        // going out of shiftIR
420
    GenClk(1);
421
      P_TDI<=#Tp 'hz; // tri-state
422
    GenClk(1);
423
    P_TMS<=#Tp 0;
424
    GenClk(1);       // we are in RunTestIdle
425
  end
426
endtask
427
 
428
 
429
// Reads the RISC register and latches the data so it is ready for reading
430
task ReadRISCRegister;
431
  input [31:0] Address;
432
  input [7:0] Crc;
433
  integer i;
434
 
435
  begin
436
    P_TMS<=#Tp 1;
437
    GenClk(1);
438
    P_TMS<=#Tp 0;
439
    GenClk(2);  // we are in shiftDR
440
 
441
    for(i=0; i<32; i=i+1)
442
    begin
443
      P_TDI<=#Tp Address[i];  // Shifting address
444
      GenClk(1);
445
    end
446
 
447
    P_TDI<=#Tp 0;             // shifting RW bit = read
448
    GenClk(1);
449
 
450
    for(i=0; i<32; i=i+1)
451
    begin
452
      P_TDI<=#Tp 0;     // Shifting data. Data is not important in read cycle.
453
      GenClk(1);
454
    end
455
 
456
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
457
    begin
458
      P_TDI<=#Tp Crc[i];     // Shifting CRC.
459
      GenClk(1);
460
    end
461
 
462
    P_TDI<=#Tp Crc[i];   // Shifting last bit of CRC.
463
    P_TMS<=#Tp 1;        // going out of shiftIR
464
    GenClk(1);
465
      P_TDI<=#Tp 'hz;   // Tristate TDI.
466
    GenClk(1);
467
 
468
    P_TMS<=#Tp 0;
469
    GenClk(1);       // we are in RunTestIdle
470
  end
471
endtask
472
 
473
 
474
// Write the RISC register
475
task WriteRISCRegister;
476
  input [31:0] Data;
477
  input [31:0] Address;
478
  input [`CRC_LENGTH-1:0] Crc;
479
  integer i;
480
 
481
  begin
482
    P_TMS<=#Tp 1;
483
    GenClk(1);
484
    P_TMS<=#Tp 0;
485
    GenClk(2);  // we are in shiftDR
486
 
487
    for(i=0; i<32; i=i+1)
488
    begin
489
      P_TDI<=#Tp Address[i];  // Shifting address
490
      GenClk(1);
491
    end
492
 
493
    P_TDI<=#Tp 1;             // shifting RW bit = write
494
    GenClk(1);
495
 
496
    for(i=0; i<32; i=i+1)
497
    begin
498
      P_TDI<=#Tp Data[i];     // Shifting data
499
      GenClk(1);
500
    end
501
 
502
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
503
    begin
504
      P_TDI<=#Tp Crc[i];     // Shifting CRC
505
      GenClk(1);
506
    end
507
 
508
    P_TDI<=#Tp Crc[i];        // shifting last bit of CRC
509
    P_TMS<=#Tp 1;        // going out of shiftIR
510
    GenClk(1);
511
      P_TDI<=#Tp 'hz;        // tristate TDI
512
    GenClk(1);
513
 
514
    P_TMS<=#Tp 0;
515
    GenClk(1);       // we are in RunTestIdle
516
 
517
    GenClk(10);      // Generating few clock cycles needed for the write operation to accomplish
518
  end
519
endtask
520
 
521
 
522
// Reads the register and latches the data so it is ready for reading
523
task ReadRegister;
524
  input [4:0] Address;
525
  input [7:0] Crc;
526
  integer i;
527
 
528
  begin
529
    P_TMS<=#Tp 1;
530
    GenClk(1);
531
    P_TMS<=#Tp 0;
532
    GenClk(2);  // we are in shiftDR
533
 
534
    for(i=0; i<5; i=i+1)
535
    begin
536
      P_TDI<=#Tp Address[i];  // Shifting address
537
      GenClk(1);
538
    end
539
 
540
    P_TDI<=#Tp 0;             // shifting RW bit = read
541
    GenClk(1);
542
 
543
    for(i=0; i<32; i=i+1)
544
    begin
545
      P_TDI<=#Tp 0;     // Shifting data. Data is not important in read cycle.
546
      GenClk(1);
547
    end
548
 
549
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
550
    begin
551
      P_TDI<=#Tp Crc[i];     // Shifting CRC. CRC is not important in read cycle.
552
      GenClk(1);
553
    end
554
 
555
    P_TDI<=#Tp Crc[i];     // Shifting last bit of CRC.
556
    P_TMS<=#Tp 1;        // going out of shiftIR
557
    GenClk(1);
558
      P_TDI<=#Tp 'hz;     // Tri state TDI
559
    GenClk(1);
560
    P_TMS<=#Tp 0;
561
    GenClk(1);       // we are in RunTestIdle
562
 
563
    GenClk(10);      // Generating few clock cycles needed for the read operation to accomplish
564
  end
565
endtask
566
 
567
 
568
// Write the register
569
task WriteRegister;
570
  input [31:0] Data;
571
  input [4:0] Address;
572
  input [`CRC_LENGTH-1:0] Crc;
573
  integer i;
574
 
575
  begin
576
    P_TMS<=#Tp 1;
577
    GenClk(1);
578
    P_TMS<=#Tp 0;
579
    GenClk(2);  // we are in shiftDR
580
 
581
    for(i=0; i<5; i=i+1)
582
    begin
583
      P_TDI<=#Tp Address[i];  // Shifting address
584
      GenClk(1);
585
    end
586
 
587
    P_TDI<=#Tp 1;             // shifting RW bit = write
588
    GenClk(1);
589
 
590
    for(i=0; i<32; i=i+1)
591
    begin
592
      P_TDI<=#Tp Data[i];     // Shifting data
593
      GenClk(1);
594
    end
595
 
596
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
597
    begin
598
      P_TDI<=#Tp Crc[i];     // Shifting CRC
599
      GenClk(1);
600
    end
601
 
602
    P_TDI<=#Tp Crc[i];   // Shifting last bit of CRC
603
    P_TMS<=#Tp 1;        // going out of shiftIR
604
    GenClk(1);
605
      P_TDI<=#Tp 'hz;   // Tri state TDI
606
    GenClk(1);
607
 
608
    P_TMS<=#Tp 0;
609
    GenClk(1);       // we are in RunTestIdle
610 5 mohor
 
611 9 mohor
    GenClk(5);       // Extra clocks needed for operations to finish 
612 5 mohor
 
613 2 mohor
  end
614
endtask
615
 
616
 
617
 
618
/**********************************************************************************
619
*                                                                                 *
620
*   Printing the information to the screen                                        *
621
*                                                                                 *
622
**********************************************************************************/
623
 
624
// Print samples that are recorded to the trace buffer
625
`ifdef TRACE_ENABLED
626
always @ (posedge Mclk)
627
begin
628
  if(dbg_tb.dbgTAP1.dbgTrace1.WriteSample)
629 5 mohor
    $write("\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWritten to Trace buffer: WritePointer=0x%x, Data=0x%x", dbg_tb.dbgTAP1.dbgTrace1.WritePointer, {dbg_tb.dbgTAP1.dbgTrace1.DataIn, 1'b0, dbg_tb.dbgTAP1.dbgTrace1.OpSelect[`OPSELECTWIDTH-1:0]});
630 2 mohor
end
631
`endif
632
 
633
 
634
// Print selected instruction
635
reg UpdateIR_q;
636
always @ (posedge P_TCK)
637
begin
638
  UpdateIR_q<=#Tp dbg_tb.dbgTAP1.UpdateIR;
639
end
640
 
641
always @ (posedge P_TCK)
642
begin
643
  if(UpdateIR_q)
644
    case(dbg_tb.dbgTAP1.JTAG_IR[`IR_LENGTH-1:0])
645
      `EXTEST         : $write("\n\tInstruction EXTEST");
646
      `SAMPLE_PRELOAD : $write("\n\tInstruction SAMPLE_PRELOAD");
647
      `IDCODE         : $write("\n\tInstruction IDCODE");
648
      `CHAIN_SELECT   : $write("\n\tInstruction CHAIN_SELECT");
649
      `INTEST         : $write("\n\tInstruction INTEST");
650
      `CLAMP          : $write("\n\tInstruction CLAMP");
651
      `CLAMPZ         : $write("\n\tInstruction CLAMPZ");
652
      `HIGHZ          : $write("\n\tInstruction HIGHZ");
653
      `DEBUG          : $write("\n\tInstruction DEBUG");
654
      `BYPASS         : $write("\n\tInstruction BYPASS");
655
                default           :     $write("\n\tInstruction not valid. Instruction BYPASS activated !!!");
656
    endcase
657
end
658
 
659
 
660
 
661
// Print selected chain
662
always @ (posedge P_TCK)
663
begin
664
  if(dbg_tb.dbgTAP1.CHAIN_SELECTSelected & dbg_tb.dbgTAP1.UpdateDR_q)
665
    case(dbg_tb.dbgTAP1.Chain[`CHAIN_ID_LENGTH-1:0])
666
      `GLOBAL_BS_CHAIN      : $write("\nChain GLOBAL_BS_CHAIN");
667
      `RISC_DEBUG_CHAIN     : $write("\nChain RISC_DEBUG_CHAIN");
668
      `RISC_TEST_CHAIN      : $write("\nChain RISC_TEST_CHAIN");
669
      `TRACE_TEST_CHAIN     : $write("\nChain TRACE_TEST_CHAIN");
670
      `REGISTER_SCAN_CHAIN  : $write("\nChain REGISTER_SCAN_CHAIN");
671
    endcase
672
end
673
 
674
 
675
// print RISC registers read/write
676
always @ (posedge Mclk)
677
begin
678 11 mohor
  if(dbg_tb.dbgTAP1.RISCAccess & ~dbg_tb.dbgTAP1.RISCAccess_q & dbg_tb.dbgTAP1.RW)
679
    $write("\n\t\tWrite to RISC Register (addr=0x%h, data=0x%h)", dbg_tb.dbgTAP1.ADDR[31:0], dbg_tb.dbgTAP1.DataOut[31:0]);
680
  else
681
  if(dbg_tb.dbgTAP1.RISCAccess_q & ~dbg_tb.dbgTAP1.RISCAccess_q2 & ~dbg_tb.dbgTAP1.RW)
682
    $write("\n\t\tRead from RISC Register (addr=0x%h, data=0x%h)", dbg_tb.dbgTAP1.ADDR[31:0], dbg_tb.dbgTAP1.risc_data_i[31:0]);
683 2 mohor
end
684
 
685
 
686
// print registers read/write
687
always @ (posedge Mclk)
688
begin
689
  if(dbg_tb.dbgTAP1.RegAccess_q & ~dbg_tb.dbgTAP1.RegAccess_q2)
690
    begin
691
      if(dbg_tb.dbgTAP1.RW)
692
        $write("\n\t\tWrite to Register (addr=0x%h, data=0x%h)", dbg_tb.dbgTAP1.ADDR[4:0], dbg_tb.dbgTAP1.DataOut[31:0]);
693
      else
694 9 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.dbgTAP1.ADDR[4:0], dbg_tb.dbgTAP1.RegDataIn[31:0]);
695 2 mohor
    end
696
end
697
 
698
 
699
// print CRC error
700
`ifdef TRACE_ENABLED
701
  wire CRCErrorReport = ~(dbg_tb.dbgTAP1.CrcMatch & (dbg_tb.dbgTAP1.CHAIN_SELECTSelected | dbg_tb.dbgTAP1.DEBUGSelected & dbg_tb.dbgTAP1.RegisterScanChain | dbg_tb.dbgTAP1.DEBUGSelected & dbg_tb.dbgTAP1.RiscDebugScanChain | dbg_tb.dbgTAP1.DEBUGSelected & dbg_tb.dbgTAP1.TraceTestScanChain));
702
`else  // TRACE_ENABLED not enabled
703
  wire CRCErrorReport = ~(dbg_tb.dbgTAP1.CrcMatch & (dbg_tb.dbgTAP1.CHAIN_SELECTSelected | dbg_tb.dbgTAP1.DEBUGSelected & dbg_tb.dbgTAP1.RegisterScanChain | dbg_tb.dbgTAP1.DEBUGSelected & dbg_tb.dbgTAP1.RiscDebugScanChain));
704
`endif
705
 
706
always @ (posedge P_TCK)
707
begin
708
  if(dbg_tb.dbgTAP1.UpdateDR & ~dbg_tb.dbgTAP1.IDCODESelected)
709
    begin
710
      if(dbg_tb.dbgTAP1.CHAIN_SELECTSelected)
711
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.dbgTAP1.JTAG_DR_IN[11:4], dbg_tb.dbgTAP1.CalculatedCrcOut[`CRC_LENGTH-1:0]);
712
      else
713
      if(dbg_tb.dbgTAP1.RegisterScanChain & ~dbg_tb.dbgTAP1.CHAIN_SELECTSelected)
714
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.dbgTAP1.JTAG_DR_IN[45:38], dbg_tb.dbgTAP1.CalculatedCrcOut[`CRC_LENGTH-1:0]);
715
      else
716
      if(dbg_tb.dbgTAP1.RiscDebugScanChain & ~dbg_tb.dbgTAP1.CHAIN_SELECTSelected)
717
        $write("\t\tCrcIn=0x%h, CrcOut=0x%h", dbg_tb.dbgTAP1.JTAG_DR_IN[72:65], dbg_tb.dbgTAP1.CalculatedCrcOut[`CRC_LENGTH-1:0]);
718
 
719
      if(CRCErrorReport)
720
        begin
721 5 mohor
          $write("\n\t\t\t\tCrc Error when receiving data (read or write) !!!  CrcIn should be: 0x%h\n", dbg_tb.dbgTAP1.CalculatedCrcIn);
722 2 mohor
          #1000 $stop;
723
        end
724
    end
725
end
726
 
727
 
728
// Print shifted IDCode
729
reg [31:0] TempData;
730
always @ (posedge P_TCK)
731
begin
732
  if(dbg_tb.dbgTAP1.IDCODESelected)
733
    begin
734
      if(dbg_tb.dbgTAP1.ShiftDR)
735
        TempData[31:0]<=#Tp {dbg_tb.dbgTAP1.TDOData, TempData[31:1]};
736
      else
737
      if(dbg_tb.dbgTAP1.UpdateDR)
738
        $write("\n\t\tIDCode = 0x%h", TempData[31:0]);
739
    end
740
end
741
 
742
 
743
// Print data from the trace buffer
744
reg [47:0] TraceData;
745
always @ (posedge P_TCK)
746
begin
747
  if(dbg_tb.dbgTAP1.DEBUGSelected & (dbg_tb.dbgTAP1.Chain==`TRACE_TEST_CHAIN))
748
    begin
749
      if(dbg_tb.dbgTAP1.ShiftDR)
750
        TraceData[47:0]<=#Tp {dbg_tb.dbgTAP1.TDOData, TraceData[47:1]};
751
      else
752
      if(dbg_tb.dbgTAP1.UpdateDR)
753
        $write("\n\t\TraceData = 0x%h + Crc = 0x%h", TraceData[39:0], TraceData[47:40]);
754
    end
755
end
756
 
757
 
758
endmodule // TB
759
 
760
 

powered by: WebSVN 2.1.0

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