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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_19/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 17

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

powered by: WebSVN 2.1.0

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