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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_21/] [bench/] [verilog/] [dbg_tb.v] - Blame information for rev 90

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

powered by: WebSVN 2.1.0

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