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 92

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
////  Author(s):                                                  ////
10 80 mohor
////       Igor Mohor (igorm@opencores.org)                       ////
11 2 mohor
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18 80 mohor
//// Copyright (C) 2000 - 2003 Authors                            ////
19 2 mohor
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 92 mohor
// Revision 1.20  2004/01/09 12:49:23  mohor
47
// tmp version.
48
//
49 91 mohor
// Revision 1.19  2004/01/08 17:53:12  mohor
50
// tmp version.
51
//
52 90 mohor
// Revision 1.18  2004/01/07 11:59:48  mohor
53
// temp4 version.
54
//
55 89 mohor
// Revision 1.17  2004/01/06 17:14:59  mohor
56
// temp3 version.
57
//
58 88 mohor
// Revision 1.16  2004/01/05 12:16:50  mohor
59
// tmp2 version.
60
//
61 87 mohor
// Revision 1.15  2003/12/23 14:26:01  mohor
62
// New version of the debug interface. Not finished, yet.
63
//
64 80 mohor
// Revision 1.14  2003/10/23 16:16:30  mohor
65
// CRC logic changed.
66
//
67 73 mohor
// Revision 1.13  2003/08/28 13:54:33  simons
68
// Three more chains added for cpu debug access.
69
//
70 63 simons
// Revision 1.12  2002/05/07 14:44:52  mohor
71
// mon_cntl_o signals that controls monitor mux added.
72
//
73 47 mohor
// Revision 1.11  2002/03/12 14:32:26  mohor
74
// Few outputs for boundary scan chain added.
75
//
76 38 mohor
// Revision 1.10  2002/03/08 15:27:08  mohor
77
// Structure changed. Hooks for jtag chain added.
78
//
79 36 mohor
// Revision 1.9  2001/10/19 11:39:20  mohor
80
// dbg_timescale.v changed to timescale.v This is done for the simulation of
81
// few different cores in a single project.
82
//
83 17 mohor
// Revision 1.8  2001/10/17 10:39:17  mohor
84
// bs_chain_o added.
85
//
86 15 mohor
// Revision 1.7  2001/10/16 10:10:18  mohor
87
// Signal names changed to lowercase.
88
//
89 13 mohor
// Revision 1.6  2001/10/15 09:52:50  mohor
90
// Wishbone interface added, few fixes for better performance,
91
// hooks for boundary scan testing added.
92
//
93 12 mohor
// Revision 1.5  2001/09/24 14:06:12  mohor
94
// Changes connected to the OpenRISC access (SPR read, SPR write).
95
//
96 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
97
// Working version. Few bugs fixed, comments added.
98
//
99 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
100
// Minor changes for simulation.
101
//
102 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
103
// Trace fixed. Some registers changed, trace simplified.
104
//
105 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
106
// Initial official release.
107
//
108 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
109
// This is a backup. It is not a fully working version. Not for use, yet.
110
//
111
// Revision 1.2  2001/05/18 13:10:05  mohor
112
// Headers changed. All additional information is now avaliable in the README.txt file.
113
//
114
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
115
// Initial release
116
//
117
//
118
 
119
 
120 17 mohor
`include "timescale.v"
121 2 mohor
`include "dbg_defines.v"
122 80 mohor
`include "dbg_wb_defines.v"
123
//`include "dbg_tb_defines.v"
124 2 mohor
 
125
// Test bench
126
module dbg_tb;
127
 
128 80 mohor
parameter TCLK = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
129 2 mohor
 
130 80 mohor
reg   tms_pad_i;
131
reg   tck_pad_i;
132
reg   trst_pad_i;
133
reg   tdi_pad_i;
134
wire  tdo_pad_o;
135
wire  tdo_padoe_o;
136 2 mohor
 
137 80 mohor
wire  shift_dr_o;
138
wire  pause_dr_o;
139
wire  update_dr_o;
140 2 mohor
 
141 80 mohor
wire  extest_select_o;
142
wire  sample_preload_select_o;
143
wire  mbist_select_o;
144
wire  debug_select_o;
145 2 mohor
 
146 80 mohor
// WISHBONE common signals
147
reg   wb_rst_i;
148
reg   wb_clk_i;
149
 
150
// WISHBONE master interface
151
wire [31:0] wb_adr_o;
152
wire [31:0] wb_dat_o;
153
wire [31:0] wb_dat_i;
154
wire        wb_cyc_o;
155
wire        wb_stb_o;
156
wire  [3:0] wb_sel_o;
157
wire        wb_we_o;
158
wire        wb_ack_i;
159
wire        wb_cab_o;
160
wire        wb_err_i;
161
wire  [2:0] wb_cti_o;
162
wire  [1:0] wb_bte_o;
163 2 mohor
 
164 87 mohor
// Text used for easier debugging
165
reg  [99:0] test_text;
166 88 mohor
reg   [2:0] last_wb_cmd;
167
reg  [99:0] last_wb_cmd_text;
168
reg  [31:0] wb_data;
169 2 mohor
 
170
 
