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 65

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
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15 52 mohor
////  All additional information is available in the README.txt   ////
16 2 mohor
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20 52 mohor
//// Copyright (C) 2000,2001, 2002 Authors                        ////
21 2 mohor
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 65 simons
// Revision 1.30  2003/08/28 13:55:22  simons
49
// Three more chains added for cpu debug access.
50
//
51 63 simons
// Revision 1.29  2003/07/31 12:19:49  simons
52
// Multiple cpu support added.
53
//
54 57 simons
// Revision 1.28  2002/11/06 14:22:41  mohor
55
// Trst signal is not inverted here any more. Inverted on higher layer !!!.
56
//
57 52 mohor
// Revision 1.27  2002/10/10 02:42:55  mohor
58
// WISHBONE Scan Chain is changed to reflect state of the WISHBONE access (WBInProgress bit added). Internal counter is used (counts 256 wb_clk cycles) and when counter exceeds that value, wb_cyc_o is negated.
59
//
60 51 mohor
// Revision 1.26  2002/05/07 14:43:59  mohor
61
// mon_cntl_o signals that controls monitor mux added.
62
//
63 47 mohor
// Revision 1.25  2002/04/22 12:54:11  mohor
64
// Signal names changed to lower case.
65
//
66 44 mohor
// Revision 1.24  2002/04/17 13:17:01  mohor
67
// Intentional error removed.
68
//
69 43 mohor
// Revision 1.23  2002/04/17 11:16:33  mohor
70
// A block for checking possible simulation/synthesis missmatch added.
71
//
72 42 mohor
// Revision 1.22  2002/03/12 10:31:53  mohor
73
// tap_top and dbg_top modules are put into two separate modules. tap_top
74
// contains only tap state machine and related logic. dbg_top contains all
75
// logic necessery for debugging.
76
//
77 37 mohor
// Revision 1.21  2002/03/08 15:28:16  mohor
78
// Structure changed. Hooks for jtag chain added.
79
//
80 36 mohor
// Revision 1.20  2002/02/06 12:23:09  mohor
81
// LatchedJTAG_IR used when muxing TDO instead of JTAG_IR.
82
//
83 33 mohor
// Revision 1.19  2002/02/05 13:34:51  mohor
84
// Stupid bug that was entered by previous update fixed.
85
//
86 32 mohor
// Revision 1.18  2002/02/05 12:41:01  mohor
87
// trst synchronization is not needed and was removed.
88
//
89 31 mohor
// Revision 1.17  2002/01/25 07:58:35  mohor
90
// IDCODE bug fixed, chains reused to decreas size of core. Data is shifted-in
91
// not filled-in. Tested in hw.
92
//
93 30 mohor
// Revision 1.16  2001/12/20 11:17:26  mohor
94
// TDO and TDO Enable signal are separated into two signals.
95
//
96 28 mohor
// Revision 1.15  2001/12/05 13:28:21  mohor
97
// trst signal is synchronized to wb_clk_i.
98
//
99 25 mohor
// Revision 1.14  2001/11/28 09:36:15  mohor
100
// Register length fixed.
101
//
102 22 mohor
// Revision 1.13  2001/11/27 13:37:43  mohor
103
// CRC is returned when chain selection data is transmitted.
104
//
105 21 mohor
// Revision 1.12  2001/11/26 10:47:09  mohor
106
// Crc generation is different for read or write commands. Small synthesys fixes.
107
//
108 20 mohor
// Revision 1.11  2001/11/14 10:10:41  mohor
109
// Wishbone data latched on wb_clk_i instead of risc_clk.
110
//
111 19 mohor
// Revision 1.10  2001/11/12 01:11:27  mohor
112
// Reset signals are not combined any more.
113
//
114 18 mohor
// Revision 1.9  2001/10/19 11:40:01  mohor
115
// dbg_timescale.v changed to timescale.v This is done for the simulation of
116
// few different cores in a single project.
117
//
118 17 mohor
// Revision 1.8  2001/10/17 10:39:03  mohor
119
// bs_chain_o added.
120
//
121 15 mohor
// Revision 1.7  2001/10/16 10:09:56  mohor
122
// Signal names changed to lowercase.
123 13 mohor
//
124 15 mohor
//
125 13 mohor
// Revision 1.6  2001/10/15 09:55:47  mohor
126
// Wishbone interface added, few fixes for better performance,
127
// hooks for boundary scan testing added.
128
//
129 12 mohor
// Revision 1.5  2001/09/24 14:06:42  mohor
130
// Changes connected to the OpenRISC access (SPR read, SPR write).
131
//
132 11 mohor
// Revision 1.4  2001/09/20 10:11:25  mohor
133
// Working version. Few bugs fixed, comments added.
134
//
135 9 mohor
// Revision 1.3  2001/09/19 11:55:13  mohor
136
// Asynchronous set/reset not used in trace any more.
137
//
138 8 mohor
// Revision 1.2  2001/09/18 14:13:47  mohor
139
// Trace fixed. Some registers changed, trace simplified.
140
//
141 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
142
// Initial official release.
143
//
144 2 mohor
// Revision 1.3  2001/06/01 22:22:35  mohor
145
// This is a backup. It is not a fully working version. Not for use, yet.
146
//
147
// Revision 1.2  2001/05/18 13:10:00  mohor
148
// Headers changed. All additional information is now avaliable in the README.txt file.
149
//
150
// Revision 1.1.1.1  2001/05/18 06:35:02  mohor
151
// Initial release
152
//
153
//
154
 
155 20 mohor
// synopsys translate_off
156 17 mohor
`include "timescale.v"
157 20 mohor
// synopsys translate_on
158 2 mohor
`include "dbg_defines.v"
159
 
160
// Top module
161 9 mohor
module dbg_top(
162
 
163
                // RISC signals
164 11 mohor
                risc_clk_i, risc_addr_o, risc_data_i, risc_data_o, wp_i,
165 57 simons
                bp_i, opselect_o, lsstatus_i, istatus_i,
166
                risc_stall_o, risc_stall_all_o, risc_sel_o, reset_o,
167
 
168 12 mohor
                // WISHBONE common signals
169
                wb_rst_i, wb_clk_i,
170
 
171
                // WISHBONE master interface
172
                wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
173 36 mohor
                wb_we_o, wb_ack_i, wb_cab_o, wb_err_i,
174 12 mohor
 
175 36 mohor
                // TAP states
176
                ShiftDR, Exit1DR, UpdateDR, UpdateDR_q,
177
 
178
                // Instructions
179
                IDCODESelected, CHAIN_SELECTSelected, DEBUGSelected,
180
 
181
                // TAP signals
182 37 mohor
                trst_in, tck, tdi, TDOData,
183 36 mohor
 
184 47 mohor
                BypassRegister,
185
 
186
                // Monitor mux control
187
                mon_cntl_o
188 37 mohor
 
189 2 mohor
              );
190
 
191
parameter Tp = 1;
192
 
193
 
