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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_6/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 64

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

powered by: WebSVN 2.1.0

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