171 12 mohor
 
172 80 mohor
wire  tdo_o;
173 12 mohor
 
174 80 mohor
wire  debug_tdi_i;
175
wire  bs_chain_tdi_i;
176
wire  mbist_tdi_i;
177 73 mohor
 
178 80 mohor
reg   test_enabled;
179 73 mohor
 
180 80 mohor
reg [31:0] result;
181 2 mohor
 
182 88 mohor
reg [31:0] tmp_crc;
183
reg [31:0] shifted_in_crc;
184
 
185 80 mohor
wire tdo;
186 73 mohor
 
187 80 mohor
assign tdo = tdo_padoe_o? tdo_pad_o : 1'hz;
188 73 mohor
 
189 80 mohor
// Connecting TAP module
190
tap_top i_tap_top (
191
                    .tms_pad_i(tms_pad_i),
192
                    .tck_pad_i(tck_pad_i),
193
                    .trst_pad_i(!trst_pad_i),
194
                    .tdi_pad_i(tdi_pad_i),
195
                    .tdo_pad_o(tdo_pad_o),
196
                    .tdo_padoe_o(tdo_padoe_o),
197 38 mohor
 
198 80 mohor
                    // TAP states
199
                    .shift_dr_o(shift_dr_o),
200
                    .pause_dr_o(pause_dr_o),
201
                    .update_dr_o(update_dr_o),
202 38 mohor
 
203 80 mohor
                    // Select signals for boundary scan or mbist
204
                    .extest_select_o(extest_select_o),
205
                    .sample_preload_select_o(sample_preload_select_o),
206
                    .mbist_select_o(mbist_select_o),
207
                    .debug_select_o(debug_select_o),
208 2 mohor
 
209 80 mohor
                    // TDO signal that is connected to TDI of sub-modules.
210
                    .tdo_o(tdo_o),
211 38 mohor
 
212 80 mohor
                    // TDI signals from sub-modules
213
                    .debug_tdi_i(debug_tdi_i),        // from debug module
214
                    .bs_chain_tdi_i(bs_chain_tdi_i),  // from Boundary Scan Chain
215
                    .mbist_tdi_i(mbist_tdi_i)         // from Mbist Chain
216 73 mohor
 
217 38 mohor
               );
218 2 mohor
 
219
 
220 80 mohor
dbg_top i_dbg_top  (
221
 
222
                    .trst_i(!trst_pad_i),
223
                    .tck_i(tck_pad_i),
224
                    .tdi_i(tdo_o),
225
                    .tdo_o(debug_tdi_i),
226
 
227
                    // TAP states
228
                    .shift_dr_i   (shift_dr_o),
229
                    .pause_dr_i   (pause_dr_o),
230
                    .update_dr_i  (update_dr_o),
231
 
232
                    // Instructions
233
                    .debug_select_i(debug_select_o),
234 12 mohor
 
235 80 mohor
                    // WISHBONE common signals
236
                    .wb_rst_i      (wb_rst_i),
237
                    .wb_clk_i      (wb_clk_i),
238
 
239
                    // WISHBONE master interface
240
                    .wb_adr_o      (wb_adr_o),
241
                    .wb_dat_o      (wb_dat_o),
242
                    .wb_dat_i      (wb_dat_i),
243
                    .wb_cyc_o      (wb_cyc_o),
244
                    .wb_stb_o      (wb_stb_o),
245
                    .wb_sel_o      (wb_sel_o),
246
                    .wb_we_o       (wb_we_o),
247
                    .wb_ack_i      (wb_ack_i),
248
                    .wb_cab_o      (wb_cab_o),
249
                    .wb_err_i      (wb_err_i),
250
                    .wb_cti_o      (wb_cti_o),
251
                    .wb_bte_o      (wb_bte_o)
252
                   );
253 12 mohor
 
254
 
