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 6

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 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
49
// Trace fixed. Some registers changed, trace simplified.
50
//
51 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
52
// Initial official release.
53
//
54 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
55
// This is a backup. It is not a fully working version. Not for use, yet.
56
//
57
// Revision 1.2  2001/05/18 13:10:05  mohor
58
// Headers changed. All additional information is now avaliable in the README.txt file.
59
//
60
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
61
// Initial release
62
//
63
//
64
 
65
 
66
`include "dbg_timescale.v"
67
`include "dbg_defines.v"
68
`include "dbg_tb_defines.v"
69
 
70
// Test bench
71
module dbg_tb;
72
 
73
parameter Tp = 1;
74
parameter Tclk = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
75
 
76
 
77
reg  P_TMS, P_TCK;
78
reg  P_TRST, P_TDI;
79
reg  P_PowerONReset;
80
reg  Mclk;
81
 
82
reg [10:0] Wp;
83
reg Bp;
84
reg [3:0] LsStatus;
85
reg [1:0] IStatus;
86 5 mohor
reg BS_CHAIN_I;
87 2 mohor
 
88
wire P_TDO;
89
wire [31:0] ADDR_RISC;
90
wire [31:0] DATAIN_RISC;     // DATAIN_RISC is connect to DATAOUT
91
wire RISC_CS;
92
wire RISC_RW;
93 5 mohor
wire RISC_STALL_O;
94
wire RISC_RESET_O;
95 2 mohor
 
96
wire  [31:0] DATAOUT_RISC;   // DATAOUT_RISC is connect to DATAIN
97
 
98
wire   [`OPSELECTWIDTH-1:0] OpSelect;
99
 
100
// Connecting TAP module
101
dbg_top dbgTAP1(.P_TMS(P_TMS), .P_TCK(P_TCK), .P_TRST(P_TRST), .P_TDI(P_TDI),
102
                .P_TDO(P_TDO), .P_PowerONReset(P_PowerONReset), .Mclk(Mclk),
103
                .RISC_ADDR(ADDR_RISC), .RISC_DATA_IN(DATAOUT_RISC), .RISC_DATA_OUT(DATAIN_RISC),
104
                .RISC_CS(RISC_CS), .RISC_RW(RISC_RW), .Wp(Wp), .Bp(Bp),
105 5 mohor
                .OpSelect(OpSelect), .LsStatus(LsStatus), .IStatus(IStatus),
106
                .RISC_STALL_O(RISC_STALL_O), .RISC_RESET_O(RISC_RESET_O), .BS_CHAIN_I(BS_CHAIN_I)
107 2 mohor
                );
108
 
109
 
110
reg TestEnabled;
111
//integer i;
112
 
113
 
114
 
115
initial
116
begin
117
  TestEnabled<=#Tp 0;
118
  P_TMS<=#Tp 0;
119
  P_TCK<=#Tp 0;
120
  P_TDI<=#Tp 0;
121
  P_TRST<=#Tp 1;
122
 
123
  Wp<=#Tp 0;
124
  Bp<=#Tp 0;
125
  LsStatus<=#Tp 0;
126
  IStatus<=#Tp 0;
127
 
128
  P_PowerONReset<=#Tp 1;
129
  #100 P_PowerONReset<=#Tp 0;    // PowerONReset is active low
130
  #100 P_PowerONReset<=#Tp 1;
131
  #Tp TestEnabled<=#Tp 1;
132
end
133
 
134
 
135
// Generating master clock (RISC clock) 200 MHz
136
initial
137
begin
138
  Mclk<=#Tp 0;
139
  #1 forever #`RISC_CLOCK Mclk<=~Mclk;
140
end
141
 
142
 
143
// Generating random number for use in DATAOUT_RISC[31:0]
144
reg [31:0] RandNumb;
145
always @ (posedge Mclk or negedge P_PowerONReset) // PowerONReset is active low
146
begin
147
  if(~P_PowerONReset)
148
    RandNumb[31:0]<=#Tp 0;
149
  else
150
    RandNumb[31:0]<=#Tp RandNumb[31:0] + 1;
151
end
152
 
153
 
154
assign DATAOUT_RISC[31:0] = RandNumb[31:0];
155
 
156
 
157
 
