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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [sdram_test_working/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 9

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

powered by: WebSVN 2.1.0

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