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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [sdram_test_working/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 49

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

powered by: WebSVN 2.1.0

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