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 15

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

powered by: WebSVN 2.1.0

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