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 36

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

powered by: WebSVN 2.1.0

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