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 99

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 99 mohor
// Revision 1.24  2004/01/15 10:47:13  mohor
47
// Working.
48
//
49 96 mohor
// Revision 1.23  2004/01/14 22:59:01  mohor
50
// Temp version.
51
//
52 95 mohor
// Revision 1.22  2004/01/13 11:28:30  mohor
53
// tmp version.
54
//
55 93 mohor
// Revision 1.21  2004/01/10 07:50:41  mohor
56
// temp version.
57
//
58 92 mohor
// Revision 1.20  2004/01/09 12:49:23  mohor
59
// tmp version.
60
//
61 91 mohor
// Revision 1.19  2004/01/08 17:53:12  mohor
62
// tmp version.
63
//
64 90 mohor
// Revision 1.18  2004/01/07 11:59:48  mohor
65
// temp4 version.
66
//
67 89 mohor
// Revision 1.17  2004/01/06 17:14:59  mohor
68
// temp3 version.
69
//
70 88 mohor
// Revision 1.16  2004/01/05 12:16:50  mohor
71
// tmp2 version.
72
//
73 87 mohor
// Revision 1.15  2003/12/23 14:26:01  mohor
74
// New version of the debug interface. Not finished, yet.
75
//
76 80 mohor
// Revision 1.14  2003/10/23 16:16:30  mohor
77
// CRC logic changed.
78
//
79 73 mohor
// Revision 1.13  2003/08/28 13:54:33  simons
80
// Three more chains added for cpu debug access.
81
//
82 63 simons
// Revision 1.12  2002/05/07 14:44:52  mohor
83
// mon_cntl_o signals that controls monitor mux added.
84
//
85 47 mohor
// Revision 1.11  2002/03/12 14:32:26  mohor
86
// Few outputs for boundary scan chain added.
87
//
88 38 mohor
// Revision 1.10  2002/03/08 15:27:08  mohor
89
// Structure changed. Hooks for jtag chain added.
90
//
91 36 mohor
// Revision 1.9  2001/10/19 11:39:20  mohor
92
// dbg_timescale.v changed to timescale.v This is done for the simulation of
93
// few different cores in a single project.
94
//
95 17 mohor
// Revision 1.8  2001/10/17 10:39:17  mohor
96
// bs_chain_o added.
97
//
98 15 mohor
// Revision 1.7  2001/10/16 10:10:18  mohor
99
// Signal names changed to lowercase.
100
//
101 13 mohor
// Revision 1.6  2001/10/15 09:52:50  mohor
102
// Wishbone interface added, few fixes for better performance,
103
// hooks for boundary scan testing added.
104
//
105 12 mohor
// Revision 1.5  2001/09/24 14:06:12  mohor
106
// Changes connected to the OpenRISC access (SPR read, SPR write).
107
//
108 11 mohor
// Revision 1.4  2001/09/20 10:10:29  mohor
109
// Working version. Few bugs fixed, comments added.
110
//
111 9 mohor
// Revision 1.3  2001/09/19 11:54:03  mohor
112
// Minor changes for simulation.
113
//
114 6 mohor
// Revision 1.2  2001/09/18 14:12:43  mohor
115
// Trace fixed. Some registers changed, trace simplified.
116
//
117 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
118
// Initial official release.
119
//
120 2 mohor
// Revision 1.3  2001/06/01 22:23:40  mohor
121
// This is a backup. It is not a fully working version. Not for use, yet.
122
//
123
// Revision 1.2  2001/05/18 13:10:05  mohor
124
// Headers changed. All additional information is now avaliable in the README.txt file.
125
//
126
// Revision 1.1.1.1  2001/05/18 06:35:15  mohor
127
// Initial release
128
//
129
//
130
 
131
 
132 17 mohor
`include "timescale.v"
133 2 mohor
`include "dbg_defines.v"
134 80 mohor
`include "dbg_wb_defines.v"
135 99 mohor
`include "dbg_cpu_defines.v"
136 80 mohor
//`include "dbg_tb_defines.v"
137 2 mohor
 
138
// Test bench
139
module dbg_tb;
140
 
141 80 mohor
parameter TCLK = 50;   // Clock half period (Clok period = 100 ns => 10 MHz)
142 2 mohor
 
143 80 mohor
reg   tms_pad_i;
144
reg   tck_pad_i;
145
reg   trst_pad_i;
146
reg   tdi_pad_i;
147
wire  tdo_pad_o;
148
wire  tdo_padoe_o;
149 2 mohor
 
150 80 mohor
wire  shift_dr_o;
151
wire  pause_dr_o;
152
wire  update_dr_o;
153 2 mohor
 
154 80 mohor
wire  extest_select_o;
155
wire  sample_preload_select_o;
156
wire  mbist_select_o;
157
wire  debug_select_o;
158 2 mohor
 
159 80 mohor
// WISHBONE common signals
160
reg   wb_rst_i;
161
reg   wb_clk_i;
162
 
163
// WISHBONE master interface
164
wire [31:0] wb_adr_o;
165
wire [31:0] wb_dat_o;
166
wire [31:0] wb_dat_i;
167
wire        wb_cyc_o;
168
wire        wb_stb_o;
169
wire  [3:0] wb_sel_o;
170
wire        wb_we_o;
171
wire        wb_ack_i;
172
wire        wb_cab_o;
173
wire        wb_err_i;
174
wire  [2:0] wb_cti_o;
175
wire  [1:0] wb_bte_o;
176 2 mohor
 
177 87 mohor
// Text used for easier debugging
178 99 mohor
reg [199:0] test_text;
179 88 mohor
reg   [2:0] last_wb_cmd;
180 99 mohor
reg [199:0] last_wb_cmd_text;
181 88 mohor
reg  [31:0] wb_data;
182 2 mohor
 
183
 
184 12 mohor
 
185 80 mohor
wire  tdo_o;
186 12 mohor
 
187 80 mohor
wire  debug_tdi_i;
188
wire  bs_chain_tdi_i;
189
wire  mbist_tdi_i;
190 73 mohor
 
191 80 mohor
reg   test_enabled;
192 73 mohor
 
193 80 mohor
reg [31:0] result;
194 2 mohor
 
195 99 mohor
reg  crc_out_en;
196
reg  crc_out_shift;
197
wire crc_out;
198 88 mohor
 
199 99 mohor
 
200
 
201 80 mohor
wire tdo;
202 73 mohor
 
203 80 mohor
assign tdo = tdo_padoe_o? tdo_pad_o : 1'hz;
204 73 mohor
 