194 9 mohor
// RISC signals
195 11 mohor
input         risc_clk_i;                 // Master clock (RISC clock)
196 9 mohor
input  [31:0] risc_data_i;                // RISC data inputs (data that is written to the RISC registers)
197
input  [10:0] wp_i;                       // Watchpoint inputs
198
input         bp_i;                       // Breakpoint input
199
input  [3:0]  lsstatus_i;                 // Load/store status inputs
200
input  [1:0]  istatus_i;                  // Instruction status inputs
201
output [31:0] risc_addr_o;                // RISC address output (for adressing registers within RISC)
202
output [31:0] risc_data_o;                // RISC data output (data read from risc registers)
203
output [`OPSELECTWIDTH-1:0] opselect_o;   // Operation selection (selecting what kind of data is set to the risc_data_i)
204 57 simons
output         risc_stall_o;              // Stalls the selected RISC
205
output         risc_stall_all_o;          // Stalls all the rest RISCs
206
output [`RISC_NUM-1:0] risc_sel_o;        // Stalls all the rest RISCs
207
output         reset_o;                   // Resets the RISC
208 2 mohor
 
209
 
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 9 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 9 mohor
 
226
// TAP states
227 36 mohor
input         ShiftDR;
228
input         Exit1DR;
229
input         UpdateDR;
230
input         UpdateDR_q;
231 2 mohor
 
232 37 mohor
input trst_in;
233 36 mohor
input tck;
234
input tdi;
235 2 mohor
 
236 36 mohor
input BypassRegister;
237 9 mohor
 
238 36 mohor
output TDOData;
239 47 mohor
output [3:0] mon_cntl_o;
240 36 mohor
 
241 9 mohor
// Defining which instruction is selected
242 36 mohor
input         IDCODESelected;
243
input         CHAIN_SELECTSelected;
244
input         DEBUGSelected;
245 2 mohor
 
246 36 mohor
reg           wb_cyc_o;
247 9 mohor
 
248 36 mohor
reg [31:0]    ADDR;
249
reg [31:0]    DataOut;
250 11 mohor
 
251 36 mohor
reg [`OPSELECTWIDTH-1:0] opselect_o;        // Operation selection (selecting what kind of data is set to the risc_data_i)
252 2 mohor
 
253 36 mohor
reg [`CHAIN_ID_LENGTH-1:0] Chain;           // Selected chain
254
reg [31:0]    DataReadLatch;                // Data when reading register or RISC is latched one risc_clk_i clock after the data is read.
255
reg           RegAccessTck;                 // Indicates access to the registers (read or write)
256 63 simons
reg           RISCAccessTck0;               // Indicates access to the RISC (read or write)
257
reg           RISCAccessTck1;               // Indicates access to the RISC (read or write)
258
reg           RISCAccessTck2;               // Indicates access to the RISC (read or write)
259
reg           RISCAccessTck3;               // Indicates access to the RISC (read or write)
260 36 mohor
reg [7:0]     BitCounter;                   // Counting bits in the ShiftDR and Exit1DR stages
261
reg           RW;                           // Read/Write bit
262
reg           CrcMatch;                     // The crc that is shifted in and the internaly calculated crc are equal
263 2 mohor
 
264 36 mohor
reg           RegAccess_q;                  // Delayed signals used for accessing the registers
265
reg           RegAccess_q2;                 // Delayed signals used for accessing the registers
266
reg           RISCAccess_q;                 // Delayed signals used for accessing the RISC
267
reg           RISCAccess_q2;                // Delayed signals used for accessing the RISC
268 57 simons
reg           RISCAccess_q3;                // Delayed signals used for accessing the RISC
269 2 mohor
 
270 36 mohor
reg           wb_AccessTck;                 // Indicates access to the WISHBONE
271
reg [31:0]    WBReadLatch;                  // Data latched during WISHBONE read
272
reg           WBErrorLatch;                 // Error latched during WISHBONE read
273 51 mohor
reg           WBInProgress;                 // WISHBONE access is in progress
274
reg [7:0]     WBAccessCounter;              // Counting access cycles. WBInProgress is cleared to 0 after counter exceeds 0xff
275
wire          WBAccessCounterExceed;        // Marks when the WBAccessCounter exceeds max value (oxff)
276
reg           WBInProgress_sync1;           // Synchronizing WBInProgress
277
reg           WBInProgress_tck;             // Synchronizing WBInProgress to tck clock signal
278 30 mohor
 
279 37 mohor
wire trst;
280 30 mohor
 
281 37 mohor
 
