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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [new_debug/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 13

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

powered by: WebSVN 2.1.0

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