205 80 mohor
// Connecting TAP module
206
tap_top i_tap_top (
207
                    .tms_pad_i(tms_pad_i),
208
                    .tck_pad_i(tck_pad_i),
209
                    .trst_pad_i(!trst_pad_i),
210
                    .tdi_pad_i(tdi_pad_i),
211
                    .tdo_pad_o(tdo_pad_o),
212
                    .tdo_padoe_o(tdo_padoe_o),
213 38 mohor
 
214 80 mohor
                    // TAP states
215
                    .shift_dr_o(shift_dr_o),
216
                    .pause_dr_o(pause_dr_o),
217
                    .update_dr_o(update_dr_o),
218 38 mohor
 
219 80 mohor
                    // Select signals for boundary scan or mbist
220
                    .extest_select_o(extest_select_o),
221
                    .sample_preload_select_o(sample_preload_select_o),
222
                    .mbist_select_o(mbist_select_o),
223
                    .debug_select_o(debug_select_o),
224 2 mohor
 
225 80 mohor
                    // TDO signal that is connected to TDI of sub-modules.
226
                    .tdo_o(tdo_o),
227 38 mohor
 
228 80 mohor
                    // TDI signals from sub-modules
229
                    .debug_tdi_i(debug_tdi_i),        // from debug module
230
                    .bs_chain_tdi_i(bs_chain_tdi_i),  // from Boundary Scan Chain
231
                    .mbist_tdi_i(mbist_tdi_i)         // from Mbist Chain
232 73 mohor
 
233 38 mohor
               );
234 2 mohor
 
235
 
236 99 mohor
// Connecting debug top module
237 80 mohor
dbg_top i_dbg_top  (
238
                    .tck_i(tck_pad_i),
239
                    .tdi_i(tdo_o),
240
                    .tdo_o(debug_tdi_i),
241
 
242
                    // TAP states
243
                    .shift_dr_i   (shift_dr_o),
244
                    .pause_dr_i   (pause_dr_o),
245
                    .update_dr_i  (update_dr_o),
246
 
247
                    // Instructions
248
                    .debug_select_i(debug_select_o),
249 12 mohor
 
250 80 mohor
                    // WISHBONE common signals
251
                    .wb_rst_i      (wb_rst_i),
252
                    .wb_clk_i      (wb_clk_i),
253
 
254
                    // WISHBONE master interface
255
                    .wb_adr_o      (wb_adr_o),
256
                    .wb_dat_o      (wb_dat_o),
257
                    .wb_dat_i      (wb_dat_i),
258
                    .wb_cyc_o      (wb_cyc_o),
259
                    .wb_stb_o      (wb_stb_o),
260
                    .wb_sel_o      (wb_sel_o),
261
                    .wb_we_o       (wb_we_o),
262
                    .wb_ack_i      (wb_ack_i),
263
                    .wb_cab_o      (wb_cab_o),
264
                    .wb_err_i      (wb_err_i),
265
                    .wb_cti_o      (wb_cti_o),
266
                    .wb_bte_o      (wb_bte_o)
267
                   );
268 12 mohor
 
269
 
270 99 mohor
 
271
// Connecting CRC module that calculates CRC that is shifted into debug
272
dbg_crc32_d1 crc32_bench_out
273
             (
274
              .data       (tdi_pad_i),
275
              .enable     (crc_out_en),
276
              .shift      (crc_out_shift),
277
              .rst        (wb_rst_i),
278
              .sync_rst   (update_dr_o),
279
              .crc_out    (crc_out),
280
              .clk        (tck_pad_i),
281
              .crc_match  ()
282
             );
283
 
284
 
285
 
286
 
287 80 mohor
wb_slave_behavioral wb_slave
288
                   (
289
                    .CLK_I(wb_clk_i),
290
                    .RST_I(wb_rst_i),
291
                    .ACK_O(wb_ack_i),
292
                    .ADR_I(wb_adr_o),
293
                    .CYC_I(wb_cyc_o),
294
                    .DAT_O(wb_dat_i),
295
                    .DAT_I(wb_dat_o),
296
                    .ERR_O(wb_err_i),
297
                    .RTY_O(),      // NOT USED for now!
298
                    .SEL_I(wb_sel_o),
299
                    .STB_I(wb_stb_o),
300
                    .WE_I (wb_we_o),
301
                    .CAB_I(1'b0)
302
                   );
303 2 mohor
 
304
 
305 80 mohor
// Initial values
306 2 mohor
initial
307
begin
308 80 mohor
  test_enabled = 1'b0;
309 99 mohor
  crc_out_en = 1'b0;
310
  crc_out_shift = 1'b0;
311 88 mohor
  wb_data = 32'h01234567;
312 80 mohor
  trst_pad_i = 1'b1;
313
  tms_pad_i = 1'hz;
314
  tck_pad_i = 1'hz;
315
  tdi_pad_i = 1'hz;
316
 
317
  #100;
318
  trst_pad_i = 1'b0;
319
  #100;
320
  trst_pad_i = 1'b1;
321
  #1 test_enabled<=#1 1'b1;
322 2 mohor
end
323
 
324 80 mohor
initial
325
begin
326
  wb_rst_i = 1'b0;
327
  #1000;
328
  wb_rst_i = 1'b1;
329
  #1000;
330
  wb_rst_i = 1'b0;
331 2 mohor
 
332 80 mohor
  // Initial values for wishbone slave model
333 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
334 80 mohor
end
335
 
336
initial
337 2 mohor
begin
338 80 mohor
  wb_clk_i = 1'b0;
339
  forever #5 wb_clk_i = ~wb_clk_i;
340 2 mohor
end
341
 
342 80 mohor
always @ (posedge test_enabled)
343
begin
344 2 mohor
 
345 80 mohor
  $display("//////////////////////////////////////////////////////////////////");
346
  $display("//                                                              //");
347
  $display("//  (%0t) dbg_tb starting                                     //", $time);
348
  $display("//                                                              //");
349
  $display("//////////////////////////////////////////////////////////////////");
350 2 mohor
 
351 80 mohor
  initialize_memory(32'h12340000, 32'h00100000);  // Initialize 0x100000 bytes starting from address 0x12340000
352 2 mohor
 
353 80 mohor
  reset_tap;
354 95 mohor
 
355
  #500;
356 80 mohor
  goto_run_test_idle;
357 12 mohor
 
358 80 mohor
  // Testing read and write to internal registers
359
  #10000;
360
  set_instruction(`IDCODE);
361
  read_id_code;
362 12 mohor
 
363 80 mohor
  set_instruction(`DEBUG);
364
  #10000;
365 2 mohor
 
366 99 mohor
  chain_select(`WISHBONE_SCAN_CHAIN, 1'b0);   // {chain, gen_crc_err}
367 12 mohor
 
368 80 mohor
//  #10000;
369
//  xxx(4'b1001, 32'he579b242);
370 12 mohor
 
371 80 mohor
  #10000;
372 2 mohor
 
373 99 mohor
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "abc 1"); // {command, ready, addr, length, gen_crc_err, result, text}
374
//  debug_wishbone(`WB_READ8, 1'b0, 32'h12345679, 16'h4, 1'b0, result, "abc 2"); // {command, ready, addr, length, gen_crc_err, result, text}
375
//  debug_wishbone(`WB_READ8, 1'b0, 32'h1234567a, 16'h4, 1'b0, result, "abc 3"); // {command, ready, addr, length, gen_crc_err, result, text}
376 88 mohor
//
377 99 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "abc 4"); // {command, ready, addr, length, gen_crc_err, result, text}
378
//  debug_wishbone(`WB_READ16, 1'b0, 32'h1234567a, 16'h4, 1'b0, result, "abc 5"); // {command, ready, addr, length, gen_crc_err, result, text}
379 88 mohor
//
380 99 mohor
  debug_wishbone(`WB_READ32, 1'b0, 32'h12345678, 16'h4, 1'b0, result, "read32 1"); // {command, ready, addr, length, gen_crc_err, result, text}
381 88 mohor
//
382 99 mohor
//  debug_wishbone(`WB_READ16, 1'b0, 32'h12345679, 16'h4, 1'b0, result, "abc 6"); // {command, ready, addr, length, gen_crc_err, result, text}
383 2 mohor
 