255 80 mohor
wb_slave_behavioral wb_slave
256
                   (
257
                    .CLK_I(wb_clk_i),
258
                    .RST_I(wb_rst_i),
259
                    .ACK_O(wb_ack_i),
260
                    .ADR_I(wb_adr_o),
261
                    .CYC_I(wb_cyc_o),
262
                    .DAT_O(wb_dat_i),
263
                    .DAT_I(wb_dat_o),
264
                    .ERR_O(wb_err_i),
265
                    .RTY_O(),      // NOT USED for now!
266
                    .SEL_I(wb_sel_o),
267
                    .STB_I(wb_stb_o),
268
                    .WE_I (wb_we_o),
269
                    .CAB_I(1'b0)
270
                   );
271 2 mohor
 
272
 
273 80 mohor
// Initial values
274 2 mohor
initial
275
begin
276 80 mohor
  test_enabled = 1'b0;
277 88 mohor
  wb_data = 32'h01234567;
278 80 mohor
  trst_pad_i = 1'b1;
279
  tms_pad_i = 1'hz;
280
  tck_pad_i = 1'hz;
281
  tdi_pad_i = 1'hz;
282
 
283
  #100;
284
  trst_pad_i = 1'b0;
285
  #100;
286
  trst_pad_i = 1'b1;
287
  #1 test_enabled<=#1 1'b1;
288 2 mohor
end
289
 
290 80 mohor
initial
291
begin
292
  wb_rst_i = 1'b0;
293
  #1000;
294
  wb_rst_i = 1'b1;
295
  #1000;
296
  wb_rst_i = 1'b0;
297 2 mohor
 
298 80 mohor
  // Initial values for wishbone slave model
299
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
300
end
301
 
302
initial
303 2 mohor
begin
304 80 mohor
  wb_clk_i = 1'b0;
305
  forever #5 wb_clk_i = ~wb_clk_i;
306 2 mohor
end
307
 
308 80 mohor
always @ (posedge test_enabled)
309
begin
310 2 mohor
 
311 80 mohor
  $display("//////////////////////////////////////////////////////////////////");
312
  $display("//                                                              //");
313
  $display("//  (%0t) dbg_tb starting                                     //", $time);
314
  $display("//                                                              //");
315
  $display("//////////////////////////////////////////////////////////////////");
316 2 mohor
 
317 80 mohor
  initialize_memory(32'h12340000, 32'h00100000);  // Initialize 0x100000 bytes starting from address 0x12340000
318 2 mohor
 
319 80 mohor
  reset_tap;
320
  goto_run_test_idle;
321 12 mohor
 
322 80 mohor
  // Testing read and write to internal registers
323
  #10000;
324
  set_instruction(`IDCODE);
325
  read_id_code;
326 12 mohor
 
327 80 mohor
  set_instruction(`DEBUG);
328
  #10000;
329 2 mohor
 
330 80 mohor
  chain_select(`WISHBONE_SCAN_CHAIN, 32'hf2bcd929);
331 12 mohor
 
332 80 mohor
//  #10000;
333
//  xxx(4'b1001, 32'he579b242);
334 12 mohor
 
335 80 mohor
  #10000;
336 2 mohor
 
337 88 mohor
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345678, 16'h4, 32'h57ecda62, result, "abc 1"); // {command, ready, addr, length, crc, result, text}
338
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345679, 16'h4, 32'h563476e5, result, "abc 2"); // {command, ready, addr, length, crc, result, text}
339
//  debug_wishbone(`WB_READ8, 1'b0, 32'h1234567a, 16'h4, 32'h545d836c, result, "abc 3"); // {command, ready, addr, length, crc, result, text}
340
//
341
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345678, 16'h4, 32'h86156251, result, "abc 4"); // {command, ready, addr, length, crc, result, text}
342
//  debug_wishbone(`WB_READ16, 1'b0, 32'h1234567a, 16'h4, 32'h85a43b5f, result, "abc 5"); // {command, ready, addr, length, crc, result, text}
343
//
344 90 mohor
  debug_wishbone(`WB_READ32, 1'b0, 32'h12345678, 16'h4, 32'hc9420a40, result, "read32 1"); // {command, ready, addr, length, crc, result, text}
345 88 mohor
//
346
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345679, 16'h4, 32'h87cdced6, result, "abc 6"); // {command, ready, addr, length, crc, result, text}
347 2 mohor
 
348 80 mohor
  #10000;
349
//  xxx(4'b1001, 32'he579b242);
350
 
351 90 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12345678, 16'h4, 32'hc9420a40, result, "read32 2"); // {command, ready, addr, length, crc, result, text}
352 87 mohor
 
353
  #10000;
354 80 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
355 90 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 32'hc935a962, result, "read32 3"); // {command, ready, addr, length, crc, result, text}
356 80 mohor
 
357
  #10000;
358 88 mohor
  wb_slave.cycle_response(`ERR_RESPONSE, 8'h03, 8'h2);   // (`ERR_RESPONSE, wbs_waits, wbs_retries);
359 90 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 32'hc935a962, result, "read32 4"); // {command, ready, addr, length, crc, result, text}
360 80 mohor
 
361
  #10000;
362 88 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 32'hc7b0424d, result, "status 1"); // {command, ready, addr, length, crc, result, text}
363 80 mohor
 
364 87 mohor
  #10000;
365 88 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 32'hc7b0424d, result, "status 2"); // {command, ready, addr, length, crc, result, text}
366 80 mohor
 
367 87 mohor
  #10000;
368 92 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 8'h0a, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
369 90 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12347778, 16'hc, 32'hd9ce3bbe, result, "read32 5"); // {command, ready, addr, length, crc, result, text}
370 80 mohor
 
371 87 mohor
  #10000;
372 90 mohor
  debug_wishbone(`WB_WRITE32, 1'b0, 32'h12346668, 16'h8, 32'hc5a58ff5, result, "wr32 len8"); // {command, ready, addr, length, crc, result, text}
373 87 mohor
 
374
  #10000;
375 90 mohor
  debug_wishbone(`WB_WRITE16, 1'b0, 32'h12344446, 16'h8, 32'hed029606, result, "wr16 len8"); // {command, ready, addr, length, crc, result, text}
