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 158

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

powered by: WebSVN 2.1.0

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