384 80 mohor
  #10000;
385
//  xxx(4'b1001, 32'he579b242);
386
 
387 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12345678, 16'h4, 1'b0, result, "read32 2"); // {command, ready, addr, length, gen_crc_err, result, text}
388 87 mohor
 
389
  #10000;
390 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h55, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
391 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, result, "read32 3"); // {command, ready, addr, length, gen_crc_err, result, text}
392 80 mohor
 
393
  #10000;
394 96 mohor
  wb_slave.cycle_response(`ERR_RESPONSE, 9'h03, 8'h2);   // (`ERR_RESPONSE, wbs_waits, wbs_retries);
395 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12346668, 16'h4, 1'b0, result, "read32 4"); // {command, ready, addr, length, gen_crc_err, result, text}
396 80 mohor
 
397
  #10000;
398 99 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, result, "status 1"); // {command, ready, addr, length, gen_crc_err, result, text}
399 80 mohor
 
400 87 mohor
  #10000;
401 99 mohor
  debug_wishbone(`WB_STATUS, 1'b0, 32'h0, 16'h0, 1'b0, result, "status 2"); // {command, ready, addr, length, gen_crc_err, result, text}
402 80 mohor
 
403 87 mohor
  #10000;
404 96 mohor
  wb_slave.cycle_response(`ACK_RESPONSE, 9'h012, 8'h2);   // (`ACK_RESPONSE, wbs_waits, wbs_retries);
405 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12347778, 16'hc, 1'b0, result, "read32 5"); // {command, ready, addr, length, gen_crc_err, result, text}
406 80 mohor
 
407 87 mohor
  #10000;