282 9 mohor
wire [31:0]             RegDataIn;        // Data from registers (read data)
283
wire [`CRC_LENGTH-1:0]  CalculatedCrcOut; // CRC calculated in this module. This CRC is apended at the end of the TDO.
284 2 mohor
 
285 9 mohor
wire RiscStall_reg;                       // RISC is stalled by setting the register bit
286
wire RiscReset_reg;                       // RISC is reset by setting the register bit
287
wire RiscStall_trace;                     // RISC is stalled by trace module
288
 
289
 
290
wire RegisterScanChain;                   // Register Scan chain selected
291 63 simons
wire RiscDebugScanChain0;                 // Risc Debug Scan chain selected
292
wire RiscDebugScanChain1;                 // Risc Debug Scan chain selected
293
wire RiscDebugScanChain2;                 // Risc Debug Scan chain selected
294
wire RiscDebugScanChain3;                 // Risc Debug Scan chain selected
295 12 mohor
wire WishboneScanChain;                   // WISHBONE Scan chain selected
296 11 mohor
 
297 63 simons
wire RiscStall_read_access_0;             // Stalling RISC because of the read access (SPR read)
298
wire RiscStall_read_access_1;             // Stalling RISC because of the read access (SPR read)
299
wire RiscStall_read_access_2;             // Stalling RISC because of the read access (SPR read)
300
wire RiscStall_read_access_3;             // Stalling RISC because of the read access (SPR read)
301
wire RiscStall_write_access_0;            // Stalling RISC because of the write access (SPR write)
302
wire RiscStall_write_access_1;            // Stalling RISC because of the write access (SPR write)
303
wire RiscStall_write_access_2;            // Stalling RISC because of the write access (SPR write)
304
wire RiscStall_write_access_3;            // Stalling RISC because of the write access (SPR write)
305 11 mohor
wire RiscStall_access;                    // Stalling RISC because of the read or write access
306
 
307 30 mohor
wire BitCounter_Lt4;
308
wire BitCounter_Eq5;
309
wire BitCounter_Eq32;
310
wire BitCounter_Lt38;
311
wire BitCounter_Lt65;
312
 
313 15 mohor
 
314
 
315 9 mohor
// This signals are used only when TRACE is used in the design
316 2 mohor
`ifdef TRACE_ENABLED
317 9 mohor
  wire [39:0] TraceChain;                 // Chain that comes from trace module
318 36 mohor
  reg  ReadBuffer_Tck;                    // Command for incrementing the trace read pointer (synchr with tck)
319 9 mohor
  wire ReadTraceBuffer;                   // Command for incrementing the trace read pointer (synchr with MClk)
320
  reg  ReadTraceBuffer_q;                 // Delayed command for incrementing the trace read pointer (synchr with MClk)
321
  wire ReadTraceBufferPulse;              // Pulse for reading the trace buffer (valid for only one Mclk command)
322 2 mohor
 
323
  // Outputs from registers
324 9 mohor
  wire ContinMode;                        // Trace working in continous mode
325
  wire TraceEnable;                       // Trace enabled
326 2 mohor
 
327 9 mohor
  wire [10:0] WpTrigger;                  // Watchpoint starts trigger
328
  wire        BpTrigger;                  // Breakpoint starts trigger
329
  wire [3:0]  LSSTrigger;                 // Load/store status starts trigger
330
  wire [1:0]  ITrigger;                   // Instruction status starts trigger
331
  wire [1:0]  TriggerOper;                // Trigger operation
332 2 mohor
 
333 9 mohor
  wire        WpTriggerValid;             // Watchpoint trigger is valid
334
  wire        BpTriggerValid;             // Breakpoint trigger is valid
335
  wire        LSSTriggerValid;            // Load/store status trigger is valid
336
  wire        ITriggerValid;              // Instruction status trigger is valid
337 2 mohor
 
338 9 mohor
  wire [10:0] WpQualif;                   // Watchpoint starts qualifier
339
  wire        BpQualif;                   // Breakpoint starts qualifier
340
  wire [3:0]  LSSQualif;                  // Load/store status starts qualifier
341
  wire [1:0]  IQualif;                    // Instruction status starts qualifier
342
  wire [1:0]  QualifOper;                 // Qualifier operation
343 2 mohor
 
344 9 mohor
  wire        WpQualifValid;              // Watchpoint qualifier is valid
345
  wire        BpQualifValid;              // Breakpoint qualifier is valid
346
  wire        LSSQualifValid;             // Load/store status qualifier is valid
347
  wire        IQualifValid;               // Instruction status qualifier is valid
348 2 mohor
 
349 9 mohor
  wire [10:0] WpStop;                     // Watchpoint stops recording of the trace
350
  wire        BpStop;                     // Breakpoint stops recording of the trace
351
  wire [3:0]  LSSStop;                    // Load/store status stops recording of the trace
352
  wire [1:0]  IStop;                      // Instruction status stops recording of the trace
353
  wire [1:0]  StopOper;                   // Stop operation
354 2 mohor
 
355 9 mohor
  wire WpStopValid;                       // Watchpoint stop is valid
356
  wire BpStopValid;                       // Breakpoint stop is valid
357
  wire LSSStopValid;                      // Load/store status stop is valid
358
  wire IStopValid;                        // Instruction status stop is valid
359 2 mohor
 
360 9 mohor
  wire RecordPC;                          // Recording program counter
361
  wire RecordLSEA;                        // Recording load/store effective address
362
  wire RecordLDATA;                       // Recording load data
363
  wire RecordSDATA;                       // Recording store data
364
  wire RecordReadSPR;                     // Recording read SPR
365
  wire RecordWriteSPR;                    // Recording write SPR
366
  wire RecordINSTR;                       // Recording instruction
367 2 mohor
 
368
  // End: Outputs from registers
369
 
370 9 mohor
  wire TraceTestScanChain;                // Trace Test Scan chain selected
371
  wire [47:0] Trace_Data;                 // Trace data
372 2 mohor
 
373 11 mohor
  wire [`OPSELECTWIDTH-1:0]opselect_trace;// Operation selection (trace selecting what kind of
374
                                          // data is set to the risc_data_i)
375 30 mohor
  wire BitCounter_Lt40;
376 11 mohor
 
377 2 mohor
`endif
378
 
379
 
380 52 mohor
assign trst = trst_in;                   // trst_pad_i is active high !!! Inverted on higher layer.
381 25 mohor
 
382
 
383 2 mohor
/**********************************************************************************
384
*                                                                                 *
385
*   JTAG_DR:  JTAG Data Register                                                  *
386
*                                                                                 *
387
**********************************************************************************/
388
reg [`DR_LENGTH-1:0]JTAG_DR_IN;    // Data register
389
reg TDOData;
390
 
391
 
392 36 mohor
always @ (posedge tck or posedge trst)
393 2 mohor
begin
394 18 mohor
  if(trst)
395 2 mohor
    JTAG_DR_IN[`DR_LENGTH-1:0]<=#Tp 0;
396
  else
397 30 mohor
  if(IDCODESelected)                          // To save space JTAG_DR_IN is also used for shifting out IDCODE
398
    begin
399
      if(ShiftDR)
400 36 mohor
        JTAG_DR_IN[31:0] <= #Tp {tdi, JTAG_DR_IN[31:1]};
401 30 mohor
      else
402
        JTAG_DR_IN[31:0] <= #Tp `IDCODE_VALUE;
403
    end
404
  else
405
  if(CHAIN_SELECTSelected & ShiftDR)
406 36 mohor
    JTAG_DR_IN[12:0] <= #Tp {tdi, JTAG_DR_IN[12:1]};
407 30 mohor
  else
408
  if(DEBUGSelected & ShiftDR)
409
    begin
410 63 simons
      if(RiscDebugScanChain0 | RiscDebugScanChain1 |
411
         RiscDebugScanChain2 | RiscDebugScanChain3 | WishboneScanChain)
412 36 mohor
        JTAG_DR_IN[73:0] <= #Tp {tdi, JTAG_DR_IN[73:1]};
413 30 mohor
      else
414
      if(RegisterScanChain)
415 36 mohor
        JTAG_DR_IN[46:0] <= #Tp {tdi, JTAG_DR_IN[46:1]};
416 30 mohor
    end
417 2 mohor
end
418 30 mohor
 
419 22 mohor
wire [73:0] RISC_Data;
420
wire [46:0] Register_Data;
421
wire [73:0] WISHBONE_Data;
422 21 mohor
wire [12:0] chain_sel_data;
423 12 mohor
wire wb_Access_wbClk;
424 65 simons
wire [1:0] wb_cntl_o;
425 2 mohor
 
426
 
427 30 mohor
reg select_crc_out;
428 36 mohor
always @ (posedge tck or posedge trst)
429 30 mohor
begin
430
  if(trst)
431
    select_crc_out <= 0;
432
  else
433 63 simons
  if( RegisterScanChain   & BitCounter_Eq5  |
434
      RiscDebugScanChain0 & BitCounter_Eq32 |
435
      RiscDebugScanChain1 & BitCounter_Eq32 |
436
      RiscDebugScanChain2 & BitCounter_Eq32 |
437
      RiscDebugScanChain3 & BitCounter_Eq32 |
438
      WishboneScanChain   & BitCounter_Eq32 )
439 36 mohor
    select_crc_out <=#Tp tdi;
440 30 mohor
  else
441
  if(CHAIN_SELECTSelected)
442
    select_crc_out <=#Tp 1;
443
  else
444
  if(UpdateDR)
445
    select_crc_out <=#Tp 0;
446
end
447 12 mohor
 
448 20 mohor
wire [8:0] send_crc;
449
 
450 30 mohor
assign send_crc = select_crc_out? {9{BypassRegister}}    :    // Calculated CRC is returned when read operation is
451
                                  {CalculatedCrcOut, 1'b0} ;  // performed, else received crc is returned (loopback).
452 20 mohor
 
453 30 mohor
assign RISC_Data      = {send_crc, DataReadLatch, 33'h0};
454
assign Register_Data  = {send_crc, DataReadLatch, 6'h0};
455 51 mohor
assign WISHBONE_Data  = {send_crc, WBReadLatch, 31'h0, WBInProgress, WBErrorLatch};
456 21 mohor
assign chain_sel_data = {send_crc, 4'h0};
457 20 mohor
 
458
 
459
`ifdef TRACE_ENABLED
460 2 mohor
  assign Trace_Data     = {CalculatedCrcOut, TraceChain};
461
`endif
462
 
463 36 mohor
//TDO is changing on the falling edge of tck
464
always @ (negedge tck or posedge trst)
465 2 mohor
begin
466 18 mohor
  if(trst)
467 2 mohor
    begin
468
      TDOData <= #Tp 0;
469
      `ifdef TRACE_ENABLED
470
      ReadBuffer_Tck<=#Tp 0;
471
      `endif
472
    end
473
  else
474
  if(UpdateDR)
475
    begin
476
      TDOData <= #Tp CrcMatch;
477
      `ifdef TRACE_ENABLED
478 9 mohor
      if(DEBUGSelected & TraceTestScanChain & TraceChain[0])  // Sample in the trace buffer is valid
479
        ReadBuffer_Tck<=#Tp 1;                                // Increment read pointer
480 2 mohor
      `endif
481
    end
482
  else
483
    begin
484
      if(ShiftDR)
485
        begin
486
          if(IDCODESelected)
487 36 mohor
            TDOData <= #Tp JTAG_DR_IN[0]; // IDCODE is shifted out 32-bits, then tdi is bypassed
488 2 mohor
          else
489
          if(CHAIN_SELECTSelected)
490 21 mohor
            TDOData <= #Tp chain_sel_data[BitCounter];        // Received crc is sent back
491 2 mohor
          else
492
          if(DEBUGSelected)
493
            begin
494 63 simons
              if(RiscDebugScanChain0 | RiscDebugScanChain1 | RiscDebugScanChain2 | RiscDebugScanChain3)
495 9 mohor
                TDOData <= #Tp RISC_Data[BitCounter];         // Data read from RISC in the previous cycle is shifted out
496 2 mohor
              else
497
              if(RegisterScanChain)
498 9 mohor
                TDOData <= #Tp Register_Data[BitCounter];     // Data read from register in the previous cycle is shifted out
499 12 mohor
              else
500
              if(WishboneScanChain)
501
                TDOData <= #Tp WISHBONE_Data[BitCounter];     // Data read from the WISHBONE slave
502 2 mohor
              `ifdef TRACE_ENABLED
503
              else
504
              if(TraceTestScanChain)
505 9 mohor
                TDOData <= #Tp Trace_Data[BitCounter];        // Data from the trace buffer is shifted out
506 2 mohor
              `endif
507
            end
508
        end
509
      else
510
        begin
511
          TDOData <= #Tp 0;
512
          `ifdef TRACE_ENABLED
513
          ReadBuffer_Tck<=#Tp 0;
514
          `endif
515
        end
516
    end
517
end
518
 
519 42 mohor
 
520
//synopsys translate_off
521
always @ (posedge tck)
522
begin
523
  if(ShiftDR & CHAIN_SELECTSelected & BitCounter > 12)
524
    begin
525
      $display("\n%m Error: BitCounter is bigger then chain_sel_data bits width[12:0]. BitCounter=%d\n",BitCounter);
526
      $stop;
527
    end
528
  else
529
  if(ShiftDR & DEBUGSelected)
530
    begin
531 63 simons
      if((RiscDebugScanChain0 | RiscDebugScanChain1 | RiscDebugScanChain2 | RiscDebugScanChain3) & BitCounter > 73)
532 42 mohor
        begin
533
          $display("\n%m Error: BitCounter is bigger then RISC_Data bits width[73:0]. BitCounter=%d\n",BitCounter);
534
          $stop;
535
        end
536
      else
537 43 mohor
      if(RegisterScanChain & BitCounter > 46)
538 42 mohor
        begin
539
          $display("\n%m Error: BitCounter is bigger then RISC_Data bits width[46:0]. BitCounter=%d\n",BitCounter);
540
          $stop;
541
        end
542
      else
543
      if(WishboneScanChain & BitCounter > 73)
544
        begin
545
          $display("\n%m Error: BitCounter is bigger then WISHBONE_Data bits width[73:0]. BitCounter=%d\n",BitCounter);
546
          $stop;
547
        end
548
      `ifdef TRACE_ENABLED
549
      else
550
      if(TraceTestScanChain & BitCounter > 47)
551
        begin
552
          $display("\n%m Error: BitCounter is bigger then Trace_Data bits width[47:0]. BitCounter=%d\n",BitCounter);
553
          $stop;
554
        end
555
      `endif
556
    end
557
end
558
// synopsys translate_on
559
 
560
 
561
 
562
 
563
 
564
 
565
 
566
 
567 2 mohor
/**********************************************************************************
568
*                                                                                 *
569
*   End: JTAG_DR                                                                  *
570
*                                                                                 *
571
**********************************************************************************/
572
 
573
 
574
 
575
/**********************************************************************************
576
*                                                                                 *
577
*   CHAIN_SELECT logic                                                            *
578
*                                                                                 *
579
**********************************************************************************/
580 36 mohor
always @ (posedge tck or posedge trst)
581 2 mohor
begin
582 18 mohor
  if(trst)
583 9 mohor
    Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp `GLOBAL_BS_CHAIN;  // Global BS chain is selected after reset
584 2 mohor
  else
585
  if(UpdateDR & CHAIN_SELECTSelected & CrcMatch)
586 9 mohor
    Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp JTAG_DR_IN[3:0];   // New chain is selected
587 2 mohor
end
588
 
589
 
590
 
591
/**********************************************************************************
592
*                                                                                 *
593
*   Register read/write logic                                                     *
594
*   RISC registers read/write logic                                               *
595
*                                                                                 *
596
**********************************************************************************/
597 36 mohor
always @ (posedge tck or posedge trst)
598 2 mohor
begin
599 18 mohor
  if(trst)
600 2 mohor
    begin
601
      ADDR[31:0]        <=#Tp 32'h0;
602
      DataOut[31:0]     <=#Tp 32'h0;
603
      RW                <=#Tp 1'b0;
604
      RegAccessTck      <=#Tp 1'b0;
605 63 simons
      RISCAccessTck0    <=#Tp 1'b0;
606
      RISCAccessTck1    <=#Tp 1'b0;
607
      RISCAccessTck2    <=#Tp 1'b0;
608
      RISCAccessTck3    <=#Tp 1'b0;
609 12 mohor
      wb_AccessTck      <=#Tp 1'h0;
610 2 mohor
    end
611
  else
612
  if(UpdateDR & DEBUGSelected & CrcMatch)
613
    begin
614
      if(RegisterScanChain)
615
        begin
616
          ADDR[4:0]         <=#Tp JTAG_DR_IN[4:0];    // Latching address for register access
617
          RW                <=#Tp JTAG_DR_IN[5];      // latch R/W bit
618
          DataOut[31:0]     <=#Tp JTAG_DR_IN[37:6];   // latch data for write
619
          RegAccessTck      <=#Tp 1'b1;
620
        end
621
      else
622 63 simons
      if(WishboneScanChain & (!WBInProgress_tck))
623 2 mohor
        begin
624 63 simons
          ADDR              <=#Tp JTAG_DR_IN[31:0];   // Latching address for WISHBONE slave access
625
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
626
          DataOut           <=#Tp JTAG_DR_IN[64:33];  // latch data for write
627
          wb_AccessTck      <=#Tp 1'b1;               // 
628
        end
629
      else
630
      if(RiscDebugScanChain0)
631
        begin
632 2 mohor
          ADDR[31:0]        <=#Tp JTAG_DR_IN[31:0];   // Latching address for RISC register access
633
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
634
          DataOut[31:0]     <=#Tp JTAG_DR_IN[64:33];  // latch data for write
635 63 simons
          RISCAccessTck0    <=#Tp 1'b1;
636 2 mohor
        end
637 12 mohor
      else
638 63 simons
      if(RiscDebugScanChain1)
639 12 mohor
        begin
640 63 simons
          ADDR[31:0]        <=#Tp JTAG_DR_IN[31:0];   // Latching address for RISC register access
641 20 mohor
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
642 63 simons
          DataOut[31:0]     <=#Tp JTAG_DR_IN[64:33];  // latch data for write
643
          RISCAccessTck1    <=#Tp 1'b1;
644 12 mohor
        end
645 63 simons
      else
646
      if(RiscDebugScanChain2)
647
        begin
648
          ADDR[31:0]        <=#Tp JTAG_DR_IN[31:0];   // Latching address for RISC register access
649
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
650
          DataOut[31:0]     <=#Tp JTAG_DR_IN[64:33];  // latch data for write
651
          RISCAccessTck2    <=#Tp 1'b1;
652
        end
653
      else
654
      if(RiscDebugScanChain3)
655
        begin
656
          ADDR[31:0]        <=#Tp JTAG_DR_IN[31:0];   // Latching address for RISC register access
657
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
658
          DataOut[31:0]     <=#Tp JTAG_DR_IN[64:33];  // latch data for write
659
          RISCAccessTck3    <=#Tp 1'b1;
660
        end
661 2 mohor
    end
662
  else
663
    begin
664 36 mohor
      RegAccessTck      <=#Tp 1'b0;       // This signals are valid for one tck clock period only
665 12 mohor
      wb_AccessTck      <=#Tp 1'b0;
666 63 simons
      RISCAccessTck0    <=#Tp 1'b0;
667
      RISCAccessTck1    <=#Tp 1'b0;
668
      RISCAccessTck2    <=#Tp 1'b0;
669
      RISCAccessTck3    <=#Tp 1'b0;
670 2 mohor
    end
671
end
672
 
673 20 mohor
 
674 65 simons
assign wb_adr_o = ADDR & {32{wb_cyc_o}};
675
assign wb_we_o  = RW & wb_cyc_o;
676
assign wb_dat_o = DataOut & {32{wb_cyc_o}};
677 12 mohor
assign wb_cab_o = 1'b0;
678 65 simons
 
679
reg [3:0] wb_sel_o;
680
always @(ADDR[1:0] or wb_cntl_o or wb_cyc_o)
681
begin
682
  if(wb_cyc_o)
683
      case (wb_cntl_o)
684
        2'b00:   wb_sel_o = 4'hf;
685
        2'b01:   wb_sel_o = ADDR[1] ? 4'h3 : 4'hc;
686
        2'b10:   wb_sel_o = ADDR[1] ? (ADDR[0] ? 4'h1 : 4'h2) : (ADDR[0] ? 4'h4 : 4'h8);
687
        default: wb_sel_o = 4'hf;
688
      endcase
689
  else
690
    wb_sel_o = 4'hf;
691
end
692 20 mohor
 
693 11 mohor
// Synchronizing the RegAccess signal to risc_clk_i clock
694 36 mohor
dbg_sync_clk1_clk2 syn1 (.clk1(risc_clk_i),   .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
695 2 mohor
                         .set2(RegAccessTck), .sync_out(RegAccess)
696
                        );
697
 
698 63 simons
// Synchronizing the wb_Access signal to wishbone clock
699
dbg_sync_clk1_clk2 syn2 (.clk1(wb_clk_i),     .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
700
                         .set2(wb_AccessTck), .sync_out(wb_Access_wbClk)
701 2 mohor
                        );
702
 
703 63 simons
// Synchronizing the RISCAccess0 signal to risc_clk_i clock
704
dbg_sync_clk1_clk2 syn3 (.clk1(risc_clk_i),    .clk2(tck),          .reset1(wb_rst_i),  .reset2(trst),
705
                         .set2(RISCAccessTck0), .sync_out(RISCAccess0)
706
                        );
707 2 mohor
 
708 63 simons
// Synchronizing the RISCAccess1 signal to risc_clk_i clock
709
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i),    .clk2(tck),          .reset1(wb_rst_i),  .reset2(trst),
710
                         .set2(RISCAccessTck1), .sync_out(RISCAccess1)
711 12 mohor
                        );
712
 
713 63 simons
// Synchronizing the RISCAccess2 signal to risc_clk_i clock
714
dbg_sync_clk1_clk2 syn5 (.clk1(risc_clk_i),    .clk2(tck),          .reset1(wb_rst_i),  .reset2(trst),
715
                         .set2(RISCAccessTck2), .sync_out(RISCAccess2)
716
                        );
717 12 mohor
 
718 63 simons
// Synchronizing the RISCAccess3 signal to risc_clk_i clock
719
dbg_sync_clk1_clk2 syn6 (.clk1(risc_clk_i),    .clk2(tck),          .reset1(wb_rst_i),  .reset2(trst),
720
                         .set2(RISCAccessTck3), .sync_out(RISCAccess3)
721
                        );
722 12 mohor
 
723
 
724
 
725 63 simons
 
726
 
727 9 mohor
// Delayed signals used for accessing registers and RISC
728 18 mohor
always @ (posedge risc_clk_i or posedge wb_rst_i)
729 2 mohor
begin
730 18 mohor
  if(wb_rst_i)
731 2 mohor
    begin
732
      RegAccess_q   <=#Tp 1'b0;
733
      RegAccess_q2  <=#Tp 1'b0;
734
      RISCAccess_q  <=#Tp 1'b0;
735
      RISCAccess_q2 <=#Tp 1'b0;
736 57 simons
      RISCAccess_q3 <=#Tp 1'b0;
737 2 mohor
    end
738
  else
739
    begin
740
      RegAccess_q   <=#Tp RegAccess;
741
      RegAccess_q2  <=#Tp RegAccess_q;
742 63 simons
      RISCAccess_q  <=#Tp RISCAccess0 | RISCAccess1 | RISCAccess2 | RISCAccess3;
743 2 mohor
      RISCAccess_q2 <=#Tp RISCAccess_q;
744 57 simons
      RISCAccess_q3 <=#Tp RISCAccess_q2;
745 2 mohor
    end
746
end
747
 
748 9 mohor
// Chip select and read/write signals for accessing RISC
749 63 simons
assign RiscStall_write_access_0 = RISCAccess0 & ~RISCAccess_q2 &  RW;
750
assign RiscStall_read_access_0  = RISCAccess0 & ~RISCAccess_q2 & ~RW;
751
assign RiscStall_write_access_1 = RISCAccess1 & ~RISCAccess_q2 &  RW;
752
assign RiscStall_read_access_1  = RISCAccess1 & ~RISCAccess_q2 & ~RW;
753
assign RiscStall_write_access_2 = RISCAccess2 & ~RISCAccess_q2 &  RW;
754
assign RiscStall_read_access_2  = RISCAccess2 & ~RISCAccess_q2 & ~RW;
755
assign RiscStall_write_access_3 = RISCAccess3 & ~RISCAccess_q2 &  RW;
756
assign RiscStall_read_access_3  = RISCAccess3 & ~RISCAccess_q2 & ~RW;
757
assign RiscStall_access = (RISCAccess0 | RISCAccess1 | RISCAccess2 | RISCAccess3) & ~RISCAccess_q3;
758 2 mohor
 
759
 
760 12 mohor
reg wb_Access_wbClk_q;
761
// Delayed signals used for accessing WISHBONE
762 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
763 12 mohor
begin
764 18 mohor
  if(wb_rst_i)
765 12 mohor
    wb_Access_wbClk_q <=#Tp 1'b0;
766
  else
767
    wb_Access_wbClk_q <=#Tp wb_Access_wbClk;
768
end
769
 
770 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
771 12 mohor
begin
772 18 mohor
  if(wb_rst_i)
773 12 mohor
    wb_cyc_o <=#Tp 1'b0;
774
  else
775 51 mohor
  if(wb_Access_wbClk & ~wb_Access_wbClk_q)
776 12 mohor
    wb_cyc_o <=#Tp 1'b1;
777
  else
778 51 mohor
  if(wb_ack_i | wb_err_i | WBAccessCounterExceed)
779 12 mohor
    wb_cyc_o <=#Tp 1'b0;
780
end
781
 
782
assign wb_stb_o = wb_cyc_o;
783
 
784
 
785
// Latching data read from registers
786 19 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
787 12 mohor
begin
788 18 mohor
  if(wb_rst_i)
789 12 mohor
    WBReadLatch[31:0]<=#Tp 32'h0;
790
  else
791
  if(wb_ack_i)
792
    WBReadLatch[31:0]<=#Tp wb_dat_i[31:0];
793
end
794
 
795
// Latching WISHBONE error cycle
796 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
797 12 mohor
begin
798 18 mohor
  if(wb_rst_i)
799 12 mohor
    WBErrorLatch<=#Tp 1'b0;
800
  else
801
  if(wb_err_i)
802
    WBErrorLatch<=#Tp 1'b1;     // Latching wb_err_i while performing WISHBONE access
803 20 mohor
  else
804 12 mohor
  if(wb_ack_i)
805
    WBErrorLatch<=#Tp 1'b0;     // Clearing status
806
end
807
 
808
 
809 51 mohor
// WBInProgress is set at the beginning of the access and cleared when wb_ack_i or wb_err_i is set
810
always @ (posedge wb_clk_i or posedge wb_rst_i)
811
begin
812
  if(wb_rst_i)
813
    WBInProgress<=#Tp 1'b0;
814
  else
815
  if(wb_Access_wbClk & ~wb_Access_wbClk_q)
816
    WBInProgress<=#Tp 1'b1;
817
  else
818
  if(wb_ack_i | wb_err_i | WBAccessCounterExceed)
819
    WBInProgress<=#Tp 1'b0;
820
end
821
 
822
 
823
// Synchronizing WBInProgress
824
always @ (posedge wb_clk_i or posedge wb_rst_i)
825
begin
826
  if(wb_rst_i)
827
    WBAccessCounter<=#Tp 8'h0;
828
  else
829
  if(wb_ack_i | wb_err_i | WBAccessCounterExceed)
830
    WBAccessCounter<=#Tp 8'h0;
831
  else
832
  if(wb_cyc_o)
833
    WBAccessCounter<=#Tp WBAccessCounter + 1'b1;
834
end
835
 
836
assign WBAccessCounterExceed = WBAccessCounter==8'hff;
837
 
838
 
839
// Synchronizing WBInProgress
840
always @ (posedge tck)
841
begin
842
    WBInProgress_sync1<=#Tp WBInProgress;
843
    WBInProgress_tck<=#Tp WBInProgress_sync1;
844
end
845
 
846
 
847 9 mohor
// Whan enabled, TRACE stalls RISC while saving data to the trace buffer.
848 5 mohor
`ifdef TRACE_ENABLED
849 11 mohor
  assign  risc_stall_o = RiscStall_access | RiscStall_reg | RiscStall_trace ;
850 5 mohor
`else
851 12 mohor
  assign  risc_stall_o = RiscStall_access | RiscStall_reg;
852 5 mohor
`endif
853
 
854 11 mohor
assign  reset_o = RiscReset_reg;
855 5 mohor
 
856
 
857 12 mohor
`ifdef TRACE_ENABLED
858 63 simons
always @ (RiscStall_write_access_0 or RiscStall_write_access_1 or
859
          RiscStall_write_access_2 or RiscStall_write_access_2 or
860
          RiscStall_read_access_0  or RiscStall_read_access_1  or
861
          RiscStall_read_access_2  or RiscStall_read_access_3  or opselect_trace)
862 12 mohor
`else
863 63 simons
always @ (RiscStall_write_access_0 or RiscStall_write_access_1 or
864
          RiscStall_write_access_2 or RiscStall_write_access_3 or
865
          RiscStall_read_access_0  or RiscStall_read_access_1  or
866
          RiscStall_read_access_2  or RiscStall_read_access_3)
867 12 mohor
`endif
868 11 mohor
begin
869 63 simons
  if(RiscStall_write_access_0)
870
    opselect_o = `DEBUG_WRITE_0;
871 11 mohor
  else
872 63 simons
  if(RiscStall_read_access_0)
873
    opselect_o = `DEBUG_READ_0;
874 11 mohor
  else
875 63 simons
  if(RiscStall_write_access_1)
876
    opselect_o = `DEBUG_WRITE_1;
877
  else
878
  if(RiscStall_read_access_1)
879
    opselect_o = `DEBUG_READ_1;
880
  else
881
  if(RiscStall_write_access_2)
882
    opselect_o = `DEBUG_WRITE_2;
883
  else
884
  if(RiscStall_read_access_2)
885
    opselect_o = `DEBUG_READ_2;
886
  else
887
  if(RiscStall_write_access_3)
888
    opselect_o = `DEBUG_WRITE_3;
889
  else
890
  if(RiscStall_read_access_3)
891
    opselect_o = `DEBUG_READ_3;
892
  else
893 12 mohor
`ifdef TRACE_ENABLED
894 11 mohor
    opselect_o = opselect_trace;
895 12 mohor
`else
896
    opselect_o = 3'h0;
897
`endif
898 11 mohor
end
899 9 mohor
 
900 11 mohor
 
901 30 mohor
// Latching data read from RISC or registers
902 18 mohor
always @ (posedge risc_clk_i or posedge wb_rst_i)
903 2 mohor
begin
904 18 mohor
  if(wb_rst_i)
905 30 mohor
    DataReadLatch[31:0]<=#Tp 0;
906 2 mohor
  else
907
  if(RISCAccess_q & ~RISCAccess_q2)
908 30 mohor
    DataReadLatch[31:0]<=#Tp risc_data_i[31:0];
909
  else
910
  if(RegAccess_q & ~RegAccess_q2)
911
    DataReadLatch[31:0]<=#Tp RegDataIn[31:0];
912 2 mohor
end
913
 
914 12 mohor
assign risc_addr_o = ADDR;
915
assign risc_data_o = DataOut;
916 2 mohor
 
917
 
918
 
919
/**********************************************************************************
920
*                                                                                 *
921
*   Read Trace buffer logic                                                       *
922
*                                                                                 *
923
**********************************************************************************/
924
`ifdef TRACE_ENABLED
925
 
926 9 mohor
 
927 11 mohor
// Synchronizing the trace read buffer signal to risc_clk_i clock
928 36 mohor
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i),     .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
929 9 mohor
                         .set2(ReadBuffer_Tck), .sync_out(ReadTraceBuffer)
930
                        );
931
 
932
 
933
 
934 18 mohor
  always @(posedge risc_clk_i or posedge wb_rst_i)
935 2 mohor
  begin
936 18 mohor
    if(wb_rst_i)
937 9 mohor
      ReadTraceBuffer_q <=#Tp 0;
938 2 mohor
    else
939 9 mohor
      ReadTraceBuffer_q <=#Tp ReadTraceBuffer;
940 2 mohor
  end
941 9 mohor
 
942
  assign ReadTraceBufferPulse = ReadTraceBuffer & ~ReadTraceBuffer_q;
943
 
944 2 mohor
`endif
945
 
946
/**********************************************************************************
947
*                                                                                 *
948
*   End: Read Trace buffer logic                                                  *
949
*                                                                                 *
950
**********************************************************************************/
951
 
952
 
953
 
954
 
955
 
956
/**********************************************************************************
957
*                                                                                 *
958
*   Bit counter                                                                   *
959
*                                                                                 *
960
**********************************************************************************/
961
 
962
 
963 36 mohor
always @ (posedge tck or posedge trst)
964 2 mohor
begin
965 18 mohor
  if(trst)
966 2 mohor
    BitCounter[7:0]<=#Tp 0;
967
  else
968
  if(ShiftDR)
969
    BitCounter[7:0]<=#Tp BitCounter[7:0]+1;
970
  else
971
  if(UpdateDR)
972
    BitCounter[7:0]<=#Tp 0;
973
end
974
 
975
 
976
 
977
/**********************************************************************************
978
*                                                                                 *
979
*   End: Bit counter                                                              *
980
*                                                                                 *
981
**********************************************************************************/
982
 
983
 
984
 
985
/**********************************************************************************
986
*                                                                                 *
987
*   Connecting Registers                                                          *
988
*                                                                                 *
989
**********************************************************************************/
990 44 mohor
dbg_registers dbgregs(.data_in(DataOut[31:0]), .data_out(RegDataIn[31:0]),
991
                      .address(ADDR[4:0]), .rw(RW), .access(RegAccess & ~RegAccess_q), .clk(risc_clk_i),
992
                      .bp(bp_i), .reset(wb_rst_i),
993 2 mohor
                      `ifdef TRACE_ENABLED
994 5 mohor
                      .ContinMode(ContinMode), .TraceEnable(TraceEnable),
995 2 mohor
                      .WpTrigger(WpTrigger), .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger),
996
                      .ITrigger(ITrigger), .TriggerOper(TriggerOper), .WpQualif(WpQualif),
997
                      .BpQualif(BpQualif), .LSSQualif(LSSQualif), .IQualif(IQualif),
998 5 mohor
                      .QualifOper(QualifOper), .RecordPC(RecordPC),
999
                      .RecordLSEA(RecordLSEA), .RecordLDATA(RecordLDATA),
1000
                      .RecordSDATA(RecordSDATA), .RecordReadSPR(RecordReadSPR),
1001
                      .RecordWriteSPR(RecordWriteSPR), .RecordINSTR(RecordINSTR),
1002
                      .WpTriggerValid(WpTriggerValid),
1003 2 mohor
                      .BpTriggerValid(BpTriggerValid), .LSSTriggerValid(LSSTriggerValid),
1004
                      .ITriggerValid(ITriggerValid), .WpQualifValid(WpQualifValid),
1005
                      .BpQualifValid(BpQualifValid), .LSSQualifValid(LSSQualifValid),
1006
                      .IQualifValid(IQualifValid),
1007
                      .WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
1008 5 mohor
                      .StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
1009
                      .LSSStopValid(LSSStopValid), .IStopValid(IStopValid),
1010 2 mohor
                      `endif
1011 57 simons
                      .risc_stall(RiscStall_reg), .risc_stall_all(risc_stall_all_o), .risc_sel(risc_sel_o),
1012 65 simons
                      .risc_reset(RiscReset_reg), .mon_cntl_o(mon_cntl_o), .wb_cntl_o(wb_cntl_o)
1013 5 mohor
 
1014 2 mohor
                     );
1015
 
1016
/**********************************************************************************
1017
*                                                                                 *
1018
*   End: Connecting Registers                                                     *
1019
*                                                                                 *
1020
**********************************************************************************/
1021
 
1022
 
1023
/**********************************************************************************
1024
*                                                                                 *
1025
*   Connecting CRC module                                                         *
1026
*                                                                                 *
1027
**********************************************************************************/
1028 18 mohor
wire AsyncResetCrc = trst;
1029 9 mohor
wire SyncResetCrc = UpdateDR_q;
1030 2 mohor
wire [7:0] CalculatedCrcIn;     // crc calculated from the input data (shifted in)
1031
 
1032 30 mohor
assign BitCounter_Lt4   = BitCounter<4;
1033
assign BitCounter_Eq5   = BitCounter==5;
1034
assign BitCounter_Eq32  = BitCounter==32;
1035
assign BitCounter_Lt38  = BitCounter<38;
1036
assign BitCounter_Lt65  = BitCounter<65;
1037
 
1038
`ifdef TRACE_ENABLED
1039
  assign BitCounter_Lt40 = BitCounter<40;
1040
`endif
1041
 
1042
 
1043 2 mohor
wire EnableCrcIn = ShiftDR &
1044 63 simons
                  ( (CHAIN_SELECTSelected                  & BitCounter_Lt4) |
1045
                    ((DEBUGSelected & RegisterScanChain)   & BitCounter_Lt38)|
1046
                    ((DEBUGSelected & RiscDebugScanChain0) & BitCounter_Lt65)|
1047
                    ((DEBUGSelected & RiscDebugScanChain1) & BitCounter_Lt65)|
1048
                    ((DEBUGSelected & RiscDebugScanChain2) & BitCounter_Lt65)|
1049
                    ((DEBUGSelected & RiscDebugScanChain3) & BitCounter_Lt65)|
1050
                    ((DEBUGSelected & WishboneScanChain)   & BitCounter_Lt65)
1051 9 mohor
                  );
1052 2 mohor
 
1053
wire EnableCrcOut= ShiftDR &
1054 9 mohor
                   (
1055 63 simons
                    ((DEBUGSelected & RegisterScanChain)   & BitCounter_Lt38)|
1056
                    ((DEBUGSelected & RiscDebugScanChain0) & BitCounter_Lt65)|
1057
                    ((DEBUGSelected & RiscDebugScanChain1) & BitCounter_Lt65)|
1058
                    ((DEBUGSelected & RiscDebugScanChain2) & BitCounter_Lt65)|
1059
                    ((DEBUGSelected & RiscDebugScanChain3) & BitCounter_Lt65)|
1060
                    ((DEBUGSelected & WishboneScanChain)   & BitCounter_Lt65)
1061 2 mohor
                    `ifdef TRACE_ENABLED
1062 30 mohor
                                                                            |
1063
                    ((DEBUGSelected & TraceTestScanChain) & BitCounter_Lt40)
1064 2 mohor
                    `endif
1065 9 mohor
                   );
1066 2 mohor
 
1067
// Calculating crc for input data
1068 44 mohor
dbg_crc8_d1 crc1 (.data(tdi), .enable_crc(EnableCrcIn), .reset(AsyncResetCrc), .sync_rst_crc(SyncResetCrc),
1069
                  .crc_out(CalculatedCrcIn), .clk(tck));
1070 2 mohor
 
1071
// Calculating crc for output data
1072 44 mohor
dbg_crc8_d1 crc2 (.data(TDOData), .enable_crc(EnableCrcOut), .reset(AsyncResetCrc), .sync_rst_crc(SyncResetCrc),
1073
                  .crc_out(CalculatedCrcOut), .clk(tck));
1074 2 mohor
 
1075
 
1076
// Generating CrcMatch signal
1077 36 mohor
always @ (posedge tck or posedge trst)
1078 2 mohor
begin
1079 18 mohor
  if(trst)
1080 2 mohor
    CrcMatch <=#Tp 1'b0;
1081
  else
1082
  if(Exit1DR)
1083
    begin
1084
      if(CHAIN_SELECTSelected)
1085
        CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[11:4];
1086
      else
1087 30 mohor
        begin
1088
          if(RegisterScanChain)
1089
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[45:38];
1090
          else
1091 63 simons
          if(RiscDebugScanChain0 | RiscDebugScanChain1 | RiscDebugScanChain2 | RiscDebugScanChain3)
1092 30 mohor
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
1093
          else
1094
          if(WishboneScanChain)
1095
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
1096
        end
1097 2 mohor
    end
1098
end
1099
 
1100
 
1101
// Active chain
1102
assign RegisterScanChain   = Chain == `REGISTER_SCAN_CHAIN;
1103 63 simons
assign RiscDebugScanChain0 = Chain == `RISC_DEBUG_CHAIN_0;
1104
assign RiscDebugScanChain1 = Chain == `RISC_DEBUG_CHAIN_1;
1105
assign RiscDebugScanChain2 = Chain == `RISC_DEBUG_CHAIN_2;
1106
assign RiscDebugScanChain3 = Chain == `RISC_DEBUG_CHAIN_3;
1107 12 mohor
assign WishboneScanChain   = Chain == `WISHBONE_SCAN_CHAIN;
1108 2 mohor
 
1109
`ifdef TRACE_ENABLED
1110
  assign TraceTestScanChain  = Chain == `TRACE_TEST_CHAIN;
1111
`endif
1112
 
1113
/**********************************************************************************
1114
*                                                                                 *
1115
*   End: Connecting CRC module                                                    *
1116
*                                                                                 *
1117
**********************************************************************************/
1118
 
1119
/**********************************************************************************
1120
*                                                                                 *
1121
*   Connecting trace module                                                       *
1122
*                                                                                 *
1123
**********************************************************************************/
1124
`ifdef TRACE_ENABLED
1125 11 mohor
  dbg_trace dbgTrace1(.Wp(wp_i), .Bp(bp_i), .DataIn(risc_data_i), .OpSelect(opselect_trace),
1126 9 mohor
                      .LsStatus(lsstatus_i), .IStatus(istatus_i), .RiscStall_O(RiscStall_trace),
1127 18 mohor
                      .Mclk(risc_clk_i), .Reset(wb_rst_i), .TraceChain(TraceChain),
1128 8 mohor
                      .ContinMode(ContinMode), .TraceEnable_reg(TraceEnable),
1129 5 mohor
                      .WpTrigger(WpTrigger),
1130 2 mohor
                      .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger), .ITrigger(ITrigger),
1131
                      .TriggerOper(TriggerOper), .WpQualif(WpQualif), .BpQualif(BpQualif),
1132
                      .LSSQualif(LSSQualif), .IQualif(IQualif), .QualifOper(QualifOper),
1133 5 mohor
                      .RecordPC(RecordPC), .RecordLSEA(RecordLSEA),
1134
                      .RecordLDATA(RecordLDATA), .RecordSDATA(RecordSDATA),
1135
                      .RecordReadSPR(RecordReadSPR), .RecordWriteSPR(RecordWriteSPR),
1136
                      .RecordINSTR(RecordINSTR),
1137 2 mohor
                      .WpTriggerValid(WpTriggerValid), .BpTriggerValid(BpTriggerValid),
1138
                      .LSSTriggerValid(LSSTriggerValid), .ITriggerValid(ITriggerValid),
1139
                      .WpQualifValid(WpQualifValid), .BpQualifValid(BpQualifValid),
1140
                      .LSSQualifValid(LSSQualifValid), .IQualifValid(IQualifValid),
1141 9 mohor
                      .ReadBuffer(ReadTraceBufferPulse),
1142 2 mohor
                      .WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
1143
                      .StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
1144
                      .LSSStopValid(LSSStopValid), .IStopValid(IStopValid)
1145
                     );
1146
`endif
1147
/**********************************************************************************
1148
*                                                                                 *
1149
*   End: Connecting trace module                                                  *
1150
*                                                                                 *
1151
**********************************************************************************/
1152
 
1153
 
1154
 
1155 9 mohor
endmodule

powered by: WebSVN 2.1.0

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