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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_15/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 95

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_top.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 81 mohor
////       Igor Mohor (igorm@opencores.org)                       ////
11 2 mohor
////                                                              ////
12
////                                                              ////
13 81 mohor
////  All additional information is avaliable in the README.txt   ////
14 2 mohor
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18 81 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 95 mohor
// Revision 1.34  2003/12/23 15:07:34  mohor
47
// New directory structure. New version of the debug interface.
48
// Files that are not needed removed.
49
//
50 81 mohor
// Revision 1.33  2003/10/23 16:17:01  mohor
51
// CRC logic changed.
52
//
53 73 mohor
// Revision 1.32  2003/09/18 14:00:47  simons
54
// Lower two address lines must be always zero.
55
//
56 67 simons
// Revision 1.31  2003/09/17 14:38:57  simons
57
// WB_CNTL register added, some syncronization fixes.
58
//
59 65 simons
// Revision 1.30  2003/08/28 13:55:22  simons
60
// Three more chains added for cpu debug access.
61
//
62 63 simons
// Revision 1.29  2003/07/31 12:19:49  simons
63
// Multiple cpu support added.
64
//
65 57 simons
// Revision 1.28  2002/11/06 14:22:41  mohor
66
// Trst signal is not inverted here any more. Inverted on higher layer !!!.
67
//
68 52 mohor
// Revision 1.27  2002/10/10 02:42:55  mohor
69 73 mohor
// WISHBONE Scan Chain is changed to reflect state of the WISHBONE access (WBInProgress bit added). 
70
// Internal counter is used (counts 256 wb_clk cycles) and when counter exceeds that value, 
71
// wb_cyc_o is negated.
72 52 mohor
//
73 51 mohor
// Revision 1.26  2002/05/07 14:43:59  mohor
74
// mon_cntl_o signals that controls monitor mux added.
75
//
76 47 mohor
// Revision 1.25  2002/04/22 12:54:11  mohor
77
// Signal names changed to lower case.
78
//
79 44 mohor
// Revision 1.24  2002/04/17 13:17:01  mohor
80
// Intentional error removed.
81
//
82 43 mohor
// Revision 1.23  2002/04/17 11:16:33  mohor
83
// A block for checking possible simulation/synthesis missmatch added.
84
//
85 42 mohor
// Revision 1.22  2002/03/12 10:31:53  mohor
86
// tap_top and dbg_top modules are put into two separate modules. tap_top
87
// contains only tap state machine and related logic. dbg_top contains all
88
// logic necessery for debugging.
89
//
90 37 mohor
// Revision 1.21  2002/03/08 15:28:16  mohor
91
// Structure changed. Hooks for jtag chain added.
92
//
93 36 mohor
// Revision 1.20  2002/02/06 12:23:09  mohor
94 81 mohor
// latched_jtag_ir used when muxing TDO instead of JTAG_IR.
95 36 mohor
//
96 33 mohor
// Revision 1.19  2002/02/05 13:34:51  mohor
97
// Stupid bug that was entered by previous update fixed.
98
//
99 32 mohor
// Revision 1.18  2002/02/05 12:41:01  mohor
100
// trst synchronization is not needed and was removed.
101
//
102 31 mohor
// Revision 1.17  2002/01/25 07:58:35  mohor
103
// IDCODE bug fixed, chains reused to decreas size of core. Data is shifted-in
104
// not filled-in. Tested in hw.
105
//
106 30 mohor
// Revision 1.16  2001/12/20 11:17:26  mohor
107
// TDO and TDO Enable signal are separated into two signals.
108
//
109 28 mohor
// Revision 1.15  2001/12/05 13:28:21  mohor
110
// trst signal is synchronized to wb_clk_i.
111
//
112 25 mohor
// Revision 1.14  2001/11/28 09:36:15  mohor
113
// Register length fixed.
114
//
115 22 mohor
// Revision 1.13  2001/11/27 13:37:43  mohor
116
// CRC is returned when chain selection data is transmitted.
117
//
118 21 mohor
// Revision 1.12  2001/11/26 10:47:09  mohor
119
// Crc generation is different for read or write commands. Small synthesys fixes.
120
//
121 20 mohor
// Revision 1.11  2001/11/14 10:10:41  mohor
122
// Wishbone data latched on wb_clk_i instead of risc_clk.
123
//
124 19 mohor
// Revision 1.10  2001/11/12 01:11:27  mohor
125
// Reset signals are not combined any more.
126
//
127 18 mohor
// Revision 1.9  2001/10/19 11:40:01  mohor
128
// dbg_timescale.v changed to timescale.v This is done for the simulation of
129
// few different cores in a single project.
130
//
131 17 mohor
// Revision 1.8  2001/10/17 10:39:03  mohor
132
// bs_chain_o added.
133
//
134 15 mohor
// Revision 1.7  2001/10/16 10:09:56  mohor
135
// Signal names changed to lowercase.
136 13 mohor
//
137 15 mohor
//
138 13 mohor
// Revision 1.6  2001/10/15 09:55:47  mohor
139
// Wishbone interface added, few fixes for better performance,
140
// hooks for boundary scan testing added.
141
//
142 12 mohor
// Revision 1.5  2001/09/24 14:06:42  mohor
143
// Changes connected to the OpenRISC access (SPR read, SPR write).
144
//
145 11 mohor
// Revision 1.4  2001/09/20 10:11:25  mohor
146
// Working version. Few bugs fixed, comments added.
147
//
148 9 mohor
// Revision 1.3  2001/09/19 11:55:13  mohor
149
// Asynchronous set/reset not used in trace any more.
150
//
151 8 mohor
// Revision 1.2  2001/09/18 14:13:47  mohor
152
// Trace fixed. Some registers changed, trace simplified.
153
//
154 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
155
// Initial official release.
156
//
157 2 mohor
// Revision 1.3  2001/06/01 22:22:35  mohor
158
// This is a backup. It is not a fully working version. Not for use, yet.
159
//
160
// Revision 1.2  2001/05/18 13:10:00  mohor
161
// Headers changed. All additional information is now avaliable in the README.txt file.
162
//
163
// Revision 1.1.1.1  2001/05/18 06:35:02  mohor
164
// Initial release
165
//
166
//
167
 