408 99 mohor
  debug_wishbone(`WB_WRITE32, 1'b0, 32'h12346668, 16'h8, 1'b0, result, "wr32 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
409 87 mohor
 
410
  #10000;
411 99 mohor
  debug_wishbone(`WB_WRITE16, 1'b0, 32'h12344446, 16'h8, 1'b0, result, "wr16 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
412 87 mohor
 
413 88 mohor
  #10000;
414 99 mohor
  debug_wishbone(`WB_WRITE8, 1'b0, 32'h1234010e, 16'h8, 1'b0, result, "wr8 len8"); // {command, ready, addr, length, gen_crc_err, result, text}
415 87 mohor
 
416 88 mohor
  #10000;
417 99 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, result, "go 1"); // {command, ready, addr, length, gen_crc_err, result, text}
418 87 mohor
 
419 89 mohor
  #10000;
420 99 mohor
  debug_wishbone(`WB_READ32, 1'b1, 32'h12340100, 16'hc, 1'b0, result, "read32 6"); // {command, ready, addr, length, gen_crc_err, result, text}
421
//  debug_wishbone(`WB_READ32, 1'b1, 32'h12340100, 16'hfffc, 1'b0, result, "read32 6"); // {command, ready, addr, length, gen_crc_err, result, text}
422 88 mohor
 
423 89 mohor
  #10000;
424 99 mohor
//  debug_wishbone(`WB_READ16, 1'b1, 32'h12340102, 16'he, 1'b0, result, "read16 7"); // {command, ready, addr, length, gen_crc_err, result, text}
425
//  debug_wishbone(`WB_READ16, 1'b1, 32'h12340102, 16'hfffe, 1'b0, result, "read16 7"); // {command, ready, addr, length, gen_crc_err, result, text}
426 88 mohor
 
427 90 mohor
  #10000;
428 99 mohor
//  debug_wishbone(`WB_READ8, 1'b1, 32'h12348804, 16'h6, 1'b0, result, "read8 8"); // {command, ready, addr, length, gen_crc_err, result, text}  
429
//  debug_wishbone(`WB_READ8, 1'b1, 32'h12348804, 16'hfffc, 1'b0, result, "read8 8"); // {command, ready, addr, length, gen_crc_err, result, text}
430 89 mohor
 
431 90 mohor
  #10000;
432 99 mohor
  debug_wishbone(`WB_GO, 1'b0, 32'h0, 16'h0, 1'b0, result, "go 2"); // {command, ready, addr, length, gen_crc_err, result, text}
433 89 mohor
 
434 99 mohor
  #10000;
435
  chain_select(`CPU_DEBUG_CHAIN, 1'b0);   // {chain, gen_crc_err}
436 89 mohor
 
437 99 mohor
  #10000;
438
  debug_cpu(`CPU_WRITE_REG, 32'h00000001, 32'h0, 1'b0, result, "cpu_write_reg"); // {command, addr, data, gen_crc_err, result, text}
439 90 mohor
 
440 99 mohor
  #10000;
441
  debug_cpu(`CPU_GO, 32'h0, 32'hff, 1'b0, result, "go cpu"); // {command, addr, data, gen_crc_err, result, text}
442 90 mohor
 
443 99 mohor
 
444 80 mohor
/*
445
  // Testing read and write to CPU0 registers
446
  #10000;
447
  set_instruction(`CHAIN_SELECT);
448
  chain_select(`CPU_DEBUG_CHAIN_0, 8'h12);  // {chain, crc}
449
  set_instruction(`DEBUG);
450
  WriteCPURegister(32'h11001100, 32'h00110011, 8'h86);  // {data, addr, crc}
451
 
452
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
453
  ReadCPURegister(32'h11001100, 8'hdb);                 // {addr, crc}
454
*/
455
  #5000 gen_clk(1);            // One extra TCLK for debugging purposes
456 95 mohor
  $display("\n\nSimulation end.");
457 5 mohor
  #1000 $stop;
458 80 mohor
 
459 2 mohor
end
460
 
461 80 mohor
 
462
task initialize_memory;
463
  input [31:0] start_addr;
464
  input [31:0] length;
465
  integer i;
466
  reg [31:0] addr;
467
  begin
468 96 mohor
//    for (i=0; i<length; i=i+4)    // inverted address
469
//      begin
470
//        addr = start_addr + i;
471
//        wb_slave.wr_mem(addr, {addr[7:0], addr[15:8], addr[23:16], addr[31:24]}, 4'hf);    // adr, data, sel
472
//      end
473 80 mohor
    for (i=0; i<length; i=i+4)
474
      begin
475
        addr = start_addr + i;
476 96 mohor
        wb_slave.wr_mem(addr, {addr[7:0], addr[7:0]+2'd1, addr[7:0]+2'd2, addr[7:0]+2'd3}, 4'hf);    // adr, data, sel
477 80 mohor
      end
478
  end
479
endtask
480
 
481
 
482
 
483 2 mohor
// Generation of the TCLK signal
484 80 mohor
task gen_clk;
485
  input [7:0] num;
486 2 mohor
  integer i;
487
  begin
488 80 mohor
    for(i=0; i<num; i=i+1)
489 2 mohor
      begin
490 80 mohor
        #TCLK tck_pad_i<=1;
491
        #TCLK tck_pad_i<=0;
492 2 mohor
      end
493
  end
494
endtask
495
 
496
 
497
// TAP reset
498 80 mohor
task reset_tap;
499 2 mohor
  begin
500 80 mohor
    $display("(%0t) Task reset_tap", $time);
501
    tms_pad_i<=#1 1'b1;
502 95 mohor
    gen_clk(5);
503 2 mohor
  end
504
endtask
505
 
506
 
507
// Goes to RunTestIdle state
508 80 mohor
task goto_run_test_idle;
509 2 mohor
  begin
510 80 mohor
    $display("(%0t) Task goto_run_test_idle", $time);
511
    tms_pad_i<=#1 1'b0;
512
    gen_clk(1);
513 2 mohor
  end
514
endtask
515
 
516
 
517
// sets the instruction to the IR register and goes to the RunTestIdle state
518 80 mohor
task set_instruction;
519
  input [3:0] instr;
520 2 mohor
  integer i;
521
 
522
  begin
523 80 mohor
    $display("(%0t) Task set_instruction", $time);
524
    tms_pad_i<=#1 1;
525
    gen_clk(2);
526
    tms_pad_i<=#1 0;
527
    gen_clk(2);  // we are in shiftIR
528 2 mohor
 
529
    for(i=0; i<`IR_LENGTH-1; i=i+1)
530
    begin
531 80 mohor
      tdi_pad_i<=#1 instr[i];
532
      gen_clk(1);
533 2 mohor
    end
534
 
535 80 mohor
    tdi_pad_i<=#1 instr[i]; // last shift
536
    tms_pad_i<=#1 1;        // going out of shiftIR
537
    gen_clk(1);
538 90 mohor
    tdi_pad_i<=#1 'hz;    // tri-state
539 80 mohor
    gen_clk(1);
540
    tms_pad_i<=#1 0;
541
    gen_clk(1);       // we are in RunTestIdle
542 2 mohor
  end
543
endtask
544
 
545
 
546 80 mohor
// Reads the ID code
547
task read_id_code;
548
  begin
549
    $display("(%0t) Task read_id_code", $time);
550
    tms_pad_i<=#1 1;
551
    gen_clk(1);
552
    tms_pad_i<=#1 0;
553
    gen_clk(2);  // we are in shiftDR
554
 
555
    tdi_pad_i<=#1 0;
556
    gen_clk(31);
557
 
558
    tms_pad_i<=#1 1;        // going out of shiftIR
559
    gen_clk(1);
560
 
561
    tdi_pad_i<=#1 'hz; // tri-state
562
    gen_clk(1);
563
    tms_pad_i<=#1 0;
564
    gen_clk(1);       // we are in RunTestIdle
565
  end
566
endtask
567
 
568
 
569 2 mohor
// sets the selected scan chain and goes to the RunTestIdle state
570 80 mohor
task chain_select;
571
  input [3:0]  data;
572 99 mohor
  input        gen_crc_err;
573 2 mohor
  integer i;
574
 
575
  begin
576 99 mohor
    case (data)
577
      `CPU_DEBUG_CHAIN      : $display("(%0t) Task chain_select (CPU_DEBUG_CHAIN, gen_crc_err=%0d)", $time, gen_crc_err);
578
      `WISHBONE_SCAN_CHAIN  : $display("(%0t) Task chain_select (WISHBONE_SCAN_CHAIN gen_crc_err=%0d)", $time, gen_crc_err);
579
      default               : $display("(%0t) Task chain_select (ERROR!!! Unknown chain selected)", $time);
580
    endcase
581
 
582 80 mohor
    tms_pad_i<=#1 1;
583
    gen_clk(1);
584
    tms_pad_i<=#1 0;
585
    gen_clk(2);  // we are in shiftDR
586 2 mohor
 
587 99 mohor
    crc_out_en = 1; // Enable CRC calculation
588
 
589 80 mohor
    tdi_pad_i<=#1 1'b1; // chain_select bit
590
    gen_clk(1);
591
 
592 2 mohor
    for(i=0; i<`CHAIN_ID_LENGTH; i=i+1)
593
    begin
594 80 mohor
      tdi_pad_i<=#1 data[i];
595
      gen_clk(1);
596 2 mohor
    end
597
 
598 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
599
    crc_out_shift = 1;  // Enable CRC shifting
600
 
601
    for(i=31; i>=0; i=i-1)
602 2 mohor
    begin
603 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
604
        tdi_pad_i<=#1 ~crc_out;   // error crc
605
      else
606
        tdi_pad_i<=#1 crc_out;    // ok crc
607
 
608 80 mohor
      gen_clk(1);
609 2 mohor
    end
610
 
611 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
612
 
613
    tdi_pad_i<=#1 'hz;  // tri-state
614
 
615 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
616
 
617
 
618
    for(i=0; i<`CRC_LEN -1; i=i+1)
619
      gen_clk(1);
620
 
621
    tms_pad_i<=#1 1;
622
    gen_clk(1);         // to exit1_dr
623
 
624
    tdi_pad_i<=#1 'hz;  // tri-state
625
    tms_pad_i<=#1 1;
626
    gen_clk(1);         // to update_dr
627
    tms_pad_i<=#1 0;
628
    gen_clk(1);         // to run_test_idle
629 2 mohor
  end
630 99 mohor
endtask   // chain_select
631 2 mohor
 
632
 
633 87 mohor
 
634
 
635
 
636
 
637
 
638 80 mohor
task debug_wishbone;
639
  input [2:0]   command;
640 87 mohor
  input         ready;
641 80 mohor
  input [31:0]  addr;
642
  input [15:0]  length;
643 99 mohor
  input         gen_crc_err;
644 80 mohor
  output [31:0] result;
645 87 mohor
  input [99:0]  text;
646 80 mohor
  integer i;
647
 
648 2 mohor
  begin
649 80 mohor
   $write("(%0t) Task debug_wishbone: ", $time);
650 2 mohor
 
651 87 mohor
    test_text = text;
652 36 mohor
 
653 80 mohor
    case (command)
654
      `WB_STATUS   :
655
        begin
656 99 mohor
          $display("wb_status (gen_crc_err=%0d (%0s))", gen_crc_err, text);
657
          debug_wishbone_status(command, gen_crc_err);
658 88 mohor
          last_wb_cmd = `WB_STATUS;  last_wb_cmd_text = "WB_STATUS";
659 80 mohor
        end
660
      `WB_READ8    :
661
        begin
662 99 mohor
          $display("wb_read8 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
663
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
664 88 mohor
          last_wb_cmd = `WB_READ8;  last_wb_cmd_text = "WB_READ8";
665 80 mohor
        end
666
      `WB_READ16   :
667
        begin
668 99 mohor
          $display("wb_read16 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
669
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
670 88 mohor
          last_wb_cmd = `WB_READ16;  last_wb_cmd_text = "WB_READ16";
671 80 mohor
        end
672
      `WB_READ32   :
673
        begin
674 99 mohor
          $display("wb_read32 (ready=%0d, adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", ready, addr, length, gen_crc_err, text);
675
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
676 88 mohor
          last_wb_cmd = `WB_READ32;  last_wb_cmd_text = "WB_READ32";
677 80 mohor
        end
678
      `WB_WRITE8   :
679
        begin
680 99 mohor
          $display("wb_write8 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
681
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
682 88 mohor
          last_wb_cmd = `WB_WRITE8;  last_wb_cmd_text = "WB_WRITE8";
683 80 mohor
        end
684
      `WB_WRITE16  :
685
        begin
686 99 mohor
          $display("wb_write16 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
687
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
688 88 mohor
          last_wb_cmd = `WB_WRITE16;  last_wb_cmd_text = "WB_WRITE16";
689 80 mohor
        end
690
      `WB_WRITE32  :
691
        begin
692 99 mohor
          $display("wb_write32 (adr=0x%0x, length=0x%0x, gen_crc_err=%0d (%0s))", addr, length, gen_crc_err, text);
693
          debug_wishbone_set_addr(command, ready, addr, length, gen_crc_err);
694 88 mohor
          last_wb_cmd = `WB_WRITE32;  last_wb_cmd_text = "WB_WRITE32";
695 80 mohor
        end
696
      `WB_GO       :
697
        begin
698 99 mohor
          $display("wb_go, gen_crc_err=%0d (%0s))", gen_crc_err, text);
699
          debug_wishbone_go(command, gen_crc_err);
700
//          $display("wb_go_tmp, gen_crc_err=0x%0x (%0s))", gen_crc_err, text);
701 93 mohor
//          debug_wishbone_go_tmp(command, crc);
702 88 mohor
          last_wb_cmd = `WB_GO;  last_wb_cmd_text = "WB_GO";
703 80 mohor
        end
704
    endcase
705 2 mohor
  end
706 87 mohor
endtask       // debug_wishbone
707 2 mohor
 
708
 
709 80 mohor
 
710
 
711
 
712
 
713 87 mohor
task debug_wishbone_set_addr;
714 80 mohor
  input [2:0]   command;
715 99 mohor
  input         wait_for_wb_ready;    // igor !!! Change this since access only occurs in the "go" stage. Add condition "fifo_empty".
716 80 mohor
  input [31:0]  addr;
717
  input [15:0]  length;
718 99 mohor
  input         gen_crc_err;
719 80 mohor
  integer i;
720
 
721
  begin
722 87 mohor
    $display("(%0t) Task debug_wishbone_set_addr: ", $time);
723 80 mohor
 
724
    tms_pad_i<=#1 1;
725
    gen_clk(1);
726
    tms_pad_i<=#1 0;
727
    gen_clk(2);  // we are in shiftDR
728
 
729 99 mohor
    crc_out_en = 1; // Enable CRC calculation
730
 
731 80 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
732
    gen_clk(1);
733
 
734 88 mohor
    for(i=2; i>=0; i=i-1)
735 80 mohor
    begin
736
      tdi_pad_i<=#1 command[i]; // command
737
      gen_clk(1);
738
    end
739
 
740 88 mohor
    for(i=31; i>=0; i=i-1)       // address
741 80 mohor
    begin
742
      tdi_pad_i<=#1 addr[i];
743
      gen_clk(1);
744
    end
745 87 mohor
 
746 88 mohor
    for(i=15; i>=0; i=i-1)       // length
747 80 mohor
    begin
748
      tdi_pad_i<=#1 length[i];
749
      gen_clk(1);
750
    end
751
 
752 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
753
    crc_out_shift = 1;  // Enable CRC shifting
754
 
755 88 mohor
    for(i=31; i>=0; i=i-1)
756 80 mohor
    begin
757 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
758
        tdi_pad_i<=#1 ~crc_out;   // error crc
759
      else
760
        tdi_pad_i<=#1 crc_out;    // ok crc
761
 
762 80 mohor
      gen_clk(1);
763
    end
764
 
765 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
766
 
767 92 mohor
    tdi_pad_i<=#1 'hz;
768 87 mohor
    if (wait_for_wb_ready)
769
      begin
770
        gen_clk(`STATUS_LEN -1);   // Generating 4 clocks to read out status. Going to pause_dr at the end
771
        tms_pad_i<=#1 1;
772
        gen_clk(1);       // to exit1_dr
773
        tms_pad_i<=#1 0;
774
        gen_clk(1);       // to pause_dr
775
 
776
        while (dbg_tb.tdo_pad_o)     // waiting for wb to send "ready" 
777
        begin
778
          gen_clk(1);       // staying in pause_dr
779
        end
780
 
781
        tms_pad_i<=#1 1;
782
        gen_clk(1);       // to exit2_dr
783
        tms_pad_i<=#1 0;
784
        gen_clk(1);       // to shift_dr
785
      end
786
    else
787
      gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
788 80 mohor
 
789 88 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
790 80 mohor
    begin
791
      gen_clk(1);
792
    end
793
 
794
    tms_pad_i<=#1 1;
795
    gen_clk(1);         // to exit1_dr
796
 
797
    tms_pad_i<=#1 1;
798
    gen_clk(1);         // to update_dr
799
    tms_pad_i<=#1 0;
800
    gen_clk(1);         // to run_test_idle
801
  end
802 87 mohor
endtask       // debug_wishbone_set_addr
803 80 mohor
 
804
 
805
 
806
 
807
 
808 88 mohor
task debug_wishbone_status;
809
  input [2:0]   command;
810 99 mohor
  input         gen_crc_err;
811 88 mohor
  integer i;
812
 
813
  begin
814
    $display("(%0t) Task debug_wishbone_status: ", $time);
815 80 mohor
 
816 88 mohor
    tms_pad_i<=#1 1;
817
    gen_clk(1);
818
    tms_pad_i<=#1 0;
819
    gen_clk(2);  // we are in shiftDR
820 87 mohor
 
821 99 mohor
    crc_out_en = 1; // Enable CRC calculation
822
 
823 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
824
    gen_clk(1);
825 87 mohor
 
826 88 mohor
    for(i=2; i>=0; i=i-1)
827
    begin
828
      tdi_pad_i<=#1 command[i]; // command
829
      gen_clk(1);
830
    end
831 87 mohor
 
832 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
833
    crc_out_shift = 1;  // Enable CRC shifting
834
 
835
    for(i=31; i>=0; i=i-1)
836 88 mohor
    begin
837 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
838
        tdi_pad_i<=#1 ~crc_out;   // error crc
839
      else
840
        tdi_pad_i<=#1 crc_out;    // ok crc
841
 
842 88 mohor
      gen_clk(1);
843
    end
844
 
845 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
846
 
847 92 mohor
    tdi_pad_i<=#1 1'hz;
848 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
849
 
850
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
851
    begin
852
      gen_clk(1);
853
    end
854
 
855
    tms_pad_i<=#1 1;
856
    gen_clk(1);         // to exit1_dr
857
 
858
    tms_pad_i<=#1 1;
859
    gen_clk(1);         // to update_dr
860
    tms_pad_i<=#1 0;
861
    gen_clk(1);         // to run_test_idle
862
  end
863
endtask       // debug_wishbone_status
864
 
865
 
866
 
867
 
868
task debug_wishbone_go;
869
  input [2:0]   command;
870 99 mohor
  input         gen_crc_err;
871 90 mohor
  integer i;
872
  reg   [4:0]   pointer;
873
 
874 2 mohor
  begin
875 88 mohor
    $display("(%0t) Task debug_wishbone_go (previous command was %0s): ", $time, last_wb_cmd_text);
876
 
877 80 mohor
    tms_pad_i<=#1 1;
878
    gen_clk(1);
879
    tms_pad_i<=#1 0;
880
    gen_clk(2);  // we are in shiftDR
881 2 mohor
 
882 99 mohor
    crc_out_en = 1; // Enable CRC calculation
883
 
884 88 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
885 80 mohor
    gen_clk(1);
886 88 mohor
 
887
    for(i=2; i>=0; i=i-1)
888
    begin
889
      tdi_pad_i<=#1 command[i]; // command
890
      gen_clk(1);
891
    end
892
 
893
 
894
    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.
895
      begin
896 90 mohor
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.len << 3); i=i+1)
897 88 mohor
          begin
898 90 mohor
            if (!(i%32))
899 88 mohor
              begin
900 90 mohor
                wb_data = wb_data + 32'h11111111;
901
                $display("\t\twb_data = 0x%x", wb_data);
902 88 mohor
              end
903 90 mohor
            pointer = 31-i[4:0];
904
            tdi_pad_i<=#1 wb_data[pointer];
905
            gen_clk(1);
906
 
907 88 mohor
          end
908
      end
909
 
910 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
911
    crc_out_shift = 1;  // Enable CRC shifting
912 88 mohor
 
913 99 mohor
    for(i=31; i>=0; i=i-1)
914 88 mohor
    begin
915 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
916
        tdi_pad_i<=#1 ~crc_out;   // error crc
917
      else
918
        tdi_pad_i<=#1 crc_out;    // ok crc
919
 
920 88 mohor
      gen_clk(1);
921
    end
922
 
923 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
924
 
925 92 mohor
    tdi_pad_i<=#1 1'hz;
926 90 mohor
 
927
 
928
 
929
    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.
930
      begin
931 95 mohor
        $display("\t\tGenerating %0d clocks to read %0d data bytes.", dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit, dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit>>3);
932
        for (i=0; i<(dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_limit); i=i+1)
933 92 mohor
          gen_clk(1);
934 90 mohor
      end
935
 
936
 
937 88 mohor
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
938
 
939
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
940
    begin
941
      gen_clk(1);
942
    end
943
 
944
    tms_pad_i<=#1 1;
945
    gen_clk(1);         // to exit1_dr
946
 
947
    tms_pad_i<=#1 1;
948
    gen_clk(1);         // to update_dr
949 80 mohor
    tms_pad_i<=#1 0;
950 88 mohor
    gen_clk(1);         // to run_test_idle
951 2 mohor
  end
952 88 mohor
endtask       // debug_wishbone_go
953 2 mohor
 
954
 
955 88 mohor
 
956
 
957 99 mohor
task debug_cpu;
958
  input [2:0]   command;
959
  input [31:0]  addr;
960
  input [31:0]  data;
961
  input         gen_crc_err;
962
  output [31:0] result;
963
  input [199:0]  text;
964
  integer i;
965
 
966
  begin
967
   $write("(%0t) Task debug_cpu: ", $time);
968 88 mohor
 
969 99 mohor
    test_text = text;
970
 
971
    case (command)
972
//      `WB_STATUS   : 
973
//        begin
974
//          $display("wb_status (gen_crc_err=%0d (%0s))", gen_crc_err, text);
975
//          debug_wishbone_status(command, gen_crc_err);
976
//          last_wb_cmd = `WB_STATUS;  last_wb_cmd_text = "WB_STATUS";
977
//        end 
978
      `CPU_READ_REG   :
979
        begin
980
          $display("cpu_read_reg (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
981
          debug_cpu_set_addr(command, addr, gen_crc_err);
982
          last_wb_cmd = `CPU_READ_REG;  last_wb_cmd_text = "CPU_READ_REG";
983
        end
984
      `CPU_WRITE_REG  :
985
        begin
986
          $display("cpu_write_reg (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
987
          debug_cpu_set_addr(command, addr, gen_crc_err);
988
          last_wb_cmd = `CPU_WRITE_REG;  last_wb_cmd_text = "CPU_WRITE_REG";
989
        end
990
      `CPU_READ8      :
991
        begin
992
          $display("cpu_read8 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
993
          debug_cpu_set_addr(command, addr, gen_crc_err);
994
          last_wb_cmd = `CPU_READ8;  last_wb_cmd_text = "CPU_READ8";
995
        end
996
      `CPU_READ32     :
997
        begin
998
          $display("cpu_read32 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
999
          debug_cpu_set_addr(command, addr, gen_crc_err);
1000
          last_wb_cmd = `CPU_READ32;  last_wb_cmd_text = "CPU_READ32";
1001
        end
1002
      `CPU_WRITE8     :
1003
        begin
1004
          $display("cpu_write8 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1005
          debug_cpu_set_addr(command, addr, gen_crc_err);
1006
          last_wb_cmd = `CPU_WRITE8;  last_wb_cmd_text = "CPU_WRITE8";
1007
        end
1008
      `CPU_WRITE32    :
1009
        begin
1010
          $display("cpu_write32 (adr=0x%0x, gen_crc_err=%0d (%0s))", addr, gen_crc_err, text);
1011
          debug_cpu_set_addr(command, addr, gen_crc_err);
1012
          last_wb_cmd = `CPU_WRITE32;  last_wb_cmd_text = "CPU_WRITE32";
1013
        end
1014
      `CPU_GO         :
1015
        begin
1016
          $display("cpu_go, data = 0x%0x, gen_crc_err=%0d (%0s))", data, gen_crc_err, text);
1017
          debug_cpu_go(command, data, gen_crc_err);
1018
          last_wb_cmd = `CPU_GO;  last_wb_cmd_text = "CPU_GO";
1019
        end
1020
      default     :
1021
        begin
1022
          $display("\t\tERROR: Non-existing command while debugging %0s", gen_crc_err, text);
1023
          $stop;
1024
        end
1025
    endcase
1026
  end
1027
endtask       // debug_cpu
1028
 
1029
 
1030
 
1031
task debug_cpu_set_addr;
1032 93 mohor
  input [2:0]   command;
1033 99 mohor
  input [31:0]  addr;
1034
  input         gen_crc_err;
1035 93 mohor
  integer i;
1036 99 mohor
 
1037
  begin
1038
    $display("(%0t) Task debug_cpu_set_addr: ", $time);
1039
 
1040
    tms_pad_i<=#1 1;
1041
    gen_clk(1);
1042
    tms_pad_i<=#1 0;
1043
    gen_clk(2);  // we are in shiftDR
1044
 
1045
    crc_out_en = 1; // Enable CRC calculation
1046
 
1047
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
1048
    gen_clk(1);
1049
 
1050
    for(i=2; i>=0; i=i-1)
1051
    begin
1052
      tdi_pad_i<=#1 command[i]; // command
1053
      gen_clk(1);
1054
    end
1055
 
1056
    for(i=31; i>=0; i=i-1)       // address
1057
    begin
1058
      tdi_pad_i<=#1 addr[i];
1059
      gen_clk(1);
1060
    end
1061 93 mohor
 
1062 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
1063
    crc_out_shift = 1;  // Enable CRC shifting
1064
 
1065
    for(i=31; i>=0; i=i-1)
1066
    begin
1067
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1068
        tdi_pad_i<=#1 ~crc_out;   // error crc
1069
      else
1070
        tdi_pad_i<=#1 crc_out;    // ok crc
1071
 
1072
      gen_clk(1);
1073
    end
1074
 
1075
    crc_out_shift = 0;  // Disable CRC shifting
1076
 
1077
    tdi_pad_i<=#1 'hz;
1078
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
1079
 
1080
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
1081
    begin
1082
      gen_clk(1);
1083
    end
1084
 
1085
    tms_pad_i<=#1 1;
1086
    gen_clk(1);         // to exit1_dr
1087
 
1088
    tms_pad_i<=#1 1;
1089
    gen_clk(1);         // to update_dr
1090
    tms_pad_i<=#1 0;
1091
    gen_clk(1);         // to run_test_idle
1092
  end
1093
endtask       // debug_cpu_set_addr
1094
 
1095
 
1096
 
1097
 
1098
task debug_cpu_go;
1099
  input [2:0]   command;
1100
  input [31:0]  data;
1101
  input         gen_crc_err;
1102
  integer i, len;
1103
 
1104
 
1105 93 mohor
  begin
1106 99 mohor
    $display("(%0t) Task debug_cpu_go (previous command was %0s): ", $time, last_wb_cmd_text);
1107 88 mohor
 
1108 93 mohor
    tms_pad_i<=#1 1;
1109
    gen_clk(1);
1110
    tms_pad_i<=#1 0;
1111
    gen_clk(2);  // we are in shiftDR
1112 88 mohor
 
1113 99 mohor
    crc_out_en = 1; // Enable CRC calculation
1114
 
1115 93 mohor
    tdi_pad_i<=#1 1'b0; // chain_select bit = 0
1116
    gen_clk(1);
1117 88 mohor
 
1118 93 mohor
    for(i=2; i>=0; i=i-1)
1119
    begin
1120
      tdi_pad_i<=#1 command[i]; // command
1121
      gen_clk(1);
1122
    end
1123 88 mohor
 
1124
 
1125 99 mohor
    if (last_wb_cmd == `CPU_WRITE32)
1126 93 mohor
      begin
1127 99 mohor
        len = 31;
1128
        $display("\t\tdata = 0x%x", data);
1129
      end
1130
    else if ((last_wb_cmd == `CPU_WRITE8) | (last_wb_cmd == `CPU_WRITE_REG))
1131
      begin
1132
        len = 7;
1133
        $display("\t\tdata = 0x%x", data[7:0]);
1134
      end
1135
    else
1136
      len = 0;
1137
 
1138
    if (len>0)  // When CPU_WRITEx was previously activated, data needs to be shifted.
1139
      begin
1140
        for (i=len; i>=0; i=i-1)
1141 93 mohor
          begin
1142 99 mohor
            tdi_pad_i<=#1 data[i];
1143 93 mohor
            gen_clk(1);
1144
          end
1145
      end
1146 2 mohor
 
1147 99 mohor
    crc_out_en = 0;     // Disable CRC calculation
1148
    crc_out_shift = 1;  // Enable CRC shifting
1149 2 mohor
 
1150 99 mohor
    for(i=31; i>=0; i=i-1)
1151 93 mohor
    begin
1152 99 mohor
      if (gen_crc_err & (i==0))  // Generate crc error at last crc bit
1153
        tdi_pad_i<=#1 ~crc_out;   // error crc
1154
      else
1155
        tdi_pad_i<=#1 crc_out;    // ok crc
1156
 
1157 93 mohor
      gen_clk(1);
1158
    end
1159
 
1160 99 mohor
    crc_out_shift = 0;  // Disable CRC shifting
1161
 
1162 93 mohor
    tdi_pad_i<=#1 1'hz;
1163
 
1164
 
1165 99 mohor
    if (last_wb_cmd == `CPU_READ32)
1166
      len = 32;
1167
    else if ((last_wb_cmd == `CPU_READ8) | (last_wb_cmd == `CPU_READ_REG))
1168
      len = 8;
1169
    else
1170
      len = 0;
1171 93 mohor
 
1172 99 mohor
    if (len>0)    // When CPU_WRITEx was previously activated, data needs to be shifted.
1173 93 mohor
      begin
1174 99 mohor
        $display("\t\tGenerating %0d clocks to read out the data.", len);
1175
        for (i=0; i<len; i=i+1)
1176 93 mohor
          gen_clk(1);
1177
      end
1178
 
1179
 
1180
    gen_clk(`STATUS_LEN);   // Generating 4 clocks to read out status.
1181
 
1182
    for(i=0; i<`CRC_LEN -1; i=i+1)  // Getting in the CRC
1183
    begin
1184
      gen_clk(1);
1185
    end
1186
 
1187
    tms_pad_i<=#1 1;
1188
    gen_clk(1);         // to exit1_dr
1189
 
1190
    tms_pad_i<=#1 1;
1191
    gen_clk(1);         // to update_dr
1192
    tms_pad_i<=#1 0;
1193
    gen_clk(1);         // to run_test_idle
1194
  end
1195 99 mohor
endtask       // debug_cpu_go
1196 93 mohor
 
1197
 
1198
 
1199
 
1200
 
1201
 
1202
 
1203
 
1204
 
1205
 
1206
 
1207
 
1208
 
1209 99 mohor
 
1210 2 mohor
/**********************************************************************************
1211
*                                                                                 *
1212
*   Printing the information to the screen                                        *
1213
*                                                                                 *
1214
**********************************************************************************/
1215
 
1216 80 mohor
always @ (posedge tck_pad_i)
1217 2 mohor
begin
1218 80 mohor
  if(dbg_tb.i_tap_top.update_ir)
1219
    case(dbg_tb.i_tap_top.jtag_ir[`IR_LENGTH-1:0])
1220
      `EXTEST         : $display("\tInstruction EXTEST entered");
1221
      `SAMPLE_PRELOAD : $display("\tInstruction SAMPLE_PRELOAD entered");
1222
      `IDCODE         : $display("\tInstruction IDCODE entered");
1223
      `MBIST          : $display("\tInstruction MBIST entered");
1224
      `DEBUG          : $display("\tInstruction DEBUG entered");
1225
      `BYPASS         : $display("\tInstruction BYPASS entered");
1226
                default           :     $display("\n\tInstruction not valid. Instruction BYPASS activated !!!");
1227 2 mohor
    endcase
1228
end
1229
 
1230
 
1231
 
1232
// Print shifted IDCode
1233 80 mohor
reg [31:0] tmp_data;
1234
always @ (posedge tck_pad_i)
1235 2 mohor
begin
1236 80 mohor
  if(dbg_tb.i_tap_top.idcode_select)
1237 2 mohor
    begin
1238 80 mohor
      if(dbg_tb.i_tap_top.shift_dr)
1239
        tmp_data[31:0]<=#1 {dbg_tb.tdo, tmp_data[31:1]};
1240 2 mohor
      else
1241 80 mohor
      if(dbg_tb.i_tap_top.update_dr)
1242
        if (tmp_data[31:0] != `IDCODE_VALUE)
1243 73 mohor
          begin
1244
            $display("(%0t) ERROR: IDCODE not correct", $time);
1245
            $stop;
1246
          end
1247
        else
1248 80 mohor
          $display("\t\tIDCode = 0x%h", tmp_data[31:0]);
1249 2 mohor
    end
1250
end
1251
 
1252
 
1253 80 mohor
// We never use following states: exit2_ir,  exit2_dr,  pause_ir or pause_dr
1254
always @ (posedge tck_pad_i)
1255 2 mohor
begin
1256 80 mohor
  if(dbg_tb.i_tap_top.pause_ir | dbg_tb.i_tap_top.exit2_ir)
1257 2 mohor
    begin
1258 80 mohor
      $display("\n(%0t) ERROR: State pause_ir or exit2_ir detected.", $time);
1259
      $display("(%0t) Simulation stopped !!!", $time);
1260
      $stop;
1261 2 mohor
    end
1262
end
1263
 
1264
 
1265 80 mohor
// sets the selected scan chain and goes to the RunTestIdle state
1266
task xxx;
1267
  input [3:0]  data;
1268
  input [31:0] crc;
1269
  integer i;
1270
 
1271
  begin
1272
    $display("(%0t) Task xxx", $time);
1273
    tms_pad_i<=#1 1;
1274
    gen_clk(1);
1275
    tms_pad_i<=#1 0;
1276
    gen_clk(2);  // we are in shiftDR
1277
 
1278
    for(i=0; i<4; i=i+1)
1279 73 mohor
    begin
1280 80 mohor
      tdi_pad_i<=#1 data[i];
1281
      gen_clk(1);
1282 73 mohor
    end
1283
 
1284 80 mohor
    for(i=0; i<`CRC_LEN; i=i+1)
1285
    begin
1286
      tdi_pad_i<=#1 crc[`CRC_LEN - 1 - i];
1287
      gen_clk(1);
1288
    end
1289 73 mohor
 
1290 80 mohor
    gen_clk(`STATUS_LEN);   // Generating 5 clocks to read out status.
1291 73 mohor
 
1292
 
1293 80 mohor
    for(i=0; i<`CRC_LEN -1; i=i+1)
1294
    begin
1295
      tdi_pad_i<=#1 1'b0;
1296
      gen_clk(1);
1297
    end
1298 73 mohor
 
1299 80 mohor
    tdi_pad_i<=#1 crc[i]; // last crc
1300
    tms_pad_i<=#1 1;
1301
    gen_clk(1);         // to exit1_dr
1302 73 mohor
 
1303 80 mohor
    tdi_pad_i<=#1 'hz;  // tri-state
1304
    tms_pad_i<=#1 1;
1305
    gen_clk(1);         // to update_dr
1306
    tms_pad_i<=#1 0;
1307
    gen_clk(1);         // to run_test_idle
1308
  end
1309
endtask
1310 2 mohor
 
1311
 
1312 80 mohor
 
1313 88 mohor
// Detecting CRC error
1314 99 mohor
always @ (posedge dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_end or posedge dbg_tb.i_dbg_top.chain_latch_en)
1315 88 mohor
begin
1316
  #2;
1317
  if (~dbg_tb.i_dbg_top.crc_match)
1318
    begin
1319
      $display("\t\tCRC ERROR !!!");
1320 90 mohor
      $stop;
1321 88 mohor
    end
1322
end
1323 80 mohor
 
1324 88 mohor
 
1325 90 mohor
 
1326
// Detecting errors in counters
1327
always @ (dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt or
1328
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end or
1329
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt or
1330
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_end or
1331
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt or
1332
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_end or
1333
          dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_en or
1334
          dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en or
1335
          dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en or
1336
          dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en or
1337
          dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1338
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt2 or
1339
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt3 or
1340
          //dbg_tb.i_dbg_top.i_dbg_wb.status_cnt4
1341
          // dbg_tb.i_dbg_top.i_dbg_wb. or
1342
         )
1343
begin
1344
  if ((~dbg_tb.i_dbg_top.i_dbg_wb.cmd_cnt_end) & (
1345
                                                  dbg_tb.i_dbg_top.i_dbg_wb.addr_len_cnt_en |
1346
                                                  dbg_tb.i_dbg_top.i_dbg_wb.data_cnt_en     |
1347
                                                  dbg_tb.i_dbg_top.i_dbg_wb.crc_cnt_en      |
1348
                                                  dbg_tb.i_dbg_top.i_dbg_wb.status_cnt1
1349
                                                 )
1350
     )
1351
    begin
1352
      $display("\n\n\t\t(%0t) ERROR in counters !!!", $time);
1353
      #10000;
1354
      $stop;
1355
    end
1356
 
1357
 
1358
 
1359
end
1360
 
1361
 
1362
 
1363
 
1364
 
1365 91 mohor
 
1366 80 mohor
endmodule // dbg_tb
1367
 
1368
 

powered by: WebSVN 2.1.0

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