376 87 mohor
 
377 88 mohor
  #10000;
378 91 mohor
  debug_wishbone(`WB_WRITE8, 1'b0, 32'h1234010e, 16'h8, 32'h359e2d2a, result, "wr8 len8"); // {command, ready, addr, length, crc, result, text}
379 87 mohor
 
380 88 mohor
  #10000;
381 90 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 32'h5e9dd377, result, "go 1"); // {command, ready, addr, length, crc, result, text}
382 87 mohor
 
383 89 mohor
  #10000;
384 90 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12340100, 16'hc, 32'h8bbeb90d, result, "read32 6"); // {command, ready, addr, length, crc, result, text}
385 88 mohor
 
386 89 mohor
  #10000;
387 90 mohor
  debug_wishbone(`WB_READ16, 1'b1, 32'h12340102, 16'he, 32'hcedab37c, result, "read16 7"); // {command, ready, addr, length, crc, result, text}
388 88 mohor
 
389 90 mohor
  #10000;
390
  debug_wishbone(`WB_READ8, 1'b1, 32'h1234010e, 16'h6, 32'h308c30d3, result, "read8 8"); // {command, ready, addr, length, crc, result, text}
391 89 mohor
 
392 90 mohor
  #10000;
393
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 32'hd4b43491, result, "go 2"); // {command, ready, addr, length, crc, result, text}
394 89 mohor
 
395
 
396 90 mohor
 
397
 
398 80 mohor
/*
399
  // Testing read and write to CPU0 registers
400
  #10000;
401
  set_instruction(`CHAIN_SELECT);
402
  chain_select(`CPU_DEBUG_CHAIN_0, 8'h12);  // {chain, crc}
403
  set_instruction(`DEBUG);