168 20 mohor
// synopsys translate_off
169 17 mohor
`include "timescale.v"
170 20 mohor
// synopsys translate_on
171 2 mohor
`include "dbg_defines.v"
172
 
173
// Top module
174 9 mohor
module dbg_top(
175 81 mohor
                // JTAG signals
176
                tck_i,
177
                tdi_i,
178
                tdo_o,
179 57 simons
 
180 81 mohor
                // TAP states
181
                shift_dr_i,
182
                pause_dr_i,
183
                update_dr_i,
184
 
185
                // Instructions
186
                debug_select_i,
187
 
188 12 mohor
                // WISHBONE common signals
189 81 mohor
                wb_rst_i, wb_clk_i,
190
 
191 12 mohor
                // WISHBONE master interface
192
                wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
193 81 mohor
                wb_we_o, wb_ack_i, wb_cab_o, wb_err_i, wb_cti_o, wb_bte_o
194 2 mohor
              );
195
 
196
 
197 81 mohor
// JTAG signals
198
input   tck_i;
199
input   tdi_i;
200
output  tdo_o;
201 2 mohor
 
202 81 mohor
// TAP states
203
input   shift_dr_i;
204
input   pause_dr_i;
205
input   update_dr_i;
206 2 mohor
 
207 81 mohor
// Instructions
208
input   debug_select_i;
209 2 mohor
 
210 12 mohor
// WISHBONE common signals
211 9 mohor
input         wb_rst_i;                   // WISHBONE reset
212 12 mohor
input         wb_clk_i;                   // WISHBONE clock
213 81 mohor
 
214 12 mohor
// WISHBONE master interface
215
output [31:0] wb_adr_o;
216
output [31:0] wb_dat_o;
217
input  [31:0] wb_dat_i;
218
output        wb_cyc_o;
219
output        wb_stb_o;
220
output  [3:0] wb_sel_o;
221
output        wb_we_o;
222
input         wb_ack_i;
223
output        wb_cab_o;
224
input         wb_err_i;
225 81 mohor
output  [2:0] wb_cti_o;
226
output  [1:0] wb_bte_o;
227 9 mohor
 