158
always @ (posedge TestEnabled)
159
begin
160
  ResetTAP;
161
  GotoRunTestIdle;
162
 
163
// Testing read and write to RISC registers
164
  SetInstruction(`CHAIN_SELECT);
165
  ChainSelect(`RISC_DEBUG_CHAIN, 8'h38);  // {chain, crc}
166
  SetInstruction(`DEBUG);
167
  ReadRISCRegister(32'h12345ead, 8'hbf);                 // {addr, crc}
168
  WriteRISCRegister(32'h11223344, 32'h12345678, 8'haf);  // {data, addr, crc}
169
//
170
 
171
 
172
 
173
// Testing read and write to internal registers
174
  SetInstruction(`IDCODE);
175
  ReadIDCode;
176
 
177
  SetInstruction(`CHAIN_SELECT);
178
  ChainSelect(`REGISTER_SCAN_CHAIN, 8'h0e);  // {chain, crc}
179
  SetInstruction(`DEBUG);
180
 
181 5 mohor
 
182
/*
183
//  Testing internal registers
184 2 mohor
    ReadRegister(`MODER_ADR, 8'h00);           // {addr, crc}
185
    ReadRegister(`TSEL_ADR, 8'h64);            // {addr, crc}
186
    ReadRegister(`QSEL_ADR, 8'h32);            // {addr, crc}
187
    ReadRegister(`SSEL_ADR, 8'h56);            // {addr, crc}
188 5 mohor
    ReadRegister(`RECSEL_ADR, 8'hc4);          // {addr, crc}
189 2 mohor
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
190
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
191
 
192
    WriteRegister(32'h00000001, `MODER_ADR,   8'h53); // {data, addr, crc}
193
    WriteRegister(32'h00000020, `TSEL_ADR,    8'h5e); // {data, addr, crc}
194
    WriteRegister(32'h00000300, `QSEL_ADR,    8'hdd); // {data, addr, crc}
195
    WriteRegister(32'h00004000, `SSEL_ADR,    8'he2); // {data, addr, crc}
196 5 mohor
    WriteRegister(32'h0000dead, `RECSEL_ADR,  8'hfb); // {data, addr, crc}
197 2 mohor
 
198
    ReadRegister(`MODER_ADR, 8'h00);           // {addr, crc}
199
    ReadRegister(`TSEL_ADR, 8'h64);            // {addr, crc}
200
    ReadRegister(`QSEL_ADR, 8'h32);            // {addr, crc}
201
    ReadRegister(`SSEL_ADR, 8'h56);            // {addr, crc}
202 5 mohor
    ReadRegister(`RECSEL_ADR, 8'hc4);          // {addr, crc}
203 2 mohor
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
204
    ReadRegister(5'h1f, 8'h04);                // {addr, crc}       // Register address don't exist. Read should return high-Z.
205 5 mohor
*/
206 2 mohor
 
207
 
208
// testing trigger and qualifier
209
`ifdef TRACE_ENABLED
210
 
211
 
212
 
213
 
214
 
215 6 mohor
// Anything starts trigger and qualifier
216 5 mohor
    #1000 WriteRegister(32'h00000000, `QSEL_ADR,   8'h50);    // Any qualifier
217
    #1000 WriteRegister(32'h00000000, `TSEL_ADR,   8'h06);    // Any trigger
218
    #1000 WriteRegister(32'h00000003, `RECSEL_ADR,   8'h0c);  // Two samples are selected for recording (RECPC and RECLSEA)
219
    #100  WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
220
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
221 6 mohor
// End: Anything starts trigger and qualifier //
222 2 mohor
 
223
 
224 6 mohor
/* Anything starts trigger, breakpoint starts qualifier
225 5 mohor
    #1000 WriteRegister(`QUALIFOP_OR | `BPQUALIFVALID | `BPQUALIF, `QSEL_ADR,   8'had);    // Any qualifier
226
    #1000 WriteRegister(32'h00000000, `TSEL_ADR,   8'h06);    // Any trigger
227 6 mohor
    #1000 WriteRegister(32'h0000000c, `RECSEL_ADR,   8'h0f);  // Two samples are selected for recording (RECSDATA and RECLDATA)
228 5 mohor
    #1000 WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
229
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
230
    wait(dbg_tb.dbgTAP1.TraceEnable)
231
    @ (posedge Mclk);
232
      #1 Bp = 1;                                                 // Set breakpoint
233
    repeat(8) @(posedge Mclk);
234
    wait(dbg_tb.dbgTAP1.dbgTrace1.RiscStall)
235
      #1 Bp = 0;                                                 // Clear breakpoint
236 6 mohor
// End: Anything starts trigger, breakpoint starts qualifier */
237 2 mohor
 
238
 
239 5 mohor
/* Anything starts qualifier, breakpoint starts trigger
240
    #1000 WriteRegister(32'h00000000, `QSEL_ADR,   8'h50);    // Any qualifier
241
    #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]
242
    #1000 WriteRegister(32'h00000003, `RECSEL_ADR,   8'h0c);  // Two samples are selected for recording (RECPC and RECLSEA)
243
    #1000 WriteRegister(32'h00000000, `SSEL_ADR,   8'h34);    // No stop signal
244
    #1000 WriteRegister(`ENABLE, `MODER_ADR,    8'hd4);       // Trace enabled
245
    wait(dbg_tb.dbgTAP1.TraceEnable)
246
    @ (posedge Mclk)
247
      Wp[4] = 1;                                              // Set watchpoint[4]
248
      LsStatus = 4'h5;                                        // LsStatus[0] and LsStatus[2] are active
249
    @ (posedge Mclk)
250
      Wp[4] = 0;                                              // Clear watchpoint[4]
251
      LsStatus = 4'h0;                                        // LsStatus[0] and LsStatus[2] are cleared
252
// End: Anything starts trigger and qualifier */
253 2 mohor
 
254
 
255 5 mohor
 
256
 
257
 
258
 
259 2 mohor
  SetInstruction(`CHAIN_SELECT);
260
  ChainSelect(`TRACE_TEST_CHAIN, 8'h24);  // {chain, crc}
261
  SetInstruction(`DEBUG);
262
  ReadTraceBuffer;
263
  ReadTraceBuffer;
264
  ReadTraceBuffer;
265
  ReadTraceBuffer;
266
  ReadTraceBuffer;
267
  ReadTraceBuffer;
268
  ReadTraceBuffer;
269
  ReadTraceBuffer;
270
  ReadTraceBuffer;
271
  ReadTraceBuffer;
272
  ReadTraceBuffer;
273
  ReadTraceBuffer;
274
 
275
//  for(i=0;i<1500;i=i+1)
276
//    ReadTraceBuffer;
277
 
278
`endif  // TRACE_ENABLED
279
 
280
 
281
 
282
 
283
  #5000 GenClk(1);            // One extra TCLK for debugging purposes
284 5 mohor
  #1000 $stop;
285 2 mohor
 
286
end
287
 
288
 
289
 
290
// Generation of the TCLK signal
291
task GenClk;
292
  input [7:0] Number;
293
  integer i;
294
  begin
295
    for(i=0; i<Number; i=i+1)
296
      begin
297
        #Tclk P_TCK<=1;
298
        #Tclk P_TCK<=0;
299
      end
300
  end
301
endtask
302
 
303
 
304
// TAP reset
305
task ResetTAP;
306
  begin
307
    P_TMS<=#Tp 1;
308
    GenClk(7);
309
  end
310
endtask
311
 
312
 
313
// Goes to RunTestIdle state
314
task GotoRunTestIdle;
315
  begin
316
    P_TMS<=#Tp 0;
317
    GenClk(1);
318
  end
319
endtask
320
 
321
 
322
// sets the instruction to the IR register and goes to the RunTestIdle state
323
task SetInstruction;
324
  input [3:0] Instr;
325
  integer i;
326
 
327
  begin
328
    P_TMS<=#Tp 1;
329
    GenClk(2);
330
    P_TMS<=#Tp 0;
331
    GenClk(2);  // we are in shiftIR
332
 
333
    for(i=0; i<`IR_LENGTH-1; i=i+1)
334
    begin
335
      P_TDI<=#Tp Instr[i];
336
      GenClk(1);
337
    end
338
 
339
    P_TDI<=#Tp Instr[i]; // last shift
340
    P_TMS<=#Tp 1;        // going out of shiftIR
341
    GenClk(1);
342
      P_TDI<=#Tp 'hz;    // tri-state
343
    GenClk(1);
344
    P_TMS<=#Tp 0;
345
    GenClk(1);       // we are in RunTestIdle
346
  end
347
endtask
348
 
349
 
350
// sets the selected scan chain and goes to the RunTestIdle state
351
task ChainSelect;
352
  input [3:0] Data;
353
  input [7:0] Crc;
354
  integer i;
355
 
356
  begin
357
    P_TMS<=#Tp 1;
358
    GenClk(1);
359
    P_TMS<=#Tp 0;
360
    GenClk(2);  // we are in shiftDR
361
 
362
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
363
    begin
364
      P_TDI<=#Tp Data[i];
365
      GenClk(1);
366
    end
367
 
368
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
369
    begin
370
      P_TDI<=#Tp Crc[i];
371
      GenClk(1);
372
    end
373
 
374
    P_TDI<=#Tp Crc[i]; // last shift
375
    P_TMS<=#Tp 1;        // going out of shiftIR
376
    GenClk(1);
377
      P_TDI<=#Tp 'hz; // tri-state
378
    GenClk(1);
379
    P_TMS<=#Tp 0;
380
    GenClk(1);       // we are in RunTestIdle
381
  end
382
endtask
383
 
384
 
385
// Reads the ID code
386
task ReadIDCode;
387
  begin
388
    P_TMS<=#Tp 1;
389
    GenClk(1);
390
    P_TMS<=#Tp 0;
391
    GenClk(2);  // we are in shiftDR
392
 
393
    P_TDI<=#Tp 0;
394
    GenClk(31);
395
    P_TMS<=#Tp 1;        // going out of shiftIR
396
    GenClk(1);
397
      P_TDI<=#Tp 'hz; // tri-state
398
    GenClk(1);
399
    P_TMS<=#Tp 0;
400
    GenClk(1);       // we are in RunTestIdle
401
  end
402
endtask
403
 
404
 
405
// Reads sample from the Trace Buffer
406
task ReadTraceBuffer;
407
  begin
408
    P_TMS<=#Tp 1;
409
    GenClk(1);
410
    P_TMS<=#Tp 0;
411
    GenClk(2);  // we are in shiftDR
412
 
413
    P_TDI<=#Tp 0;
414
    GenClk(47);
415
    P_TMS<=#Tp 1;        // going out of shiftIR
416
    GenClk(1);
417
      P_TDI<=#Tp 'hz; // tri-state
418
    GenClk(1);
419
    P_TMS<=#Tp 0;
420
    GenClk(1);       // we are in RunTestIdle
421
  end
422
endtask
423
 
424
 
425
// Reads the RISC register and latches the data so it is ready for reading
426
task ReadRISCRegister;
427
  input [31:0] Address;
428
  input [7:0] Crc;
429
  integer i;
430
 
431
  begin
432
    P_TMS<=#Tp 1;
433
    GenClk(1);
434
    P_TMS<=#Tp 0;
435
    GenClk(2);  // we are in shiftDR
436
 
437
    for(i=0; i<32; i=i+1)
438
    begin
439
      P_TDI<=#Tp Address[i];  // Shifting address
440
      GenClk(1);
441
    end
442
 
443
    P_TDI<=#Tp 0;             // shifting RW bit = read
444
    GenClk(1);
445
 
446
    for(i=0; i<32; i=i+1)
447
    begin
448
      P_TDI<=#Tp 0;     // Shifting data. Data is not important in read cycle.
449
      GenClk(1);
450
    end
451
 
452
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
453
    begin
454
      P_TDI<=#Tp Crc[i];     // Shifting CRC.
455
      GenClk(1);
456
    end
457
 
458
    P_TDI<=#Tp Crc[i];   // Shifting last bit of CRC.
459
    P_TMS<=#Tp 1;        // going out of shiftIR
460
    GenClk(1);
461
      P_TDI<=#Tp 'hz;   // Tristate TDI.
462
    GenClk(1);
463
 
464
    P_TMS<=#Tp 0;
465
    GenClk(1);       // we are in RunTestIdle
466
  end
467
endtask
468
 
469
 
470
// Write the RISC register
471
task WriteRISCRegister;
472
  input [31:0] Data;
473
  input [31:0] Address;
474
  input [`CRC_LENGTH-1:0] Crc;
475
  integer i;
476
 
477
  begin
478
    P_TMS<=#Tp 1;
479
    GenClk(1);
480
    P_TMS<=#Tp 0;
481
    GenClk(2);  // we are in shiftDR
482
 
483
    for(i=0; i<32; i=i+1)
484
    begin
485
      P_TDI<=#Tp Address[i];  // Shifting address
486
      GenClk(1);
487
    end
488
 
489
    P_TDI<=#Tp 1;             // shifting RW bit = write
490
    GenClk(1);
491
 
492
    for(i=0; i<32; i=i+1)
493
    begin
494
      P_TDI<=#Tp Data[i];     // Shifting data
495
      GenClk(1);
496
    end
497
 
498
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
499
    begin
500
      P_TDI<=#Tp Crc[i];     // Shifting CRC
501
      GenClk(1);
502
    end
503
 
504
    P_TDI<=#Tp Crc[i];        // shifting last bit of CRC
505
    P_TMS<=#Tp 1;        // going out of shiftIR
506
    GenClk(1);
507
      P_TDI<=#Tp 'hz;        // tristate TDI
508
    GenClk(1);
509
 
510
    P_TMS<=#Tp 0;
511
    GenClk(1);       // we are in RunTestIdle
512
 
513
    GenClk(10);      // Generating few clock cycles needed for the write operation to accomplish
514
  end
515
endtask
516
 
517
 
518
// Reads the register and latches the data so it is ready for reading
519
task ReadRegister;
520
  input [4:0] Address;
521
  input [7:0] Crc;
522
  integer i;
523
 
524
  begin
525
    P_TMS<=#Tp 1;
526
    GenClk(1);
527
    P_TMS<=#Tp 0;
528
    GenClk(2);  // we are in shiftDR
529
 
530
    for(i=0; i<5; i=i+1)
531
    begin
532
      P_TDI<=#Tp Address[i];  // Shifting address
533
      GenClk(1);
534
    end
535
 
536
    P_TDI<=#Tp 0;             // shifting RW bit = read
537
    GenClk(1);
538
 
539
    for(i=0; i<32; i=i+1)
540
    begin
541
      P_TDI<=#Tp 0;     // Shifting data. Data is not important in read cycle.
542
      GenClk(1);
543
    end
544
 
545
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
546
    begin
547
      P_TDI<=#Tp Crc[i];     // Shifting CRC. CRC is not important in read cycle.
548
      GenClk(1);
549
    end
550
 
551
    P_TDI<=#Tp Crc[i];     // Shifting last bit of CRC.
552
    P_TMS<=#Tp 1;        // going out of shiftIR
553
    GenClk(1);
554
      P_TDI<=#Tp 'hz;     // Tri state TDI
555
    GenClk(1);
556
    P_TMS<=#Tp 0;
557
    GenClk(1);       // we are in RunTestIdle
558
 
559
    GenClk(10);      // Generating few clock cycles needed for the read operation to accomplish
560
  end
561
endtask
562
 
563
 
564
// Write the register
565
task WriteRegister;
566
  input [31:0] Data;
567
  input [4:0] Address;
568
  input [`CRC_LENGTH-1:0] Crc;
569
  integer i;
570
 
571
  begin
572
    P_TMS<=#Tp 1;
573
    GenClk(1);
574
    P_TMS<=#Tp 0;
575
    GenClk(2);  // we are in shiftDR
576
 
577
    for(i=0; i<5; i=i+1)
578
    begin
579
      P_TDI<=#Tp Address[i];  // Shifting address
580
      GenClk(1);
581
    end
582
 
583
    P_TDI<=#Tp 1;             // shifting RW bit = write
584
    GenClk(1);
585
 
586
    for(i=0; i<32; i=i+1)
587
    begin
588
      P_TDI<=#Tp Data[i];     // Shifting data
589
      GenClk(1);
590
    end
591
 
592
    for(i=0; i<`CRC_LENGTH-1; i=i+1)
593
    begin
594
      P_TDI<=#Tp Crc[i];     // Shifting CRC
595
      GenClk(1);
596
    end
597
 
598
    P_TDI<=#Tp Crc[i];   // Shifting last bit of CRC
599
    P_TMS<=#Tp 1;        // going out of shiftIR
600
    GenClk(1);
601
      P_TDI<=#Tp 'hz;   // Tri state TDI
602
    GenClk(1);
603
 
604
    P_TMS<=#Tp 0;
605
    GenClk(1);       // we are in RunTestIdle
606 5 mohor
 
607
    GenClk(5);       // Igor !!!! To mora iti ven. Tu je le zato, da se tisti write-i naredijo
608
 
609 2 mohor
  end
610
endtask
611
 
612
 
613
 
614
/**********************************************************************************
615
*                                                                                 *
616
*   Printing the information to the screen                                        *
617
*                                                                                 *
618
**********************************************************************************/
619
 
620
// Print samples that are recorded to the trace buffer
621
`ifdef TRACE_ENABLED
622
always @ (posedge Mclk)
623
begin
624
  if(dbg_tb.dbgTAP1.dbgTrace1.WriteSample)
625 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]});
626 2 mohor
end
627
`endif
628
 
629
 
630
// Print selected instruction
631
reg UpdateIR_q;
632
always @ (posedge P_TCK)
633
begin
634
  UpdateIR_q<=#Tp dbg_tb.dbgTAP1.UpdateIR;
635
end
636
 
637
always @ (posedge P_TCK)
638
begin
639
  if(UpdateIR_q)
640
    case(dbg_tb.dbgTAP1.JTAG_IR[`IR_LENGTH-1:0])
641
      `EXTEST         : $write("\n\tInstruction EXTEST");
642
      `SAMPLE_PRELOAD : $write("\n\tInstruction SAMPLE_PRELOAD");
643
      `IDCODE         : $write("\n\tInstruction IDCODE");
644
      `CHAIN_SELECT   : $write("\n\tInstruction CHAIN_SELECT");
645
      `INTEST         : $write("\n\tInstruction INTEST");
646
      `CLAMP          : $write("\n\tInstruction CLAMP");
647
      `CLAMPZ         : $write("\n\tInstruction CLAMPZ");
648
      `HIGHZ          : $write("\n\tInstruction HIGHZ");
649
      `DEBUG          : $write("\n\tInstruction DEBUG");
650
      `BYPASS         : $write("\n\tInstruction BYPASS");
651
                default           :     $write("\n\tInstruction not valid. Instruction BYPASS activated !!!");
652
    endcase
653
end
654
 
655
 
656
 
657
// Print selected chain
658
always @ (posedge P_TCK)
659
begin
660
  if(dbg_tb.dbgTAP1.CHAIN_SELECTSelected & dbg_tb.dbgTAP1.UpdateDR_q)
661
    case(dbg_tb.dbgTAP1.Chain[`CHAIN_ID_LENGTH-1:0])
662
      `GLOBAL_BS_CHAIN      : $write("\nChain GLOBAL_BS_CHAIN");
663
      `RISC_DEBUG_CHAIN     : $write("\nChain RISC_DEBUG_CHAIN");
664
      `RISC_TEST_CHAIN      : $write("\nChain RISC_TEST_CHAIN");
665
      `TRACE_TEST_CHAIN     : $write("\nChain TRACE_TEST_CHAIN");
666
      `REGISTER_SCAN_CHAIN  : $write("\nChain REGISTER_SCAN_CHAIN");
667
    endcase
668
end
669
 
670
 
671
// print RISC registers read/write
672
always @ (posedge Mclk)
673
begin
674
  if(dbg_tb.dbgTAP1.RISC_CS)
675
    if(dbg_tb.dbgTAP1.RISC_RW)
676
      begin
677
        $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]);
678
      end
679
    else
680
      begin
681
        $write("\n\t\tRead from RISC Register (addr=0x%h, data=0x%h)", dbg_tb.dbgTAP1.ADDR[31:0], dbg_tb.dbgTAP1.RISC_DATA_IN[31:0]);
682
      end
683
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
        $write("\n\t\tRead from Register (addr=0x%h, data=0x%h)", dbg_tb.dbgTAP1.ADDR[4:0], dbg_tb.dbgTAP1.RegDataIn[31:0]);
695
    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.