404
  WriteCPURegister(32'h11001100, 32'h00110011, 8'h86);  // {data, addr, crc}
405
 
406
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
407
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
408
*/
409
  #5000 gen_clk(1);            // One extra TCLK for debugging purposes
410 5 mohor
  #1000 $stop;
411 80 mohor
 
412 2 mohor
end
413
 
414 80 mohor
 
415
task initialize_memory;
416
  input [31:0] start_addr;
417
  input [31:0] length;
418
  integer i;
419
  reg [31:0] addr;
420
  begin
421
    for (i=0; i<length; i=i+4)
422
      begin
423
        addr = start_addr + i;
424
        wb_slave.wr_mem(addr, {addr[7:0], addr[15:8], addr[23:16], addr[31:24]}, 4'hf);    // adr, data, sel
425
      end
426
  end
427
endtask
428
 
429
 
430
 
431 2 mohor
// Generation of the TCLK signal
432 80 mohor
task gen_clk;
433
  input [7:0] num;
434 2 mohor
  integer i;
435
  begin
436 80 mohor
    for(i=0; i<num; i=i+1)
437 2 mohor
      begin
438 80 mohor
        #TCLK tck_pad_i<=1;
439
        #TCLK tck_pad_i<=0;
440 2 mohor
      end
441
  end
442
endtask
443
 
444
 
445
// TAP reset
446 80 mohor
task reset_tap;
447 2 mohor
  begin
448 80 mohor
    $display("(%0t) Task reset_tap", $time);
449
    tms_pad_i<=#1 1'b1;
450
    gen_clk(7);
451 2 mohor
  end
452
endtask
453
 
454
 
455
// Goes to RunTestIdle state
456 80 mohor
task goto_run_test_idle;
457 2 mohor
  begin
458 80 mohor
    $display("(%0t) Task goto_run_test_idle", $time);
459
    tms_pad_i<=#1 1'b0;
460
    gen_clk(1);
461 2 mohor
  end
462
endtask
463
 
464
 
465
// sets the instruction to the IR register and goes to the RunTestIdle state
466 80 mohor
task set_instruction;
467
  input [3:0] instr;
468 2 mohor
  integer i;
469
 
470
  begin
471 80 mohor
    $display("(%0t) Task set_instruction", $time);
472
    tms_pad_i<=#1 1;
473
    gen_clk(2);
474
    tms_pad_i<=#1 0;
475
    gen_clk(2);  // we are in shiftIR
476 2 mohor
 
477
    for(i=0; i<`IR_LENGTH-1; i=i+1)
478
    begin
479 80 mohor
      tdi_pad_i<=#1 instr[i];
480
      gen_clk(1);
481 2 mohor
    end
482
 
483 80 mohor
    tdi_pad_i<=#1 instr[i]; // last shift
484
    tms_pad_i<=#1 1;        // going out of shiftIR
485
    gen_clk(1);
486 90 mohor
    tdi_pad_i<=#1 'hz;    // tri-state
487 80 mohor
    gen_clk(1);
488
    tms_pad_i<=#1 0;
489
    gen_clk(1);       // we are in RunTestIdle
490 2 mohor
  end
491
endtask
492
 
493
 
494 80 mohor
// Reads the ID code
495
task read_id_code;
496
  begin
497
    $display("(%0t) Task read_id_code", $time);
498
    tms_pad_i<=#1 1;
499
    gen_clk(1);
500
    tms_pad_i<=#1 0;
501
    gen_clk(2);  // we are in shiftDR
502
 
503
    tdi_pad_i<=#1 0;
504
    gen_clk(31);
505
 
506
    tms_pad_i<=#1 1;        // going out of shiftIR
507
    gen_clk(1);
508
 
509
    tdi_pad_i<=#1 'hz; // tri-state
510
    gen_clk(1);
511
    tms_pad_i<=#1 0;
512
    gen_clk(1);       // we are in RunTestIdle
513
  end
514
endtask
515
 
516
 
517 2 mohor
// sets the selected scan chain and goes to the RunTestIdle state
518 80 mohor
task chain_select;
519
  input [3:0]  data;
520
  input [31:0] crc;
521 2 mohor
  integer i;
522
 
523
  begin
524 80 mohor
    $display("(%0t) Task chain_select", $time);
525
    tms_pad_i<=#1 1;
526
    gen_clk(1);
527
    tms_pad_i<=#1 0;
528
    gen_clk(2);  // we are in shiftDR
529 2 mohor
 
530 80 mohor
    tdi_pad_i<=#1 1'b1; // chain_select bit
531
    gen_clk(1);
532
 
533 2 mohor
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
534
    begin
535 80 mohor
      tdi_pad_i<=#1 data[i];
536
      gen_clk(1);
537 2 mohor
    end
538
 
539 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
540 2 mohor
    begin
541 80 mohor
      tdi_pad_i<=#1 crc[`CRC_LEN -1-i];
542
      gen_clk(1);
543 2 mohor
    end
544
 
545 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
546
 
547
 
548
    for(i=0; i<`CRC_LEN -1; i=i+1)
549
    begin
550
      tdi_pad_i<=#1 1'b0;
551
      gen_clk(1);
552
    end
553
 
554
    tdi_pad_i<=#1 crc[i]; // last crc
555
    tms_pad_i<=#1 1;
556
    gen_clk(1);         // to exit1_dr
557
 
558
    tdi_pad_i<=#1 'hz;  // tri-state
559
    tms_pad_i<=#1 1;
560
    gen_clk(1);         // to update_dr
561
    tms_pad_i<=#1 0;
562
    gen_clk(1);         // to run_test_idle
563 2 mohor
  end
564
endtask
565
 
566
 
567 87 mohor
 
568
 
569
 
570
 
571
 
572 80 mohor
task debug_wishbone;
573
  input [2:0]   command;
574 87 mohor
  input         ready;
575 80 mohor
  input [31:0]  addr;
576
  input [15:0]  length;
577
  input [31:0]  crc;
578
  output [31:0] result;
579 87 mohor
  input [99:0]  text;
580 80 mohor
  integer i;
581
 
582 2 mohor
  begin
583 80 mohor
   $write("(%0t) Task debug_wishbone: ", $time);
584 2 mohor
 
585 87 mohor
    test_text = text;
586 88 mohor
    shifted_in_crc = crc;
587 36 mohor
 
588 80 mohor
    case (command)
589
      `WB_STATUS   :
590
        begin
591 88 mohor
          $display("wb_status (crc=0x%0x (%0s))", crc, text);
592
          debug_wishbone_status(command, crc);
593
          last_wb_cmd = `WB_STATUS;  last_wb_cmd_text = "WB_STATUS";
594 80 mohor
        end
595
      `WB_READ8    :
596
        begin
597 87 mohor
          $display("wb_read8 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
598
          debug_wishbone_set_addr(command, ready, addr, length, crc);
599 88 mohor
          last_wb_cmd = `WB_READ8;  last_wb_cmd_text = "WB_READ8";
600 80 mohor
        end
601
      `WB_READ16   :
602
        begin
603 87 mohor
          $display("wb_read16 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
604
          debug_wishbone_set_addr(command, ready, addr, length, crc);
605 88 mohor
          last_wb_cmd = `WB_READ16;  last_wb_cmd_text = "WB_READ16";
606 80 mohor
        end
607
      `WB_READ32   :
608
        begin
609 87 mohor
          $display("wb_read32 (ready=%0d, adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", ready, addr, length, crc, text);
610
          debug_wishbone_set_addr(command, ready, addr, length, crc);
611 88 mohor
          last_wb_cmd = `WB_READ32;  last_wb_cmd_text = "WB_READ32";
612 80 mohor
        end
613
      `WB_WRITE8   :
614
        begin
615 88 mohor
          $display("wb_write8 (adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, length, crc, text);
616 87 mohor
          debug_wishbone_set_addr(command, ready, addr, length, crc);
617 88 mohor
          last_wb_cmd = `WB_WRITE8;  last_wb_cmd_text = "WB_WRITE8";
618 80 mohor
        end
619
      `WB_WRITE16  :
620
        begin
621 88 mohor
          $display("wb_write16 (adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, length, crc, text);
622 87 mohor
          debug_wishbone_set_addr(command, ready, addr, length, crc);
623 88 mohor
          last_wb_cmd = `WB_WRITE16;  last_wb_cmd_text = "WB_WRITE16";
624 80 mohor
        end
625
      `WB_WRITE32  :
626
        begin
627 88 mohor
          $display("wb_write32 (adr=0x%0x, length=0x%0x, crc=0x%0x (%0s))", addr, length, crc, text);
628 87 mohor
          debug_wishbone_set_addr(command, ready, addr, length, crc);
629 88 mohor
          last_wb_cmd = `WB_WRITE32;  last_wb_cmd_text = "WB_WRITE32";
630 80 mohor
        end
631
      `WB_GO       :
632
        begin
633 87 mohor
          $display("wb_go, crc=0x%0x (%0s))", crc, text);
634 88 mohor
          debug_wishbone_go(command, crc);
635
          last_wb_cmd = `WB_GO;  last_wb_cmd_text = "WB_GO";
636 80 mohor
        end
637
    endcase
638 2 mohor
  end
639 87 mohor
endtask       // debug_wishbone
640 2 mohor
 
641
 
642 80 mohor
 
643
 
644
 
645
 
646 87 mohor
task debug_wishbone_set_addr;
647 80 mohor
  input [2:0]   command;
648 87 mohor
  input         wait_for_wb_ready;
649 80 mohor
  input [31:0]  addr;
650
  input [15:0]  length;
651
  input [31:0]  crc;
652
  integer i;
653
 
654
  begin
655 87 mohor
    $display("(%0t) Task debug_wishbone_set_addr: ", $time);
656 80 mohor
 
657
    tms_pad_i<=#1 1;
658
    gen_clk(1);
659
    tms_pad_i<=#1 0;
660
    gen_clk(2);  // we are in shiftDR
661
 
662
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
663
    gen_clk(1);
664
 
665 88 mohor
    for(i=2; i>=0; i=i-1)
666 80 mohor
    begin
667
      tdi_pad_i<=#1 command[i]; // command
668
      gen_clk(1);
669
    end
670
 
671 88 mohor
    for(i=31; i>=0; i=i-1)       // address
672 80 mohor
    begin
673
      tdi_pad_i<=#1 addr[i];
674
      gen_clk(1);
675
    end
676 87 mohor
 
677 88 mohor
    for(i=15; i>=0; i=i-1)       // length
678 80 mohor
    begin
679
      tdi_pad_i<=#1 length[i];
680
      gen_clk(1);
681
    end
682
 
683 88 mohor
    for(i=31; i>=0; i=i-1)
684 80 mohor
    begin
685 88 mohor
      tdi_pad_i<=#1 crc[i];
686 80 mohor
      gen_clk(1);
687
    end
688
 
689 92 mohor
    tdi_pad_i<=#1 'hz;
690 87 mohor
    if (wait_for_wb_ready)
691
      begin
692
        gen_clk(`STATUS_LEN -1);   // Generating 4 clocks to read out status. Going to pause_dr at the end
693
        tms_pad_i<=#1 1;
694
        gen_clk(1);       // to exit1_dr
695
        tms_pad_i<=#1 0;
696
        gen_clk(1);       // to pause_dr
697
 
698
        while (dbg_tb.tdo_pad_o)     // waiting for wb to send "ready" 
699
        begin
700
          gen_clk(1);       // staying in pause_dr
701
        end
702
 
703
        tms_pad_i<=#1 1;
704
        gen_clk(1);       // to exit2_dr
705
        tms_pad_i<=#1 0;
706
        gen_clk(1);       // to shift_dr
707
      end
708
    else
709
      gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
710 80 mohor
 
711 88 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
712 80 mohor
    begin
713
      gen_clk(1);
714
    end
715
 
716
    tms_pad_i<=#1 1;
717
    gen_clk(1);         // to exit1_dr
718
 
719
    tms_pad_i<=#1 1;
720
    gen_clk(1);         // to update_dr
721
    tms_pad_i<=#1 0;
722
    gen_clk(1);         // to run_test_idle
723
  end
724 87 mohor
endtask       // debug_wishbone_set_addr
725 80 mohor
 
726
 
727
 
728
 
729
 
730 88 mohor
task debug_wishbone_status;
731
  input [2:0]   command;
732
  input [31:0]  crc;
733
  integer i;
734
 
735
  begin
736
    $display("(%0t) Task debug_wishbone_status: ", $time);
737 80 mohor
 
738 88 mohor
    tms_pad_i<=#1 1;
739
    gen_clk(1);
740
    tms_pad_i<=#1 0;
741
    gen_clk(2);  // we are in shiftDR
742 87 mohor
 
743 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
744
    gen_clk(1);
745 87 mohor
 
746 88 mohor
    for(i=2; i>=0; i=i-1)
747
    begin
748
      tdi_pad_i<=#1 command[i]; // command
749
      gen_clk(1);
750
    end
751 87 mohor
 
752 88 mohor
    for(i=31; i>=0; i=i-1)      // crc
753
    begin
754
      tdi_pad_i<=#1 crc[i];
755
      gen_clk(1);
756
    end
757
 
758 92 mohor
    tdi_pad_i<=#1 1'hz;
759 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
760
 
761
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
762
    begin
763
      gen_clk(1);
764
    end
765
 
766
    tms_pad_i<=#1 1;
767
    gen_clk(1);         // to exit1_dr
768
 
769
    tms_pad_i<=#1 1;
770
    gen_clk(1);         // to update_dr
771
    tms_pad_i<=#1 0;
772
    gen_clk(1);         // to run_test_idle
773
  end
774
endtask       // debug_wishbone_status
775
 
776
 
777
 
778
 
779
task debug_wishbone_go;
780
  input [2:0]   command;
781
  input [31:0]  crc;
782 90 mohor
  integer i;
783
  reg   [4:0]   pointer;
784
 
785 2 mohor
  begin
786 88 mohor
    $display("(%0t) Task debug_wishbone_go (previous command was %0s): ", $time, last_wb_cmd_text);
787
 
788 80 mohor
    tms_pad_i<=#1 1;
789
    gen_clk(1);
790
    tms_pad_i<=#1 0;
791
    gen_clk(2);  // we are in shiftDR
792 2 mohor
 
793 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
794 80 mohor
    gen_clk(1);
795 88 mohor
 
796
    for(i=2; i>=0; i=i-1)
797
    begin
798
      tdi_pad_i<=#1 command[i]; // command
799
      gen_clk(1);
800
    end
801
 
802
 
803
    if ((last_wb_cmd == `WB_WRITE8) | (last_wb_cmd == `WB_WRITE16) | (last_wb_cmd == `WB_WRITE32))  // When WB_WRITEx was previously activated, data needs to be shifted.
804
      begin
805 90 mohor
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.len << 3); i=i+1)
806 88 mohor
          begin
807 90 mohor
            if (!(i%32))
808 88 mohor
              begin
809 90 mohor
                wb_data = wb_data + 32'h11111111;
810
                $display("\t\twb_data = 0x%x", wb_data);
811 88 mohor
              end
812 90 mohor
            pointer = 31-i[4:0];
813
            tdi_pad_i<=#1 wb_data[pointer];
814
            gen_clk(1);
815
 
816 88 mohor
          end
817
      end
818
 
819
 
820
    for(i=31; i>=0; i=i-1)      // crc
821
    begin
822
      tdi_pad_i<=#1 crc[i];
823
      gen_clk(1);
824
    end
825
 
826 92 mohor
    tdi_pad_i<=#1 1'hz;
827 90 mohor
 
828
 
829
 
830
    if ((last_wb_cmd == `WB_READ8) | (last_wb_cmd == `WB_READ16) | (last_wb_cmd == `WB_READ32))  // When WB_WRITEx was previously activated, data needs to be shifted.
831
      begin
832
        $display("\t\tGenerating %0d clocks to read %0d data bytes.", dbg_tb.i_dbg_top.i_dbg_wb.len << 3, dbg_tb.i_dbg_top.i_dbg_wb.len);
833
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.len << 3); i=i+1)
834 92 mohor
          gen_clk(1);
835 90 mohor
      end
836
 
837
 
838 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
839
 
840
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
841
    begin
842
      gen_clk(1);
843
    end
844
 
845
    tms_pad_i<=#1 1;
846
    gen_clk(1);         // to exit1_dr
847
 
848
    tms_pad_i<=#1 1;
849
    gen_clk(1);         // to update_dr
850 80 mohor
    tms_pad_i<=#1 0;
851 88 mohor
    gen_clk(1);         // to run_test_idle
852 2 mohor
  end
853 88 mohor
endtask       // debug_wishbone_go
854 2 mohor
 
855
 
856 88 mohor
 
857
 
858
 
859
 
860
 
861
 
862
 
863
 
864 2 mohor
 
865
 
866
 
867
/**********************************************************************************
868
*                                                                                 *
869
*   Printing the information to the screen                                        *
870
*                                                                                 *
871
**********************************************************************************/
872
 
873 80 mohor
always @ (posedge tck_pad_i)
874 2 mohor
begin
875 80 mohor
  if(dbg_tb.i_tap_top.update_ir)
876
    case(dbg_tb.i_tap_top.jtag_ir[`IR_LENGTH-1:0])
877
      `EXTEST         : $display("\tInstruction EXTEST entered");
878
      `SAMPLE_PRELOAD : $display("\tInstruction SAMPLE_PRELOAD entered");
879
      `IDCODE         : $display("\tInstruction IDCODE entered");
880
      `MBIST          : $display("\tInstruction MBIST entered");
881
      `DEBUG          : $display("\tInstruction DEBUG entered");
882
      `BYPASS         : $display("\tInstruction BYPASS entered");
883
                default           :     $display("\n\tInstruction not valid. Instruction BYPASS activated !!!");
884 2 mohor
    endcase
885
end
886
 
887
 
888
 
889
// Print shifted IDCode
890 80 mohor
reg [31:0] tmp_data;
891
always @ (posedge tck_pad_i)
892 2 mohor
begin
893 80 mohor
  if(dbg_tb.i_tap_top.idcode_select)
894 2 mohor
    begin
895 80 mohor
      if(dbg_tb.i_tap_top.shift_dr)
896
        tmp_data[31:0]<=#1 {dbg_tb.tdo, tmp_data[31:1]};
897 2 mohor
      else
898 80 mohor
      if(dbg_tb.i_tap_top.update_dr)
899
        if (tmp_data[31:0] != `IDCODE_VALUE)
900 73 mohor
          begin
901
            $display("(%0t) ERROR: IDCODE not correct", $time);
902
            $stop;
903
          end
904
        else
905 80 mohor
          $display("\t\tIDCode = 0x%h", tmp_data[31:0]);
906 2 mohor
    end
907
end
908
 
909
 
910 80 mohor
// We never use following states: exit2_ir,  exit2_dr,  pause_ir or pause_dr
911
always @ (posedge tck_pad_i)
912 2 mohor
begin
913 80 mohor
  if(dbg_tb.i_tap_top.pause_ir | dbg_tb.i_tap_top.exit2_ir)
914 2 mohor
    begin
915 80 mohor
      $display("\n(%0t) ERROR: State pause_ir or exit2_ir detected.", $time);
916
      $display("(%0t) Simulation stopped !!!", $time);
917
      $stop;
918 2 mohor
    end
919
end
920
 
921
 
922 80 mohor
// sets the selected scan chain and goes to the RunTestIdle state
923
task xxx;
924
  input [3:0]  data;
925
  input [31:0] crc;
926
  integer i;
927
 
928
  begin
929
    $display("(%0t) Task xxx", $time);
930
    tms_pad_i<=#1 1;
931
    gen_clk(1);
932
    tms_pad_i<=#1 0;
933
    gen_clk(2);  // we are in shiftDR
934
 
935
    for(i=0; i<4; i=i+1)
936 73 mohor
    begin
937 80 mohor
      tdi_pad_i<=#1 data[i];
938
      gen_clk(1);
939 73 mohor
    end
940
 
941 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
942
    begin
943
      tdi_pad_i<=#1 crc[`CRC_LEN - 1 - i];
944
      gen_clk(1);
945
    end
946 73 mohor
 
947 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
948 73 mohor
 
949
 
950 80 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)
951
    begin
952
      tdi_pad_i<=#1 1'b0;
953
      gen_clk(1);
954
    end
955 73 mohor
 
956 80 mohor
    tdi_pad_i<=#1 crc[i]; // last crc
957
    tms_pad_i<=#1 1;
958
    gen_clk(1);         // to exit1_dr
959 73 mohor
 
960 80 mohor
    tdi_pad_i<=#1 'hz;  // tri-state
961
    tms_pad_i<=#1 1;
962
    gen_clk(1);         // to update_dr
963
    tms_pad_i<=#1 0;
964
    gen_clk(1);         // to run_test_idle
965
  end
966
endtask
967 2 mohor
 
968
 
969 88 mohor
// Printing CRC
970
//always @ (posedge dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end)
971
always @ (posedge dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end or posedge dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_end)
972
begin
973
  #2;
974
  if (dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end & dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_end)
975
    tmp_crc = dbg_tb.i_dbg_top.i_dbg_crc32_d1_in.crc;
976
end
977 80 mohor
 
978
 
979 88 mohor
// Detecting CRC error
980
always @ (posedge dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_end)
981
begin
982
  #2;
983
  if (~dbg_tb.i_dbg_top.crc_match)
984
    begin
985
      $display("\t\tCRC ERROR !!!");
986
      $display("\t\tCRC needed (%0s) = 0x%0x , shifted_in = 0x%0x", test_text, tmp_crc, shifted_in_crc);
987 90 mohor
      $stop;
988 88 mohor
    end
989
end
990 80 mohor
 
991 88 mohor
 
992 90 mohor
 
993
// Detecting errors in counters
994
always @ (dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt or
995
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end or
996
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt or
997
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_end or
998
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt or
999
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end or
1000
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_en or
1001
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en or
1002
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en or
1003
          dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en or
1004
          dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1005
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt2 or
1006
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt3 or
1007
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt4
1008
          // dbg_tb.i_dbg_top.i_dbg_wb. or
1009
         )
1010
begin
1011
  if ((~dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end) & (
1012
                                                  dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en |
1013
                                                  dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en     |
1014
                                                  dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en      |
1015
                                                  dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1016
                                                 )
1017
     )
1018
    begin
1019
      $display("\n\n\t\t(%0t) ERROR in counters !!!", $time);
1020
      #10000;
1021
      $stop;
1022
    end
1023
 
1024
 
1025
 
1026
end
1027
 
1028
 
1029
 
1030
 
1031
 
1032 91 mohor
 
1033 80 mohor
endmodule // dbg_tb
1034
 
1035
 

powered by: WebSVN 2.1.0

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