228 2 mohor
 
229 81 mohor
reg     cpu_debug_scan_chain;
230
reg     wishbone_scan_chain;
231 2 mohor
 
232 81 mohor
reg [`DATA_CNT -1:0]        data_cnt;
233
reg [`CRC_CNT -1:0]         crc_cnt;
234
reg [`STATUS_CNT -1:0]      status_cnt;
235
reg [`CHAIN_DATA_LEN -1:0]  chain_dr;
236
reg [`CHAIN_ID_LENGTH -1:0] chain;
237 9 mohor
 
238 81 mohor
wire data_cnt_end;
239
wire crc_cnt_end;
240
wire status_cnt_end;
241
reg  crc_cnt_end_q;
242
reg  crc_cnt_end_q2;
243
reg  crc_cnt_end_q3;
244
reg  chain_select;
245
reg  chain_select_error;
246
wire crc_out;
247
wire crc_match;
248
wire crc_en_wb;
249
wire shift_crc_wb;
250 36 mohor
 
251 81 mohor
wire data_shift_en;
252
wire selecting_command;
253 2 mohor
 
254 81 mohor
reg tdo_o;
255
reg wishbone_ce;
256 73 mohor
 
257 81 mohor
// data counter
258 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
259 81 mohor
begin
260 95 mohor
  if (wb_rst_i)
261 81 mohor
    data_cnt <= #1 'h0;
262
  else if(shift_dr_i & (~data_cnt_end))
263
    data_cnt <= #1 data_cnt + 1'b1;
264
  else if (update_dr_i)
265
    data_cnt <= #1 'h0;
266
end
267 9 mohor
 
268 11 mohor
 
269 81 mohor
assign data_cnt_end = data_cnt == `CHAIN_DATA_LEN;
270 2 mohor
 
271
 
272 81 mohor
// crc counter
273 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
274 2 mohor
begin
275 95 mohor
  if (wb_rst_i)
276 81 mohor
    crc_cnt <= #1 'h0;
277
  else if(shift_dr_i & data_cnt_end & (~crc_cnt_end) & chain_select)
278
    crc_cnt <= #1 crc_cnt + 1'b1;
279
  else if (update_dr_i)
280
    crc_cnt <= #1 'h0;
281 2 mohor
end
282
 
283 81 mohor
assign crc_cnt_end = crc_cnt == `CRC_LEN;
284 2 mohor
 
285 12 mohor
 
286 81 mohor
always @ (posedge tck_i)
287 73 mohor
  begin
288 81 mohor
    crc_cnt_end_q  <= #1 crc_cnt_end;
289
    crc_cnt_end_q2 <= #1 crc_cnt_end_q;
290
    crc_cnt_end_q3 <= #1 crc_cnt_end_q2;
291 73 mohor
  end
292 20 mohor
 
293 2 mohor
 
294 81 mohor
// status counter
295 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
296 2 mohor
begin
297 95 mohor
  if (wb_rst_i)
298 81 mohor
    status_cnt <= #1 'h0;
299
  else if(shift_dr_i & crc_cnt_end & (~status_cnt_end))
300
    status_cnt <= #1 status_cnt + 1'b1;
301
  else if (update_dr_i)
302
    status_cnt <= #1 'h0;
303 2 mohor
end
304
 
305 81 mohor
assign status_cnt_end = status_cnt == `STATUS_LEN;
306 42 mohor
 
307
 
308 81 mohor
assign selecting_command = shift_dr_i & (data_cnt == `DATA_CNT'h0) & debug_select_i;
309 42 mohor
 
310
 
311 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
312 2 mohor
begin
313 95 mohor
  if (wb_rst_i)
314 81 mohor
    chain_select <= #1 1'b0;
315
  else if(selecting_command & tdi_i)       // Chain select
316
    chain_select <= #1 1'b1;
317
  else if (update_dr_i)
318
    chain_select <= #1 1'b0;
319 2 mohor
end
320
 
321
 
322 81 mohor
always @ (chain)
323 2 mohor
begin
324 81 mohor
  cpu_debug_scan_chain  <= #1 1'b0;
325
  wishbone_scan_chain   <= #1 1'b0;
326
  chain_select_error    <= #1 1'b0;
327
 
328
  case (chain)                /* synthesis parallel_case */
329
    `CPU_DEBUG_CHAIN      :   cpu_debug_scan_chain  <= #1 1'b1;
330
    `WISHBONE_SCAN_CHAIN  :   wishbone_scan_chain   <= #1 1'b1;
331
    default               :   chain_select_error    <= #1 1'b1;
332
  endcase
333 2 mohor
end
334
 
335 20 mohor
 
336 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
337 67 simons
begin
338 95 mohor
  if (wb_rst_i)
339 81 mohor
    chain <= `CHAIN_ID_LENGTH'b111;
340
  else if(chain_select & crc_cnt_end & (~crc_cnt_end_q) & crc_match)
341
    chain <= #1 chain_dr[`CHAIN_DATA_LEN -1:1];
342 67 simons
end
343
 
344 2 mohor
 
345 81 mohor
assign data_shift_en = shift_dr_i & (~data_cnt_end);
346 2 mohor
 
347
 
348 81 mohor
always @ (posedge tck_i)
349 2 mohor
begin
350 81 mohor
  if (data_shift_en)
351
    chain_dr[`CHAIN_DATA_LEN -1:0] <= #1 {tdi_i, chain_dr[`CHAIN_DATA_LEN -1:1]};
352 2 mohor
end
353
 
354
 
355 81 mohor
// Calculating crc for input data
356
dbg_crc32_d1 i_dbg_crc32_d1_in
357
             (
358
              .data       (tdi_i),
359
              .enable     (shift_dr_i),
360
              .shift      (1'b0),
361 95 mohor
              .rst        (wb_rst_i),
362 81 mohor
              .sync_rst   (update_dr_i),
363
              .crc_out    (),
364
              .clk        (tck_i),
365
              .crc_match  (crc_match)
366
             );
367 2 mohor
 
368 12 mohor
 
369 81 mohor
reg tdo_chain_select;
370
wire crc_en;
371
wire crc_en_dbg;
372
reg crc_started;
373
assign crc_en = crc_en_dbg | crc_en_wb;
374
assign crc_en_dbg = shift_dr_i & crc_cnt_end & (~status_cnt_end);
375 12 mohor
 
376 81 mohor
always @ (posedge tck_i)
377 12 mohor
begin
378 81 mohor
  if (crc_en)
379
    crc_started <= #1 1'b1;
380
  else if (update_dr_i)
381
    crc_started <= #1 1'b0;
382 12 mohor
end
383
 
384
 
385 81 mohor
reg tdo_tmp;
386 12 mohor
 
387 51 mohor
 
388 81 mohor
// Calculating crc for input data
389
dbg_crc32_d1 i_dbg_crc32_d1_out
390
             (
391
              .data       (tdo_tmp),
392
              .enable     (crc_en), // enable has priority
393
//              .shift      (1'b0),
394
              .shift      (shift_dr_i & crc_started & (~crc_en)),
395 95 mohor
              .rst        (wb_rst_i),
396 81 mohor
              .sync_rst   (update_dr_i),
397
              .crc_out    (crc_out),
398
              .clk        (tck_i),
399
              .crc_match  ()
400
             );
401 51 mohor
 
402 81 mohor
// Following status is shifted out: 
403
// 1. bit:          1 if crc is OK, else 0
404
// 2. bit:          1 if command is "chain select", else 0
405
// 3. bit:          1 if non-existing chain is selected else 0
406
// 4. bit:          always 1
407 51 mohor
 
408 81 mohor
reg [799:0] current_on_tdo;
409 51 mohor
 
410 81 mohor
always @ (status_cnt or chain_select or crc_match or chain_select_error or crc_out)
411 51 mohor
begin
412 81 mohor
  case (status_cnt)                   /* synthesis full_case parallel_case */
413
    `STATUS_CNT'd0  : begin
414
                        tdo_chain_select = crc_match;
415
                        current_on_tdo = "crc_match";
416
                      end
417
    `STATUS_CNT'd1  : begin
418
                        tdo_chain_select = chain_select;
419
                        current_on_tdo = "chain_select";
420
                      end
421
    `STATUS_CNT'd2  : begin
422
                        tdo_chain_select = chain_select_error;
423
                        current_on_tdo = "chain_select_error";
424
                      end
425
    `STATUS_CNT'd3  : begin
426
                        tdo_chain_select = 1'b1;
427
                        current_on_tdo = "one 1";
428
                      end
429
    `STATUS_CNT'd4  : begin
430
                        tdo_chain_select = crc_out;
431
                  //      tdo_chain_select = 1'hz;
432
                        current_on_tdo = "crc_out";
433
                      end
434
  endcase
435 51 mohor
end
436
 
437
 
438 81 mohor
wire tdi_wb;
439
wire tdo_wb;
440 5 mohor
 
441 81 mohor
always @ (shift_crc_wb or crc_out or wishbone_ce or tdo_wb or tdo_chain_select)
442 11 mohor
begin
443 81 mohor
  if (shift_crc_wb)       // shifting crc
444
    tdo_tmp = crc_out;
445
  else if (wishbone_ce)   //  shifting data from wb
446
    tdo_tmp = tdo_wb;
447 11 mohor
  else
448 81 mohor
    tdo_tmp = tdo_chain_select;
449 11 mohor
end
450 9 mohor
 
451 11 mohor
 
452 81 mohor
always @ (negedge tck_i)
453 2 mohor
begin
454 81 mohor
  tdo_o <= #1 tdo_tmp;
455 2 mohor
end
456
 
457
 
458
 
459
 
460 81 mohor
// Signals for WISHBONE module
461 9 mohor
 
462
 
463 95 mohor
always @ (posedge tck_i or posedge wb_rst_i)
464 2 mohor
begin
465 95 mohor
  if (wb_rst_i)
466 81 mohor
    wishbone_ce <= #1 1'b0;
467
  else if(selecting_command & (~tdi_i) & wishbone_scan_chain) // wishbone CE
468
    wishbone_ce <= #1 1'b1;
469
  else if (update_dr_i)   // igor !!! This needs to be changed?
470
    wishbone_ce <= #1 1'b0;
471 2 mohor
end
472
 
473
 
474 81 mohor
assign tdi_wb = wishbone_ce & tdi_i;
475 2 mohor
 
476 81 mohor
// Connecting wishbone module
477
dbg_wb i_dbg_wb (
478
                  // JTAG signals
479
                  .tck_i         (tck_i),
480
                  .tdi_i         (tdi_wb),
481
                  .tdo_o         (tdo_wb),
482 2 mohor
 
483 81 mohor
                  // TAP states
484
                  .shift_dr_i    (shift_dr_i),
485
                  .pause_dr_i    (pause_dr_i),
486
                  .update_dr_i   (update_dr_i),
487 2 mohor
 
488 81 mohor
                  .wishbone_ce_i (wishbone_ce),
489
                  .crc_match_i   (crc_match),
490
                  .crc_en_o      (crc_en_wb),
491
                  .shift_crc_o   (shift_crc_wb),
492 95 mohor
                  .rst_i         (wb_rst_i),
493 2 mohor
 
494 81 mohor
                  // WISHBONE common signals
495
                  .wb_clk_i      (wb_clk_i),
496 5 mohor
 
497 81 mohor
                  // WISHBONE master interface
498
                  .wb_adr_o      (wb_adr_o),
499
                  .wb_dat_o      (wb_dat_o),
500
                  .wb_dat_i      (wb_dat_i),
501
                  .wb_cyc_o      (wb_cyc_o),
502
                  .wb_stb_o      (wb_stb_o),
503
                  .wb_sel_o      (wb_sel_o),
504
                  .wb_we_o       (wb_we_o),
505
                  .wb_ack_i      (wb_ack_i),
506
                  .wb_cab_o      (wb_cab_o),
507
                  .wb_err_i      (wb_err_i),
508
                  .wb_cti_o      (wb_cti_o),
509
                  .wb_bte_o      (wb_bte_o)
510 2 mohor
 
511 81 mohor
            );
512 2 mohor
 
513 9 mohor
endmodule

powered by: WebSVN 2.1.0

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