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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_6/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 38

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

powered by: WebSVN 2.1.0

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