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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [highland_ver1/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 73

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

powered by: WebSVN 2.1.0

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